From c159de229f97dbcb6901966d934958739d077182 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Thu, 18 Jul 2024 16:56:05 -0700 Subject: [PATCH] add Mac about menu override, minor MainWindow refactor --- main.go | 12 +----------- ui/mainwindow.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index 45adda8..fe38b7b 100644 --- a/main.go +++ b/main.go @@ -73,17 +73,7 @@ func main() { }() - mainWindow.Show() - mainWindow.Window.SetCloseIntercept(func() { - mainWindow.SaveWindowSize() - if myApp.Config.Application.CloseToSystemTray && - mainWindow.HaveSystemTray() { - mainWindow.Window.Hide() - } else { - fyneApp.Quit() - } - }) - fyneApp.Run() + mainWindow.ShowAndRun() log.Println("Running shutdown tasks...") myApp.Shutdown() diff --git a/ui/mainwindow.go b/ui/mainwindow.go index 0335eb2..4dbfe84 100644 --- a/ui/mainwindow.go +++ b/ui/mainwindow.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "math" + "runtime" "strings" "time" @@ -87,6 +88,18 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string, m.Controller.CurPageFunc = m.BrowsingPane.CurrentPage m.Controller.RefreshPageFunc = m.BrowsingPane.RefreshPage + if runtime.GOOS == "darwin" { + // Fyne will extract out an "About" menu item and + // assign its action to the native Mac "About Supersonic" menu item + m.Window.SetMainMenu(fyne.NewMainMenu( + fyne.NewMenu("File", /*name doesn't matter*/ + fyne.NewMenuItem("About", func() { + m.Window.Show() + m.Controller.ShowAboutDialog() + })), + )) + } + m.BottomPanel = NewBottomPanel(app.PlaybackManager, app.ImageManager, m.Controller) m.container = container.NewBorder(nil, m.BottomPanel, nil, nil, m.BrowsingPane) m.Window.SetContent(m.container) @@ -139,6 +152,16 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string, m.addNavigationButtons() m.BrowsingPane.DisableNavigationButtons() m.addShortcuts() + + m.Window.SetCloseIntercept(func() { + m.SaveWindowSize() + if app.Config.Application.CloseToSystemTray && m.HaveSystemTray() { + m.Window.Hide() + } else { + fyneApp.Quit() + } + }) + return m } @@ -384,6 +407,10 @@ func (m *MainWindow) Show() { m.Window.Show() } +func (m *MainWindow) ShowAndRun() { + m.Window.ShowAndRun() +} + func (m *MainWindow) Canvas() fyne.Canvas { return m.Window.Canvas() }