Skip to content

Commit 42cc4db

Browse files
committed
feat: put status text in disabled menu item on macos
Tooltips on menu bar icons are unexpected on macos, the idiomatic solution is disabled menu items.
1 parent 626156c commit 42cc4db

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

cmd/backrest/tray.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ func startTray() {
2323
systray.Run(func() { onReady(status) }, func() {})
2424
}
2525

26+
var mStatusText *systray.MenuItem
27+
2628
func onReady(status *trayStatus) {
2729
systray.SetTooltip("Backrest")
2830
systray.SetIcon(icon)
2931

32+
if runtime.GOOS == "darwin" {
33+
mStatusText = systray.AddMenuItem("", "")
34+
mStatusText.Disable()
35+
mStatusText.Hide()
36+
}
37+
3038
mOpenUI := systray.AddMenuItem("Open WebUI", "Open the Backrest WebUI in your default browser")
3139
mOpenLog := systray.AddMenuItem("Open Log Dir", "Open the Backrest log directory")
3240
mQuit := systray.AddMenuItem("Quit", "Kills the backrest process and exits the tray app")

cmd/backrest/tray_status.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,15 @@ func (t *trayStatus) refresh() {
7272
if log == nil {
7373
return
7474
}
75-
state, tooltip := computeStatus(log)
75+
state, message := computeStatus(log)
7676
if ic := statusIcon(state); ic != nil {
7777
systray.SetIcon(ic)
7878
}
79-
systray.SetTooltip(tooltip)
79+
systray.SetTooltip("Backrest — " + message)
80+
if mStatusText != nil {
81+
mStatusText.SetTitle(message)
82+
mStatusText.Show()
83+
}
8084
}
8185

8286
// computeStatus returns the tray state and tooltip for the most recent backup.
@@ -100,22 +104,22 @@ func computeStatus(log *oplog.OpLog) (trayState, string) {
100104
})
101105

102106
if last == nil {
103-
return stateIdle, "Backrest — no backups yet"
107+
return stateIdle, "No backups yet"
104108
}
105109
when := relativeTime(last.GetUnixTimeEndMs())
106110
switch last.GetStatus() {
107111
case v1.OperationStatus_STATUS_INPROGRESS:
108-
return stateRunning, "Backrest — backup in progress…"
112+
return stateRunning, "Backup in progress…"
109113
case v1.OperationStatus_STATUS_SUCCESS:
110-
return stateOK, "Backrest — last backup succeeded " + when
114+
return stateOK, "Last backup succeeded " + when
111115
case v1.OperationStatus_STATUS_WARNING:
112-
return stateWarning, "Backrest — last backup finished with warnings " + when
116+
return stateWarning, "Last backup finished with warnings " + when
113117
case v1.OperationStatus_STATUS_ERROR, v1.OperationStatus_STATUS_SYSTEM_CANCELLED:
114-
return stateError, "Backrest — last backup failed " + when
118+
return stateError, "Last backup failed " + when
115119
case v1.OperationStatus_STATUS_USER_CANCELLED:
116-
return stateIdle, "Backrest — last backup was cancelled " + when
120+
return stateIdle, "Last backup was cancelled " + when
117121
default:
118-
return stateIdle, "Backrest — no backups yet"
122+
return stateIdle, "No backups yet"
119123
}
120124
}
121125

0 commit comments

Comments
 (0)