diff --git a/main.go b/main.go index 5ec9592..ac82b0a 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( "log" - "math" "os" "runtime" "time" @@ -42,10 +41,7 @@ func main() { } mainWindow := ui.NewMainWindow(fyneApp, res.AppName, res.DisplayName, res.AppVersion, myApp, fyne.NewSize(w, h)) myApp.OnReactivate = mainWindow.Show - myApp.OnExit = func() { - saveWindowSize(myApp.Config, mainWindow.Window) - fyneApp.Quit() - } + myApp.OnExit = mainWindow.Quit go func() { // TODO: There is a race condition with laying out the window before the @@ -66,7 +62,7 @@ func main() { mainWindow.Show() mainWindow.Window.SetCloseIntercept(func() { - saveWindowSize(myApp.Config, mainWindow.Window) + mainWindow.SaveWindowSize() if myApp.Config.Application.CloseToSystemTray && mainWindow.HaveSystemTray() { mainWindow.Window.Hide() @@ -79,10 +75,3 @@ func main() { log.Println("Running shutdown tasks...") myApp.Shutdown() } - -func saveWindowSize(config *backend.Config, window fyne.Window) { - // round sizes to even to avoid Wayland issues with 2x scaling factor - // https://github.com/dweymouth/supersonic/issues/212 - config.Application.WindowHeight = int(math.RoundToEven(float64(window.Canvas().Size().Height))) - config.Application.WindowWidth = int(math.RoundToEven(float64(window.Canvas().Size().Width))) -} diff --git a/ui/mainwindow.go b/ui/mainwindow.go index 85b5ace..ce17413 100644 --- a/ui/mainwindow.go +++ b/ui/mainwindow.go @@ -3,6 +3,7 @@ package ui import ( "fmt" "log" + "math" "strings" "github.com/20after4/configdir" @@ -280,6 +281,11 @@ func (m *MainWindow) addShortcuts() { m.showSettingsDialog() }) } + if os.QuitShortcut != nil { + m.Canvas().AddShortcut(os.QuitShortcut, func(_ fyne.Shortcut) { + m.Quit() + }) + } m.Canvas().AddShortcut(&ShortcutReload, func(_ fyne.Shortcut) { m.BrowsingPane.Reload() @@ -346,3 +352,15 @@ func (m *MainWindow) SetTitle(title string) { func (m *MainWindow) SetContent(c fyne.CanvasObject) { m.Window.SetContent(c) } + +func (m *MainWindow) Quit() { + m.SaveWindowSize() + fyne.CurrentApp().Quit() +} + +func (m *MainWindow) SaveWindowSize() { + // round sizes to even to avoid Wayland issues with 2x scaling factor + // https://github.com/dweymouth/supersonic/issues/212 + m.App.Config.Application.WindowHeight = int(math.RoundToEven(float64(m.Window.Canvas().Size().Height))) + m.App.Config.Application.WindowWidth = int(math.RoundToEven(float64(m.Window.Canvas().Size().Width))) +} diff --git a/ui/os/shortcuts_darwin.go b/ui/os/shortcuts_darwin.go index d1c7369..7dd3c20 100644 --- a/ui/os/shortcuts_darwin.go +++ b/ui/os/shortcuts_darwin.go @@ -13,7 +13,8 @@ const ( ) var ( - BackShortcuts = []desktop.CustomShortcut{ + QuitShortcut *desktop.CustomShortcut = nil // Fyne already adds Cmd+Q + BackShortcuts = []desktop.CustomShortcut{ {Modifier: fyne.KeyModifierSuper, KeyName: fyne.KeyLeft}, {Modifier: fyne.KeyModifierSuper, KeyName: fyne.KeyLeftBracket}, } diff --git a/ui/os/shortcuts_default.go b/ui/os/shortcuts_default.go index 3bcc331..75865f6 100644 --- a/ui/os/shortcuts_default.go +++ b/ui/os/shortcuts_default.go @@ -13,6 +13,7 @@ const ( ) var ( + QuitShortcut = &desktop.CustomShortcut{Modifier: KeyModifierControl, KeyName: fyne.KeyQ} BackShortcuts = []desktop.CustomShortcut{ {Modifier: fyne.KeyModifierAlt, KeyName: fyne.KeyLeft}, }