cmd/systray: properly set tooltip on different platforms

On Linux, systray.SetTitle actually seems to set the tooltip on all
desktops I've tested on.  But on macOS, it actually does set a title
that is always displayed in the systray area next to the icon. This
change should properly set the tooltip across platforms.

Updates #1708

Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d
Signed-off-by: Will Norris <will@tailscale.com>
This commit is contained in:
Will Norris 2024-12-27 12:34:16 -08:00 committed by Will Norris
parent 5a4148e7e8
commit c43c5ca003

View File

@ -199,14 +199,14 @@ func (menu *Menu) rebuild() {
case ipn.Running.String(): case ipn.Running.String():
if menu.status.ExitNodeStatus != nil && !menu.status.ExitNodeStatus.ID.IsZero() { if menu.status.ExitNodeStatus != nil && !menu.status.ExitNodeStatus.ID.IsZero() {
if menu.status.ExitNodeStatus.Online { if menu.status.ExitNodeStatus.Online {
systray.SetTitle("Using exit node") setTooltip("Using exit node")
setAppIcon(exitNodeOnline) setAppIcon(exitNodeOnline)
} else { } else {
systray.SetTitle("Exit node offline") setTooltip("Exit node offline")
setAppIcon(exitNodeOffline) setAppIcon(exitNodeOffline)
} }
} else { } else {
systray.SetTitle(fmt.Sprintf("Connected to %s", menu.status.CurrentTailnet.Name)) setTooltip(fmt.Sprintf("Connected to %s", menu.status.CurrentTailnet.Name))
setAppIcon(connected) setAppIcon(connected)
} }
menu.connect.SetTitle("Connected") menu.connect.SetTitle("Connected")
@ -214,10 +214,10 @@ func (menu *Menu) rebuild() {
menu.disconnect.Show() menu.disconnect.Show()
menu.disconnect.Enable() menu.disconnect.Enable()
case ipn.Starting.String(): case ipn.Starting.String():
systray.SetTitle("Connecting") setTooltip("Connecting")
setAppIcon(loading) setAppIcon(loading)
default: default:
systray.SetTitle("Disconnected") setTooltip("Disconnected")
setAppIcon(disconnected) setAppIcon(disconnected)
} }
@ -312,6 +312,16 @@ func setRemoteIcon(menu *systray.MenuItem, urlStr string) {
} }
} }
// setTooltip sets the tooltip text for the systray icon.
func setTooltip(text string) {
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
systray.SetTooltip(text)
} else {
// on Linux, SetTitle actually sets the tooltip
systray.SetTitle(text)
}
}
// eventLoop is the main event loop for handling click events on menu items // eventLoop is the main event loop for handling click events on menu items
// and responding to Tailscale state changes. // and responding to Tailscale state changes.
// This method does not return until ctx.Done is closed. // This method does not return until ctx.Done is closed.