-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create settings API to manage theme preferences
Allow reloading of theme to rendered widgets
- Loading branch information
1 parent
2ba5caf
commit 4869829
Showing
9 changed files
with
105 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package app | ||
|
||
import "os" | ||
|
||
// Settings describes the system configuration available and allows configurable | ||
// items to be changed. | ||
type Settings interface { | ||
Theme() string | ||
SetTheme(string) | ||
|
||
AddChangeListener(chan Settings) | ||
} | ||
|
||
type settings struct { | ||
theme string | ||
|
||
changeListeners []chan Settings | ||
} | ||
|
||
var singleton *settings | ||
|
||
func (s *settings) Theme() string { | ||
return s.theme | ||
} | ||
|
||
func (s *settings) SetTheme(theme string) { | ||
s.theme = theme | ||
s.apply() | ||
} | ||
|
||
func (s *settings) AddChangeListener(listener chan Settings) { | ||
s.changeListeners = append(s.changeListeners, listener) | ||
} | ||
|
||
func (s *settings) apply() { | ||
for _, listener := range s.changeListeners { | ||
go func(listener chan Settings) { | ||
listener <- s | ||
}(listener) | ||
} | ||
} | ||
|
||
func loadSettings() *settings { | ||
s := &settings{} | ||
|
||
env := os.Getenv("FYNE_THEME") | ||
if env == "light" { | ||
s.theme = env | ||
} else { | ||
s.theme = "dark" | ||
} | ||
|
||
return s | ||
} | ||
|
||
// GetSettings returns the system wide settings currently configured | ||
func GetSettings() Settings { | ||
if singleton == nil { | ||
singleton = loadSettings() | ||
} | ||
|
||
return singleton | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters