hook up config settings to light/dark appearance

This commit is contained in:
Drew Weymouth
2023-05-01 17:45:34 -07:00
parent cdac9ae66f
commit 62f8f821cc
3 changed files with 26 additions and 7 deletions
+8
View File
@@ -87,6 +87,10 @@ type ReplayGainConfig struct {
PreventClipping bool PreventClipping bool
} }
type ThemeConfig struct {
Appearance string
}
type Config struct { type Config struct {
Application AppConfig Application AppConfig
Servers []*ServerConfig Servers []*ServerConfig
@@ -101,6 +105,7 @@ type Config struct {
LocalPlayback LocalPlaybackConfig LocalPlayback LocalPlaybackConfig
Scrobbling ScrobbleConfig Scrobbling ScrobbleConfig
ReplayGain ReplayGainConfig ReplayGain ReplayGainConfig
Theme ThemeConfig
} }
var SupportedStartupPages = []string{"Albums", "Favorites", "Playlists"} var SupportedStartupPages = []string{"Albums", "Favorites", "Playlists"}
@@ -158,6 +163,9 @@ func DefaultConfig(appVersionTag string) *Config {
PreampGainDB: 0.0, PreampGainDB: 0.0,
PreventClipping: true, PreventClipping: true,
}, },
Theme: ThemeConfig{
Appearance: "Dark",
},
} }
} }
+1
View File
@@ -30,6 +30,7 @@ func main() {
fyneApp.Settings().SetTheme(&theme.MyTheme{ fyneApp.Settings().SetTheme(&theme.MyTheme{
NormalFont: myApp.Config.Application.FontNormalTTF, NormalFont: myApp.Config.Application.FontNormalTTF,
BoldFont: myApp.Config.Application.FontBoldTTF, BoldFont: myApp.Config.Application.FontBoldTTF,
Config: &myApp.Config.Theme,
}) })
w := float32(myApp.Config.Application.WindowWidth) w := float32(myApp.Config.Application.WindowWidth)
if w <= 1 { if w <= 1 {
+17 -7
View File
@@ -6,7 +6,9 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"strings" "strings"
"supersonic/backend"
"supersonic/res" "supersonic/res"
"supersonic/sharedutil"
"fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/theme"
@@ -25,12 +27,12 @@ const (
IconNameShuffle fyne.ThemeIconName = "Shuffle" IconNameShuffle fyne.ThemeIconName = "Shuffle"
) )
type VariantMode int type AppearanceMode string
const ( const (
VariantModeAuto VariantMode = iota AppearanceLight AppearanceMode = "Light"
VariantModeDark AppearanceDark AppearanceMode = "Dark"
VariantModeLight AppearanceAuto AppearanceMode = "Auto"
) )
var ( var (
@@ -41,7 +43,7 @@ var (
type MyTheme struct { type MyTheme struct {
NormalFont string NormalFont string
BoldFont string BoldFont string
VariantMode VariantMode Config *backend.ThemeConfig
} }
var _ fyne.Theme = (*MyTheme)(nil) 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 { func (m *MyTheme) Font(style fyne.TextStyle) fyne.Resource {
switch style { switch style {
case fyne.TextStyle{}: case fyne.TextStyle{}:
@@ -170,9 +173,16 @@ func (m *MyTheme) Size(name fyne.ThemeSizeName) float32 {
} }
func (m *MyTheme) getVariant() fyne.ThemeVariant { 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 return theme.VariantDark
} else if m.VariantMode == VariantModeLight { } else if AppearanceMode(v) == AppearanceLight {
return theme.VariantLight return theme.VariantLight
} }
return fyne.CurrentApp().Settings().ThemeVariant() return fyne.CurrentApp().Settings().ThemeVariant()