add UI for system tray settings

This commit is contained in:
Drew Weymouth
2023-04-06 19:17:04 -07:00
parent 8086262a8b
commit 43616f4f31
+47 -2
View File
@@ -12,7 +12,9 @@ import (
"fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/container" "fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget" "fyne.io/fyne/v2/widget"
) )
@@ -28,6 +30,7 @@ type SettingsDialog struct {
config *backend.Config config *backend.Config
audioDevices []player.AudioDevice audioDevices []player.AudioDevice
promptText *widget.RichText
content fyne.CanvasObject content fyne.CanvasObject
} }
@@ -41,8 +44,9 @@ func NewSettingsDialog(config *backend.Config, audioDeviceList []player.AudioDev
s.createGeneralTab(), s.createGeneralTab(),
s.createPlaybackTab(), s.createPlaybackTab(),
) )
s.promptText = widget.NewRichTextWithText("")
s.content = container.NewVBox(tabs, widget.NewSeparator(), s.content = container.NewVBox(tabs, widget.NewSeparator(),
container.NewHBox(layout.NewSpacer(), widget.NewButton("Close", func() { container.NewHBox(s.promptText, layout.NewSpacer(), widget.NewButton("Close", func() {
if s.OnDismiss != nil { if s.OnDismiss != nil {
s.OnDismiss() s.OnDismiss()
} }
@@ -52,6 +56,28 @@ func NewSettingsDialog(config *backend.Config, audioDeviceList []player.AudioDev
} }
func (s *SettingsDialog) createGeneralTab() *container.TabItem { func (s *SettingsDialog) createGeneralTab() *container.TabItem {
closeToTray := widget.NewCheckWithData("Close to system tray",
binding.BindBool(&s.config.Application.CloseToSystemTray))
if !s.config.Application.EnableSystemTray {
closeToTray.Disable()
}
systemTrayEnable := widget.NewCheck("Enable system tray", func(val bool) {
s.config.Application.EnableSystemTray = val
// TODO: see https://github.com/fyne-io/fyne/issues/3788
// Once Fyne supports removing/hiding an existing system tray menu,
// the restart required prompt can be removed and this dialog
// can expose a callback for the Controller to show/hide the system tray menu.
s.setRestartRequired()
if val {
closeToTray.Enable()
} else {
closeToTray.Disable()
}
})
systemTrayEnable.Checked = s.config.Application.EnableSystemTray
// Scrobble settings
twoDigitValidator := func(text string, r rune) bool { twoDigitValidator := func(text string, r rune) bool {
return unicode.IsDigit(r) && len(text) < 2 return unicode.IsDigit(r) && len(text) < 2
} }
@@ -122,6 +148,10 @@ func (s *SettingsDialog) createGeneralTab() *container.TabItem {
scrobbleEnabled.Checked = s.config.Scrobbling.Enabled scrobbleEnabled.Checked = s.config.Scrobbling.Enabled
return container.NewTabItem("General", container.NewVBox( return container.NewTabItem("General", container.NewVBox(
systemTrayEnable,
closeToTray,
s.newSectionSeparator(),
widget.NewRichText(&widget.TextSegment{Text: "Scrobbling", Style: boldStyle}), widget.NewRichText(&widget.TextSegment{Text: "Scrobbling", Style: boldStyle}),
scrobbleEnabled, scrobbleEnabled,
container.NewHBox( container.NewHBox(
@@ -217,7 +247,8 @@ func (s *SettingsDialog) createPlaybackTab() *container.TabItem {
widget.NewLabel("Audio device"), container.NewBorder(nil, nil, nil, util.NewHSpace(70), deviceSelect), widget.NewLabel("Audio device"), container.NewBorder(nil, nil, nil, util.NewHSpace(70), deviceSelect),
layout.NewSpacer(), container.NewHBox(audioExclusive, layout.NewSpacer()), layout.NewSpacer(), container.NewHBox(audioExclusive, layout.NewSpacer()),
)), )),
container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15}, widget.NewSeparator()), s.newSectionSeparator(),
widget.NewRichText(&widget.TextSegment{Text: "ReplayGain", Style: boldStyle}), widget.NewRichText(&widget.TextSegment{Text: "ReplayGain", Style: boldStyle}),
container.New(layout.NewFormLayout(), container.New(layout.NewFormLayout(),
widget.NewLabel("ReplayGain mode"), container.NewGridWithColumns(2, replayGainSelect), widget.NewLabel("ReplayGain mode"), container.NewGridWithColumns(2, replayGainSelect),
@@ -227,6 +258,20 @@ func (s *SettingsDialog) createPlaybackTab() *container.TabItem {
)) ))
} }
func (s *SettingsDialog) setRestartRequired() {
ts := s.promptText.Segments[0].(*widget.TextSegment)
if ts.Text != "" {
return
}
ts.Text = "Restart required"
ts.Style.ColorName = theme.ColorNameError
s.promptText.Refresh()
}
func (s *SettingsDialog) newSectionSeparator() fyne.CanvasObject {
return container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15}, widget.NewSeparator())
}
func (s *SettingsDialog) onReplayGainSettingsChanged() { func (s *SettingsDialog) onReplayGainSettingsChanged() {
if s.OnReplayGainSettingsChanged != nil { if s.OnReplayGainSettingsChanged != nil {
s.OnReplayGainSettingsChanged() s.OnReplayGainSettingsChanged()