Add Ctrl+Q quit shortcut for non-Mac
This commit is contained in:
@@ -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)))
|
||||
}
|
||||
|
||||
@@ -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)))
|
||||
}
|
||||
|
||||
@@ -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},
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
QuitShortcut = &desktop.CustomShortcut{Modifier: KeyModifierControl, KeyName: fyne.KeyQ}
|
||||
BackShortcuts = []desktop.CustomShortcut{
|
||||
{Modifier: fyne.KeyModifierAlt, KeyName: fyne.KeyLeft},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user