Files
gosentry/src/ui/tray.go
T
mixeme 882fcfe65d chore: release 0.11.2 with window persistence, appID update, and doc fixes
- Persist window size on quit/close and restore it on next launch
- Update appID from ru.mixdep.gosentry.desktop to ru.mixeme.gosentry.desktop
- Use markdown headers for Build sections in DEVELOPMENT.md
- Remove stale go.yaml.in/yaml/v4 dependency from DEVELOPMENT.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-25 22:50:28 +03:00

65 lines
2.0 KiB
Go

package ui
import (
"runtime"
"gitea.mixdep.ru/mix/gosentry/assets"
"fyne.io/fyne/v2"
fynedesktop "fyne.io/fyne/v2/driver/desktop"
)
func configureSystemTray(a fyne.App, w fyne.Window) {
desk, ok := a.(fynedesktop.App)
if !ok {
// Not every Fyne driver exposes desktop tray features. Returning silently
// keeps the same binary usable on platforms or sessions without a tray.
return
}
// The tray icon is platform-specific. The Windows notification area is
// ICO-native and renders at 16-24px, so a single 16x16 .ico frame keeps the
// hand-tuned glyph crisp with correct alpha. Linux/macOS trays
// (StatusNotifierItem) render much larger (22-48px) and take a PNG, so the
// full-size artwork scales down cleanly instead of upscaling the tiny 16x16.
if runtime.GOOS == "windows" {
desk.SetSystemTrayIcon(assets.IconSmallICO())
} else {
desk.SetSystemTrayIcon(assets.Icon())
}
// IsQuit marks this as the tray's quit item. Without it Fyne's
// addMissingQuitForMenu appends a second, localized Quit (e.g. "Выход" on a
// Russian system) because it only recognizes an existing quit by matching the
// localized label — which our literal "Quit" does not. Setting IsQuit makes
// Fyne reuse this item instead of adding a duplicate, regardless of locale.
saveWindowSize := func() {
size := w.Canvas().Size()
prefs := a.Preferences()
prefs.SetFloat("window.width", float64(size.Width))
prefs.SetFloat("window.height", float64(size.Height))
}
quit := fyne.NewMenuItem("Quit", func() {
saveWindowSize()
a.Quit()
})
quit.IsQuit = true
menu := fyne.NewMenu("GoSentry",
fyne.NewMenuItem("Show", func() {
w.Show()
w.RequestFocus()
}),
fyne.NewMenuItemSeparator(),
quit,
)
desk.SetSystemTrayMenu(menu)
desk.SetSystemTrayWindow(w)
w.SetCloseIntercept(func() {
// Closing hides the window instead of quitting because scheduler tools are
// expected to keep working in the background. The explicit Quit tray item
// remains the way to stop the process.
saveWindowSize()
w.Hide()
})
}