T4.6: Extract tray.go, singleinstance.go, layout.go
Extract three focused modules from run.go and mainwindow.go: - tray.go: configureSystemTray() and related tray setup - singleinstance.go: acquireSingleInstance(), serveSingleInstance(), and constants - layout.go: minWidthLayout type and methods No behavior change; purely mechanical extraction to improve file organization. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"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
|
||||
}
|
||||
|
||||
// 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.
|
||||
quit := fyne.NewMenuItem("Quit", func() {
|
||||
a.Quit()
|
||||
})
|
||||
quit.IsQuit = true
|
||||
menu := fyne.NewMenu("GoSentry",
|
||||
fyne.NewMenuItem("Show", func() {
|
||||
w.Show()
|
||||
w.RequestFocus()
|
||||
}),
|
||||
fyne.NewMenuItemSeparator(),
|
||||
quit,
|
||||
)
|
||||
desk.SetSystemTrayMenu(menu)
|
||||
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.
|
||||
w.Hide()
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user