Add Ctrl+Q quit shortcut for non-Mac
This commit is contained in:
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"math"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
@@ -42,10 +41,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
mainWindow := ui.NewMainWindow(fyneApp, res.AppName, res.DisplayName, res.AppVersion, myApp, fyne.NewSize(w, h))
|
mainWindow := ui.NewMainWindow(fyneApp, res.AppName, res.DisplayName, res.AppVersion, myApp, fyne.NewSize(w, h))
|
||||||
myApp.OnReactivate = mainWindow.Show
|
myApp.OnReactivate = mainWindow.Show
|
||||||
myApp.OnExit = func() {
|
myApp.OnExit = mainWindow.Quit
|
||||||
saveWindowSize(myApp.Config, mainWindow.Window)
|
|
||||||
fyneApp.Quit()
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
// TODO: There is a race condition with laying out the window before the
|
// TODO: There is a race condition with laying out the window before the
|
||||||
@@ -66,7 +62,7 @@ func main() {
|
|||||||
|
|
||||||
mainWindow.Show()
|
mainWindow.Show()
|
||||||
mainWindow.Window.SetCloseIntercept(func() {
|
mainWindow.Window.SetCloseIntercept(func() {
|
||||||
saveWindowSize(myApp.Config, mainWindow.Window)
|
mainWindow.SaveWindowSize()
|
||||||
if myApp.Config.Application.CloseToSystemTray &&
|
if myApp.Config.Application.CloseToSystemTray &&
|
||||||
mainWindow.HaveSystemTray() {
|
mainWindow.HaveSystemTray() {
|
||||||
mainWindow.Window.Hide()
|
mainWindow.Window.Hide()
|
||||||
@@ -79,10 +75,3 @@ func main() {
|
|||||||
log.Println("Running shutdown tasks...")
|
log.Println("Running shutdown tasks...")
|
||||||
myApp.Shutdown()
|
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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/20after4/configdir"
|
"github.com/20after4/configdir"
|
||||||
@@ -280,6 +281,11 @@ func (m *MainWindow) addShortcuts() {
|
|||||||
m.showSettingsDialog()
|
m.showSettingsDialog()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if os.QuitShortcut != nil {
|
||||||
|
m.Canvas().AddShortcut(os.QuitShortcut, func(_ fyne.Shortcut) {
|
||||||
|
m.Quit()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
m.Canvas().AddShortcut(&ShortcutReload, func(_ fyne.Shortcut) {
|
m.Canvas().AddShortcut(&ShortcutReload, func(_ fyne.Shortcut) {
|
||||||
m.BrowsingPane.Reload()
|
m.BrowsingPane.Reload()
|
||||||
@@ -346,3 +352,15 @@ func (m *MainWindow) SetTitle(title string) {
|
|||||||
func (m *MainWindow) SetContent(c fyne.CanvasObject) {
|
func (m *MainWindow) SetContent(c fyne.CanvasObject) {
|
||||||
m.Window.SetContent(c)
|
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,6 +13,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
QuitShortcut *desktop.CustomShortcut = nil // Fyne already adds Cmd+Q
|
||||||
BackShortcuts = []desktop.CustomShortcut{
|
BackShortcuts = []desktop.CustomShortcut{
|
||||||
{Modifier: fyne.KeyModifierSuper, KeyName: fyne.KeyLeft},
|
{Modifier: fyne.KeyModifierSuper, KeyName: fyne.KeyLeft},
|
||||||
{Modifier: fyne.KeyModifierSuper, KeyName: fyne.KeyLeftBracket},
|
{Modifier: fyne.KeyModifierSuper, KeyName: fyne.KeyLeftBracket},
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
QuitShortcut = &desktop.CustomShortcut{Modifier: KeyModifierControl, KeyName: fyne.KeyQ}
|
||||||
BackShortcuts = []desktop.CustomShortcut{
|
BackShortcuts = []desktop.CustomShortcut{
|
||||||
{Modifier: fyne.KeyModifierAlt, KeyName: fyne.KeyLeft},
|
{Modifier: fyne.KeyModifierAlt, KeyName: fyne.KeyLeft},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user