Keep orgstar in the menu bar when asked !437

merged merged by cmc on 2026-11-22 01:26 UTC · krz/orgstar:menu-bar-item into main

7 files changed, +188 −20

Layout: unified · split

Sources/OrgApp/UserConfig.swift +2
@@ -391,6 +391,8 @@ public enum UserConfig {
391 comment: "the Reminders lists shown, by title or identifier, separated by commas; \"\" for all", legacy: ""), 391 comment: "the Reminders lists shown, by title or identifier, separated by commas; \"\" for all", legacy: ""),
392 Setting(section: "orgstar", key: "global-capture-hotkey", defaultsKey: "globalCapture", kind: .bool, fallback: .bool(true), 392 Setting(section: "orgstar", key: "global-capture-hotkey", defaultsKey: "globalCapture", kind: .bool, fallback: .bool(true),
393 comment: "⌃⌥Space opens Capture from any app; templates go in capture.toml", legacy: "capture.global-hotkey"), 393 comment: "⌃⌥Space opens Capture from any app; templates go in capture.toml", legacy: "capture.global-hotkey"),
394 Setting(section: "orgstar", key: "menu-bar-item", defaultsKey: "menuBarItem", kind: .bool, fallback: .bool(false),
395 comment: "keep orgstar in the menu bar, with capture and today's agenda; off shows it only while a clock runs", legacy: ""),
394 ] 396 ]
395 397
396 /// `"-3d"` as -3; nil for anything else. 398 /// `"-3d"` as -3; nil for anything else.
Sources/Orgstar/ClockViews.swift +64 −14
@@ -15,6 +15,10 @@ func clockElapsed(_ running: ClockModel.Running, now: Date) -> String {
15struct ClockMenuState: Equatable { 15struct ClockMenuState: Equatable {
16 let running: ClockModel.Running? 16 let running: ClockModel.Running?
17 let history: [ClockTask] 17 let history: [ClockTask]
18 /// `menu-bar-item`: the item stays when no clock runs.
19 var always = false
20 /// Today's agenda, overdue entries first.
21 var today: [AgendaSnapshot.Row] = []
18} 22}
19 23
20/// `org-user-idle-seconds` on macOS: time since the last keyboard or mouse input anywhere. 24/// `org-user-idle-seconds` on macOS: time since the last keyboard or mouse input anywhere.
@@ -62,21 +66,27 @@ struct ClockMenu: View {
62 } 66 }
63} 67}
64 68
65/// The menu bar item while a clock runs: elapsed time, and clock out, cancel and go to. 69/// The menu bar item: while a clock runs, the elapsed time and the clock commands; with
70/// `always`, there all the time, with capture, the agenda and today's entries too.
66@MainActor 71@MainActor
67final class ClockStatusItem: NSObject { 72final class ClockStatusItem: NSObject {
73 /// Today's entries the menu lists before "more".
74 static let rowLimit = 12
75
68 private var item: NSStatusItem? 76 private var item: NSStatusItem?
69 private var timer: Timer? 77 private var timer: Timer?
70 private var running: ClockModel.Running? 78 private var running: ClockModel.Running?
71 private let run: (String) -> Void 79 private let run: (String) -> Void
80 private let jump: (String, Int) -> Void
72 81
73 init(run: @escaping (String) -> Void) { 82 init(run: @escaping (String) -> Void, jump: @escaping (String, Int) -> Void) {
74 self.run = run 83 self.run = run
84 self.jump = jump
75 } 85 }
76 86
77 func update(_ running: ClockModel.Running?, recent: [String] = []) { 87 func update(_ state: ClockMenuState) {
78 self.running = running 88 running = state.running
79 guard let running else { 89 guard state.running != nil || state.always else {
80 timer?.invalidate() 90 timer?.invalidate()
81 timer = nil 91 timer = nil
82 if let item { NSStatusBar.system.removeStatusItem(item) } 92 if let item { NSStatusBar.system.removeStatusItem(item) }
@@ -90,19 +100,42 @@ final class ClockStatusItem: NSObject {
90 } 100 }
91 } 101 }
92 let menu = NSMenu() 102 let menu = NSMenu()
93 menu.addItem(withTitle: running.heading, action: nil, keyEquivalent: "") 103 if state.always {
94 menu.addItem(.separator()) 104 add(String(localized: "Capture…"), "app.capture", to: menu)
95 for (title, id) in [ 105 add(String(localized: "Agenda"), "app.agenda", to: menu)
96 ("Clock Out", "app.clock.out"), ("Cancel Clock", "app.clock.cancel"), ("Go to Clocked Entry", "app.clock.goto"), 106 menu.addItem(.separator())
97 ("Clock In to Recent Entry…", "app.clock.in-recent"), ("Clock Report", "app.clock.report"), 107 menu.addItem(NSMenuItem.sectionHeader(title: String(localized: "Today")))
98 ] { 108 let rows = state.today.filter { !$0.isDone }
99 add(title, id, to: menu) 109 if rows.isEmpty { menu.addItem(withTitle: String(localized: "Nothing scheduled"), action: nil, keyEquivalent: "") }
110 for row in rows.prefix(Self.rowLimit) {
111 let title = [row.gutter, row.todo ?? "", row.title].filter { !$0.isEmpty }.joined(separator: " ")
112 let entry = NSMenuItem(title: title, action: row.link == nil ? nil : #selector(open(_:)), keyEquivalent: "")
113 entry.target = self
114 entry.representedObject = row.link
115 menu.addItem(entry)
116 }
117 if rows.count > Self.rowLimit { add(String(localized: "\(rows.count - Self.rowLimit) more…"), "app.agenda", to: menu) }
118 menu.addItem(.separator())
100 } 119 }
120 var commands = [("Clock In to Recent Entry…", "app.clock.in-recent"), ("Clock Report", "app.clock.report")]
121 if let running = state.running {
122 menu.addItem(withTitle: running.heading, action: nil, keyEquivalent: "")
123 menu.addItem(.separator())
124 commands.insert(contentsOf: [("Clock Out", "app.clock.out"), ("Cancel Clock", "app.clock.cancel"), ("Go to Clocked Entry", "app.clock.goto")], at: 0)
125 }
126 for (title, id) in commands { add(title, id, to: menu) }
127 let recent = state.history.map(\.title)
101 if !recent.isEmpty { 128 if !recent.isEmpty {
102 menu.addItem(.separator()) 129 menu.addItem(.separator())
103 menu.addItem(NSMenuItem.sectionHeader(title: "Recent Entries")) 130 menu.addItem(NSMenuItem.sectionHeader(title: "Recent Entries"))
104 for (index, title) in recent.enumerated() { add(title, "app.clock.history.\(index)", to: menu) } 131 for (index, title) in recent.enumerated() { add(title, "app.clock.history.\(index)", to: menu) }
105 } 132 }
133 if state.always {
134 menu.addItem(.separator())
135 let show = NSMenuItem(title: String(localized: "Open orgstar"), action: #selector(activate), keyEquivalent: "")
136 show.target = self
137 menu.addItem(show)
138 }
106 item?.menu = menu 139 item?.menu = menu
107 refresh() 140 refresh()
108 } 141 }
@@ -115,8 +148,14 @@ final class ClockStatusItem: NSObject {
115 } 148 }
116 149
117 private func refresh() { 150 private func refresh() {
118 guard let running else { return } 151 guard let button = item?.button else { return }
119 item?.button?.title = "⏱ " + clockElapsed(running, now: Date()) 152 if let running {
153 button.image = nil
154 button.title = "⏱ " + clockElapsed(running, now: Date())
155 } else {
156 button.image = NSImage(systemSymbolName: "star", accessibilityDescription: "orgstar")
157 button.title = ""
158 }
120 } 159 }
121 160
122 @objc private func choose(_ sender: NSMenuItem) { 161 @objc private func choose(_ sender: NSMenuItem) {
@@ -125,6 +164,17 @@ final class ClockStatusItem: NSObject {
125 run(id) 164 run(id)
126 } 165 }
127 } 166 }
167
168 @objc private func open(_ sender: NSMenuItem) {
169 if case .entry(let path, let offset)? = sender.representedObject as? AppLink {
170 NSApp.activate()
171 jump(path, offset)
172 }
173 }
174
175 @objc private func activate() {
176 NSApp.activate()
177 }
128} 178}
129 179
130/// Clocked time per day and heading (`ClockReport.timeReport`) for chosen files and dates. 180/// Clocked time per day and heading (`ClockReport.timeReport`) for chosen files and dates.
Sources/Orgstar/ContentView.swift +13 −6
@@ -28,6 +28,9 @@ struct ContentView: View {
28 @State private var hotKey: GlobalHotKey? 28 @State private var hotKey: GlobalHotKey?
29 @State private var statusItem: ClockStatusItem? 29 @State private var statusItem: ClockStatusItem?
30 @AppStorage("globalCapture") private var globalCapture = true 30 @AppStorage("globalCapture") private var globalCapture = true
31 @AppStorage("menuBarItem") private var menuBarItem = false
32 /// Today's agenda for the menu bar item.
33 @State private var menuToday: [AgendaSnapshot.Row] = []
31 @State private var hour = 0 34 @State private var hour = 0
32 @AppStorage("saveMode") private var saveMode = SaveMode.automatic 35 @AppStorage("saveMode") private var saveMode = SaveMode.automatic
33 @AppStorage("keymap") private var preset = KeymapPreset.emacs 36 @AppStorage("keymap") private var preset = KeymapPreset.emacs
@@ -428,10 +431,11 @@ struct ContentView: View {
428 var body: some View { 431 var body: some View {
429 main 432 main
430 .task(id: workspace.files.count) { syncClock(paths: workspace.agendaFilePaths()) } 433 .task(id: workspace.files.count) { syncClock(paths: workspace.agendaFilePaths()) }
431 .onChange(of: ClockMenuState(running: clock.running, history: clock.history), initial: true) { _, state in 434 .onChange(of: ClockMenuState(running: clock.running, history: clock.history, always: menuBarItem, today: menuToday), initial: true) { _, state in
432 if statusItem == nil { statusItem = ClockStatusItem { commands.run($0) } } 435 if statusItem == nil { statusItem = ClockStatusItem(run: { commands.run($0) }, jump: { commands.jump(path: $0, offset: $1) }) }
433 statusItem?.update(state.running, recent: state.history.map(\.title)) 436 statusItem?.update(state)
434 } 437 }
438 .task(id: menuBarItem) { if menuBarItem { await updateWidgets() } }
435 .onChange(of: globalCapture, initial: true) { _, enabled in 439 .onChange(of: globalCapture, initial: true) { _, enabled in
436 hotKey?.unregister() 440 hotKey?.unregister()
437 hotKey = enabled ? GlobalHotKey { perform("app.capture") } : nil 441 hotKey = enabled ? GlobalHotKey { perform("app.capture") } : nil
@@ -1172,9 +1176,10 @@ struct ContentView: View {
1172 } 1176 }
1173 1177
1174 /// The desktop widgets' agenda and habits, written where the widget extension reads them, 1178 /// The desktop widgets' agenda and habits, written where the widget extension reads them,
1175 /// with the widgets reloaded when they changed. 1179 /// with the widgets reloaded when they changed; and today's agenda for the menu bar item.
1176 private func updateWidgets() async { 1180 private func updateWidgets() async {
1177 guard !Task.isCancelled, ProAccess.shared.isUnlocked, !workspace.files.isEmpty, let file = AgendaSnapshot.file() else { return } 1181 let file = ProAccess.shared.isUnlocked ? AgendaSnapshot.file() : nil
1182 guard !Task.isCancelled, !workspace.files.isEmpty, file != nil || menuBarItem else { return }
1178 let days = widgetAgenda ?? AgendaModel(workspace: workspace) 1183 let days = widgetAgenda ?? AgendaModel(workspace: workspace)
1179 widgetAgenda = days 1184 widgetAgenda = days
1180 days.mode = .agenda(span: AgendaSnapshot.dayCount, startOffset: 0) 1185 days.mode = .agenda(span: AgendaSnapshot.dayCount, startOffset: 0)
@@ -1192,10 +1197,12 @@ struct ContentView: View {
1192 let open = session.openTexts 1197 let open = session.openTexts
1193 await days.refresh(open: open) 1198 await days.refresh(open: open)
1194 guard !Task.isCancelled else { return } 1199 guard !Task.isCancelled else { return }
1200 let snapshot = AgendaSnapshot(groups: days.groups(), today: days.today, theme: theme, generated: Date())
1201 menuToday = snapshot.days.first.map { $0.overdue + $0.rows } ?? []
1202 guard let file else { return }
1195 if (try? HabitSnapshot(habits: await days.habits(open: open), theme: theme).write()) == true { 1203 if (try? HabitSnapshot(habits: await days.habits(open: open), theme: theme).write()) == true {
1196 WidgetCenter.shared.reloadTimelines(ofKind: "sh.krz.orgstar.habits") 1204 WidgetCenter.shared.reloadTimelines(ofKind: "sh.krz.orgstar.habits")
1197 } 1205 }
1198 let snapshot = AgendaSnapshot(groups: days.groups(), today: days.today, theme: theme, generated: Date())
1199 if (try? snapshot.write(to: file)) == true { WidgetCenter.shared.reloadAllTimelines() } 1206 if (try? snapshot.write(to: file)) == true { WidgetCenter.shared.reloadAllTimelines() }
1200 } 1207 }
1201 1208
Sources/Orgstar/OrgstarApp.swift +3
@@ -707,6 +707,7 @@ struct SettingsView: View {
707 @AppStorage("clockIdleTime") private var clockIdleTime = 0 707 @AppStorage("clockIdleTime") private var clockIdleTime = 0
708 @AppStorage("clockHistoryLength") private var clockHistoryLength = 5 708 @AppStorage("clockHistoryLength") private var clockHistoryLength = 5
709 @AppStorage("globalCapture") private var globalCapture = true 709 @AppStorage("globalCapture") private var globalCapture = true
710 @AppStorage("menuBarItem") private var menuBarItem = false
710 @AppStorage("settingsTab") private var tab = "general" 711 @AppStorage("settingsTab") private var tab = "general"
711 @AppStorage("showHiddenFiles") private var showHiddenFiles = true 712 @AppStorage("showHiddenFiles") private var showHiddenFiles = true
712 @AppStorage("themeFont") private var themeFont = "" 713 @AppStorage("themeFont") private var themeFont = ""
@@ -821,6 +822,8 @@ struct SettingsView: View {
821 ForEach(KeymapPreset.allCases, id: \.self) { Text($0.title).tag($0) } 822 ForEach(KeymapPreset.allCases, id: \.self) { Text($0.title).tag($0) }
822 } 823 }
823 Toggle("Show hidden files and folders", isOn: $showHiddenFiles) 824 Toggle("Show hidden files and folders", isOn: $showHiddenFiles)
825 Toggle("Keep orgstar in the menu bar", isOn: $menuBarItem)
826 .help("Capture, the agenda, today's entries and the clock, from any app. When off, the menu bar shows orgstar only while a clock runs.")
824 Picker("Option as Meta", selection: $optionAsMeta) { 827 Picker("Option as Meta", selection: $optionAsMeta) {
825 Text("Left Option").tag(OptionAsMeta.left.rawValue) 828 Text("Left Option").tag(OptionAsMeta.left.rawValue)
826 Text("Right Option").tag(OptionAsMeta.right.rawValue) 829 Text("Right Option").tag(OptionAsMeta.right.rawValue)
docs/manual/guide/06-dates-and-clocking.org +2
@@ -320,6 +320,8 @@ While a clock runs, orgstar shows it in three places, refreshed every 30 seconds
320 320
321The time shown is the time since you clocked in, not the entry's total. Each of them opens a menu with Clock Out, Cancel Clock and Go to Clocked Entry. The toolbar's menu also has Clock In to Recent Entry…, Go to Recent Clocked Entry… and the recent entries. The menu bar item also has Clock In to Recent Entry…, Clock Report and a Recent Entries section. Choosing a recent entry clocks in to it. 321The time shown is the time since you clocked in, not the entry's total. Each of them opens a menu with Clock Out, Cancel Clock and Go to Clocked Entry. The toolbar's menu also has Clock In to Recent Entry…, Go to Recent Clocked Entry… and the recent entries. The menu bar item also has Clock In to Recent Entry…, Clock Report and a Recent Entries section. Choosing a recent entry clocks in to it.
322 322
323With Settings ▸ General ▸ Keep orgstar in the menu bar (=menu-bar-item=), the menu bar item stays when no clock runs, as a star, and its menu starts with Capture…, Agenda and today's agenda entries that aren't done, overdue ones first; choosing an entry shows it in the main window. It is there while orgstar is running.
324
323** Recent entries 325** Recent entries
324 326
325orgstar keeps a clock history, as =org-clock-history=. Every clock-in, including one from the agenda or a capture template, puts the entry first in the history and removes its other entries there. The history holds =org-clock-history-length= entries (5 by default); the oldest go first. 327orgstar keeps a clock history, as =org-clock-history=. Every clock-in, including one from the agenda or a capture template, puts the entry first in the history and removes its other entries there. The history holds =org-clock-history-length= entries (5 by default); the oldest go first.
docs/manual/guide/13-configuration.org +2
@@ -63,6 +63,7 @@ Open it with orgstar ▸ Settings (=⌘,=). It has six panes. The last, orgstar+
63| Save files | Automatically, when typing stops; Only with File ▸ Save (=⌘S=) | Automatically | =save= | 63| Save files | Automatically, when typing stops; Only with File ▸ Save (=⌘S=) | Automatically | =save= |
64| Keys | Emacs; Mac; Doom (Vim keys) | Emacs | =keymap= | 64| Keys | Emacs; Mac; Doom (Vim keys) | Emacs | =keymap= |
65| Show hidden files and folders | On or off | On | =show-hidden-files= | 65| Show hidden files and folders | On or off | On | =show-hidden-files= |
66| Keep orgstar in the menu bar | On or off | Off | =menu-bar-item= |
66| Option as Meta | Left Option; Right Option; Both; Neither | Left Option | =option-as-meta= | 67| Option as Meta | Left Option; Right Option; Both; Neither | Left Option | =option-as-meta= |
67 68
68Automatic saving writes a file one second after you stop typing. The keymap presets and =keymap.toml= are covered in [[file:03-keys.org][Keys and commands]]. 69Automatic saving writes a file one second after you stop typing. The keymap presets and =keymap.toml= are covered in [[file:03-keys.org][Keys and commands]].
@@ -426,6 +427,7 @@ Any other key in =[theme]= is a color; see Themes below.
426| =agenda-reminders= | boolean | =false= | Show incomplete reminders with a due date from Reminders in the agenda, read-only. | 427| =agenda-reminders= | boolean | =false= | Show incomplete reminders with a due date from Reminders in the agenda, read-only. |
427| =agenda-reminder-lists= | string | =""= | The Reminders lists shown, by title or identifier, separated by commas; =""= for all. | 428| =agenda-reminder-lists= | string | =""= | The Reminders lists shown, by title or identifier, separated by commas; =""= for all. |
428| =global-capture-hotkey= | boolean | =true= | =⌃⌥Space= opens Capture from any app. | 429| =global-capture-hotkey= | boolean | =true= | =⌃⌥Space= opens Capture from any app. |
430| =menu-bar-item= | boolean | =false= | Keep orgstar in the menu bar, with capture and today's agenda; off shows it only while a clock runs. |
429 431
430The default =ignored-folders= is: 432The default =ignored-folders= is:
431 433
l10n/Localizable.xcstrings +102
@@ -1409,6 +1409,40 @@
1409 } 1409 }
1410 } 1410 }
1411 }, 1411 },
1412 "%lld more…": {
1413 "localizations": {
1414 "de": {
1415 "stringUnit": {
1416 "state": "translated",
1417 "value": "%lld weitere …"
1418 }
1419 },
1420 "es": {
1421 "stringUnit": {
1422 "state": "translated",
1423 "value": "%lld más…"
1424 }
1425 },
1426 "fr": {
1427 "stringUnit": {
1428 "state": "translated",
1429 "value": "%lld de plus…"
1430 }
1431 },
1432 "ja": {
1433 "stringUnit": {
1434 "state": "translated",
1435 "value": "ほか%lld件…"
1436 }
1437 },
1438 "pt-BR": {
1439 "stringUnit": {
1440 "state": "translated",
1441 "value": "Mais %lld…"
1442 }
1443 }
1444 }
1445 },
1412 "%lld open": { 1446 "%lld open": {
1413 "localizations": { 1447 "localizations": {
1414 "de": { 1448 "de": {
@@ -5757,6 +5791,40 @@
5757 } 5791 }
5758 } 5792 }
5759 }, 5793 },
5794 "Capture, the agenda, today's entries and the clock, from any app. When off, the menu bar shows orgstar only while a clock runs.": {
5795 "localizations": {
5796 "de": {
5797 "stringUnit": {
5798 "state": "translated",
5799 "value": "Erfassen, die Agenda, die heutigen Einträge und die Zeiterfassung aus jeder App. Wenn deaktiviert, zeigt die Menüleiste orgstar nur, während eine Zeiterfassung läuft."
5800 }
5801 },
5802 "es": {
5803 "stringUnit": {
5804 "state": "translated",
5805 "value": "Captura, la agenda, las entradas de hoy y el registro de tiempo, desde cualquier app. Si está desactivado, la barra de menús muestra orgstar solo mientras hay un registro de tiempo en curso."
5806 }
5807 },
5808 "fr": {
5809 "stringUnit": {
5810 "state": "translated",
5811 "value": "La capture, l'agenda, les entrées du jour et le chronométrage, depuis n'importe quelle app. Si désactivé, la barre des menus n'affiche orgstar que pendant un chronométrage."
5812 }
5813 },
5814 "ja": {
5815 "stringUnit": {
5816 "state": "translated",
5817 "value": "どのアプリからでも、キャプチャ、アジェンダ、今日のエントリ、クロックを使えます。オフの場合、クロックの実行中のみメニューバーにorgstarが表示されます。"
5818 }
5819 },
5820 "pt-BR": {
5821 "stringUnit": {
5822 "state": "translated",
5823 "value": "Captura, a agenda, as entradas de hoje e o registro de tempo, a partir de qualquer app. Quando desativado, a barra de menus mostra o orgstar apenas enquanto um registro de tempo está em andamento."
5824 }
5825 }
5826 }
5827 },
5760 "Capture…": { 5828 "Capture…": {
5761 "comment": "Command title", 5829 "comment": "Command title",
5762 "localizations": { 5830 "localizations": {
@@ -16423,6 +16491,40 @@
16423 } 16491 }
16424 } 16492 }
16425 }, 16493 },
16494 "Keep orgstar in the menu bar": {
16495 "localizations": {
16496 "de": {
16497 "stringUnit": {
16498 "state": "translated",
16499 "value": "orgstar in der Menüleiste behalten"
16500 }
16501 },
16502 "es": {
16503 "stringUnit": {
16504 "state": "translated",
16505 "value": "Mantener orgstar en la barra de menús"
16506 }
16507 },
16508 "fr": {
16509 "stringUnit": {
16510 "state": "translated",
16511 "value": "Garder orgstar dans la barre des menus"
16512 }
16513 },
16514 "ja": {
16515 "stringUnit": {
16516 "state": "translated",
16517 "value": "orgstarをメニューバーに常に表示"
16518 }
16519 },
16520 "pt-BR": {
16521 "stringUnit": {
16522 "state": "translated",
16523 "value": "Manter o orgstar na barra de menus"
16524 }
16525 }
16526 }
16527 },
16426 "Keys": { 16528 "Keys": {
16427 "localizations": { 16529 "localizations": {
16428 "de": { 16530 "de": {