From 62f8f821ccfba407c340c37b36b1eb4253187834 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Wed, 29 Mar 2023 08:44:25 -0700 Subject: [PATCH] hook up config settings to light/dark appearance --- backend/config.go | 8 ++++++++ main.go | 1 + ui/theme/theme.go | 24 +++++++++++++++++------- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/backend/config.go b/backend/config.go index ab866ad..91851db 100644 --- a/backend/config.go +++ b/backend/config.go @@ -87,6 +87,10 @@ type ReplayGainConfig struct { PreventClipping bool } +type ThemeConfig struct { + Appearance string +} + type Config struct { Application AppConfig Servers []*ServerConfig @@ -101,6 +105,7 @@ type Config struct { LocalPlayback LocalPlaybackConfig Scrobbling ScrobbleConfig ReplayGain ReplayGainConfig + Theme ThemeConfig } var SupportedStartupPages = []string{"Albums", "Favorites", "Playlists"} @@ -158,6 +163,9 @@ func DefaultConfig(appVersionTag string) *Config { PreampGainDB: 0.0, PreventClipping: true, }, + Theme: ThemeConfig{ + Appearance: "Dark", + }, } } diff --git a/main.go b/main.go index 52a919a..1a9592e 100644 --- a/main.go +++ b/main.go @@ -30,6 +30,7 @@ func main() { fyneApp.Settings().SetTheme(&theme.MyTheme{ NormalFont: myApp.Config.Application.FontNormalTTF, BoldFont: myApp.Config.Application.FontBoldTTF, + Config: &myApp.Config.Theme, }) w := float32(myApp.Config.Application.WindowWidth) if w <= 1 { diff --git a/ui/theme/theme.go b/ui/theme/theme.go index c46a09c..c7bd999 100644 --- a/ui/theme/theme.go +++ b/ui/theme/theme.go @@ -6,7 +6,9 @@ import ( "io/ioutil" "log" "strings" + "supersonic/backend" "supersonic/res" + "supersonic/sharedutil" "fyne.io/fyne/v2" "fyne.io/fyne/v2/theme" @@ -25,12 +27,12 @@ const ( IconNameShuffle fyne.ThemeIconName = "Shuffle" ) -type VariantMode int +type AppearanceMode string const ( - VariantModeAuto VariantMode = iota - VariantModeDark - VariantModeLight + AppearanceLight AppearanceMode = "Light" + AppearanceDark AppearanceMode = "Dark" + AppearanceAuto AppearanceMode = "Auto" ) var ( @@ -41,7 +43,7 @@ var ( type MyTheme struct { NormalFont string BoldFont string - VariantMode VariantMode + Config *backend.ThemeConfig } var _ fyne.Theme = (*MyTheme)(nil) @@ -133,6 +135,7 @@ func (m *MyTheme) Icon(name fyne.ThemeIconName) fyne.Resource { } } +<<<<<<< HEAD func (m *MyTheme) Font(style fyne.TextStyle) fyne.Resource { switch style { case fyne.TextStyle{}: @@ -170,9 +173,16 @@ func (m *MyTheme) Size(name fyne.ThemeSizeName) float32 { } func (m *MyTheme) getVariant() fyne.ThemeVariant { - if m.VariantMode == VariantModeDark { + v := "Dark" // default if config has invalid or missing setting + if sharedutil.StringSliceContains( + []string{string(AppearanceLight), string(AppearanceDark), string(AppearanceAuto)}, + m.Config.Appearance) { + v = m.Config.Appearance + } + + if AppearanceMode(v) == AppearanceDark { return theme.VariantDark - } else if m.VariantMode == VariantModeLight { + } else if AppearanceMode(v) == AppearanceLight { return theme.VariantLight } return fyne.CurrentApp().Settings().ThemeVariant()