app_theme_wasm.go 705 B

12345678910111213141516171819202122232425262728293031
  1. //go:build !ci && wasm
  2. // +build !ci,wasm
  3. package app
  4. import (
  5. "syscall/js"
  6. "fyne.io/fyne/v2"
  7. "fyne.io/fyne/v2/theme"
  8. )
  9. func defaultVariant() fyne.ThemeVariant {
  10. matches := js.Global().Call("matchMedia", "(prefers-color-scheme: dark)")
  11. if matches.Truthy() {
  12. if matches.Get("matches").Bool() {
  13. return theme.VariantDark
  14. }
  15. return theme.VariantLight
  16. }
  17. return theme.VariantDark
  18. }
  19. func init() {
  20. if matchMedia := js.Global().Call("matchMedia", "(prefers-color-scheme: dark)"); matchMedia.Truthy() {
  21. matchMedia.Call("addEventListener", "change", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
  22. fyne.CurrentApp().Settings().(*settings).setupTheme()
  23. return nil
  24. }))
  25. }
  26. }