Skip to content

Commit

Permalink
Remove Default theme'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexballas committed May 5, 2024
1 parent 215576c commit 7a8a572
Showing 1 changed file with 41 additions and 22 deletions.
63 changes: 41 additions & 22 deletions internal/gui/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package gui

import (
"image/color"
"sync"
"time"

"fyne.io/fyne/v2"
Expand All @@ -20,9 +21,16 @@ type go2tvTheme struct {
}

var _ fyne.Theme = go2tvTheme{}
var SystemVariant fyne.ThemeVariant = 999
var once sync.Once

func (m go2tvTheme) Color(name fyne.ThemeColorName, variant fyne.ThemeVariant) color.Color {
switch m.Theme {
case "GrabVariant":
once.Do(func() {
SystemVariant = variant
})

case "Dark":
variant = theme.VariantDark
switch name {
Expand Down Expand Up @@ -71,15 +79,31 @@ func settingsWindow(s *NewScreen) fyne.CanvasObject {
w := s.Current

themeText := widget.NewLabel("Theme")
dropdown := widget.NewSelect([]string{"Light", "Dark", "Default"}, parseTheme(s))
theme := fyne.CurrentApp().Preferences().StringWithFallback("Theme", "Default")
switch theme {
dropdown := widget.NewSelect([]string{"Light", "Dark"}, parseTheme)
themeName := fyne.CurrentApp().Preferences().StringWithFallback("Theme", "GrabVariant")

switch themeName {
case "Light":
dropdown.PlaceHolder = "Light"
case "Dark":
dropdown.PlaceHolder = "Dark"
case "Default":
dropdown.PlaceHolder = "Default"
case "GrabVariant":
fyne.CurrentApp().Settings().SetTheme(go2tvTheme{"GrabVariant"})

// Wait for SystemVariant to get the correct variant from the command above
for SystemVariant == 999 {
time.Sleep(time.Millisecond)
}

switch SystemVariant {
case theme.VariantDark:
dropdown.PlaceHolder = "Dark"
parseTheme("Dark")
case theme.VariantLight:
dropdown.PlaceHolder = "Light"
parseTheme("Light")
}

}

debugText := widget.NewLabel("Debug")
Expand Down Expand Up @@ -164,21 +188,16 @@ func saveDebugLogs(f fyne.URIWriteCloser, s *NewScreen) {
dialog.ShowInformation("Debug", "Saved to... "+f.URI().String(), w)
}

func parseTheme(s *NewScreen) func(string) {
return func(t string) {
go func() {
time.Sleep(10 * time.Millisecond)
switch t {
case "Light":
fyne.CurrentApp().Preferences().SetString("Theme", "Light")
fyne.CurrentApp().Settings().SetTheme(go2tvTheme{"Light"})
case "Dark":
fyne.CurrentApp().Preferences().SetString("Theme", "Dark")
fyne.CurrentApp().Settings().SetTheme(go2tvTheme{"Dark"})
case "Default":
fyne.CurrentApp().Preferences().SetString("Theme", "Default")
fyne.CurrentApp().Settings().SetTheme(go2tvTheme{"Default"})
}
}()
}
func parseTheme(t string) {
go func() {
time.Sleep(10 * time.Millisecond)
switch t {
case "Light":
fyne.CurrentApp().Preferences().SetString("Theme", "Light")
fyne.CurrentApp().Settings().SetTheme(go2tvTheme{"Light"})
case "Dark":
fyne.CurrentApp().Preferences().SetString("Theme", "Dark")
fyne.CurrentApp().Settings().SetTheme(go2tvTheme{"Dark"})
}
}()
}

0 comments on commit 7a8a572

Please sign in to comment.