Skip to content

Commit 9317d63

Browse files
committed
Better system theme detection.
1 parent 1611920 commit 9317d63

File tree

5 files changed

+15
-21
lines changed

5 files changed

+15
-21
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/alexballas/go2tv
33
go 1.23.3
44

55
require (
6-
fyne.io/fyne/v2 v2.5.3
6+
fyne.io/fyne/v2 v2.5.2
77
github.com/alexballas/go-ssdp v0.0.3
88
github.com/gdamore/tcell/v2 v2.7.4
99
github.com/h2non/filetype v1.1.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
3737
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
3838
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
3939
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
40-
fyne.io/fyne/v2 v2.5.3 h1:k6LjZx6EzRZhClsuzy6vucLZBstdH2USDGHSGWq8ly8=
41-
fyne.io/fyne/v2 v2.5.3/go.mod h1:0GOXKqyvNwk3DLmsFu9v0oYM0ZcD1ysGnlHCerKoAmo=
40+
fyne.io/fyne/v2 v2.5.2 h1:eSyGTmSkv10yAdAeHpDet6u2KkKxOGFc14kQu81We7Q=
41+
fyne.io/fyne/v2 v2.5.2/go.mod h1:26gqPDvtaxHeyct+C0BBjuGd2zwAJlPkUGSBrb+d7Ug=
4242
fyne.io/systray v1.11.0 h1:D9HISlxSkx+jHSniMBR6fCFOUjk1x/OOOJLa9lJYAKg=
4343
fyne.io/systray v1.11.0/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs=
4444
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

internal/gui/gui.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type FyneScreen struct {
6767
currentmfolder string
6868
ffmpegPath string
6969
ffmpegSeek int
70+
systemTheme fyne.ThemeVariant
7071
mediaFormats []string
7172
muError sync.RWMutex
7273
mu sync.RWMutex

internal/gui/settings.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ func settingsWindow(s *FyneScreen) fyne.CanvasObject {
3636
themeName := lang.L(fyne.CurrentApp().Preferences().StringWithFallback("Theme", "System Default"))
3737
dropdownTheme.PlaceHolder = themeName
3838
parseTheme(themeName)
39-
go detectSystemThemeChange()
39+
40+
s.systemTheme = fyne.CurrentApp().Settings().ThemeVariant()
41+
go detectSystemThemeChange(s)
4042

4143
ffmpegText := widget.NewLabel("ffmpeg " + lang.L("Path"))
4244
ffmpegTextEntry := widget.NewEntry()
@@ -177,13 +179,9 @@ func parseTheme(t string) {
177179
fyne.CurrentApp().Settings().SetTheme(go2tvTheme{"Dark"})
178180
fyne.CurrentApp().Preferences().SetString("Theme", "Dark")
179181
default:
180-
fyne.CurrentApp().Settings().SetTheme(go2tvTheme{"System Default"})
181182
fyne.CurrentApp().Preferences().SetString("Theme", "System Default")
182183

183-
// Wait for the SystemVariant variable to change
184-
<-signalSystemVariantChange
185-
186-
switch systemVariant {
184+
switch fyne.CurrentApp().Settings().ThemeVariant() {
187185
case theme.VariantDark:
188186
fyne.CurrentApp().Settings().SetTheme(go2tvTheme{"Dark"})
189187
case theme.VariantLight:
@@ -212,16 +210,17 @@ func parseLanguage(s *FyneScreen) func(string) {
212210
}
213211
}
214212

215-
func detectSystemThemeChange() {
213+
func detectSystemThemeChange(s *FyneScreen) {
216214
tik := time.NewTicker(time.Second)
215+
217216
for range tik.C {
217+
currentSystemTheme := fyne.CurrentApp().Settings().ThemeVariant()
218218
themeName := fyne.CurrentApp().Preferences().StringWithFallback("Theme", "System Default")
219-
if themeName == "System Default" {
220-
fyne.CurrentApp().Settings().SetTheme(go2tvTheme{"System Default"})
221-
// Wait for the SystemVariant variable to change
222-
<-signalSystemVariantChange
223219

224-
switch systemVariant {
220+
if s.systemTheme != currentSystemTheme && themeName == "System Default" {
221+
s.systemTheme = currentSystemTheme
222+
223+
switch s.systemTheme {
225224
case theme.VariantDark:
226225
fyne.CurrentApp().Settings().SetTheme(go2tvTheme{"Dark"})
227226
case theme.VariantLight:

internal/gui/theme.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ var (
1919

2020
func (m go2tvTheme) Color(name fyne.ThemeColorName, variant fyne.ThemeVariant) color.Color {
2121
switch m.Theme {
22-
case "System Default":
23-
systemVariant = variant
24-
go func() {
25-
signalSystemVariantChange <- struct{}{}
26-
}()
27-
2822
case "Dark":
2923
variant = theme.VariantDark
3024
switch name {

0 commit comments

Comments
 (0)