app_theme_js.go 748 B

1234567891011121314151617181920212223242526272829
  1. //go:build !ci && js && !wasm
  2. // +build !ci,js,!wasm
  3. package app
  4. import (
  5. "fyne.io/fyne/v2"
  6. "fyne.io/fyne/v2/theme"
  7. "github.com/gopherjs/gopherjs/js"
  8. )
  9. func defaultVariant() fyne.ThemeVariant {
  10. if matchMedia := js.Global.Call("matchMedia", "(prefers-color-scheme: dark)"); matchMedia != js.Undefined {
  11. if matches := matchMedia.Get("matches"); matches != js.Undefined && matches.Bool() {
  12. return theme.VariantDark
  13. }
  14. return theme.VariantLight
  15. }
  16. return theme.VariantDark
  17. }
  18. func init() {
  19. if matchMedia := js.Global.Call("matchMedia", "(prefers-color-scheme: dark)"); matchMedia != js.Undefined {
  20. matchMedia.Call("addEventListener", "change", func(o *js.Object) {
  21. fyne.CurrentApp().Settings().(*settings).setupTheme()
  22. })
  23. }
  24. }