add system tray + close to tray support (no settigs UI yet)
This commit is contained in:
@@ -20,6 +20,8 @@ type AppConfig struct {
|
||||
WindowWidth int
|
||||
WindowHeight int
|
||||
LastCheckedVersion string
|
||||
EnableSystemTray bool
|
||||
CloseToSystemTray bool
|
||||
}
|
||||
|
||||
type AlbumPageConfig struct {
|
||||
@@ -87,6 +89,8 @@ func DefaultConfig(appVersionTag string) *Config {
|
||||
WindowWidth: 1000,
|
||||
WindowHeight: 800,
|
||||
LastCheckedVersion: appVersionTag,
|
||||
EnableSystemTray: true,
|
||||
CloseToSystemTray: false,
|
||||
},
|
||||
AlbumPage: AlbumPageConfig{
|
||||
TracklistColumns: []string{"Artist", "Time", "Plays", "Favorite"},
|
||||
|
||||
@@ -57,10 +57,15 @@ func main() {
|
||||
mainWindow.Window.SetCloseIntercept(func() {
|
||||
myApp.Config.Application.WindowHeight = int(mainWindow.Canvas().Size().Height)
|
||||
myApp.Config.Application.WindowWidth = int(mainWindow.Canvas().Size().Width)
|
||||
mainWindow.Window.Close()
|
||||
if myApp.Config.Application.CloseToSystemTray &&
|
||||
mainWindow.HaveSystemTray() {
|
||||
mainWindow.Window.Hide()
|
||||
} else {
|
||||
fyneApp.Quit()
|
||||
}
|
||||
})
|
||||
fyneApp.Run()
|
||||
|
||||
// shutdown tasks
|
||||
log.Println("Running shutdown tasks...")
|
||||
myApp.Shutdown()
|
||||
}
|
||||
|
||||
+31
-1
@@ -40,7 +40,8 @@ type MainWindow struct {
|
||||
BrowsingPane *browsing.BrowsingPane
|
||||
BottomPanel *BottomPanel
|
||||
|
||||
container *fyne.Container
|
||||
haveSystemTray bool
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -54,6 +55,9 @@ func NewMainWindow(fyneApp fyne.App, appName, appVersion string, app *backend.Ap
|
||||
BrowsingPane: browsing.NewBrowsingPane(app),
|
||||
}
|
||||
|
||||
if app.Config.Application.EnableSystemTray {
|
||||
m.SetupSystemTrayMenu(appName, fyneApp)
|
||||
}
|
||||
m.Controller = &controller.Controller{
|
||||
AppVersion: appVersion,
|
||||
MainWindow: m.Window,
|
||||
@@ -123,6 +127,32 @@ func NewMainWindow(fyneApp fyne.App, appName, appVersion string, app *backend.Ap
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *MainWindow) SetupSystemTrayMenu(appName string, fyneApp fyne.App) {
|
||||
if desk, ok := fyneApp.(desktop.App); ok {
|
||||
menu := fyne.NewMenu(appName,
|
||||
fyne.NewMenuItem("Play/Pause", func() {
|
||||
m.App.Player.PlayPause()
|
||||
}),
|
||||
fyne.NewMenuItem("Previous", func() {
|
||||
m.App.Player.SeekBackOrPrevious()
|
||||
}),
|
||||
fyne.NewMenuItem("Next", func() {
|
||||
m.App.Player.SeekNext()
|
||||
}),
|
||||
fyne.NewMenuItemSeparator(),
|
||||
fyne.NewMenuItem("Show", func() {
|
||||
m.Show()
|
||||
}))
|
||||
desk.SetSystemTrayMenu(menu)
|
||||
desk.SetSystemTrayIcon(res.ResAppicon250Png)
|
||||
m.haveSystemTray = true
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MainWindow) HaveSystemTray() bool {
|
||||
return m.haveSystemTray
|
||||
}
|
||||
|
||||
func (m *MainWindow) ShowNewVersionDialog(appName, versionTag string) {
|
||||
contentStr := fmt.Sprintf("A new version of %s (%s) is available",
|
||||
appName, versionTag)
|
||||
|
||||
Reference in New Issue
Block a user