device_goxjs.go 597 B

1234567891011121314151617181920212223242526
  1. //go:build js || wasm
  2. // +build js wasm
  3. package glfw
  4. import (
  5. "regexp"
  6. "syscall/js"
  7. "fyne.io/fyne/v2"
  8. )
  9. var isMobile = regexp.MustCompile("Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile")
  10. var navigator = js.Global().Get("navigator")
  11. var userAgent = navigator.Get("userAgent").String()
  12. var mobileCheck = isMobile.MatchString(userAgent)
  13. func (*glDevice) IsMobile() bool {
  14. return mobileCheck
  15. }
  16. func (*glDevice) SystemScaleForWindow(w fyne.Window) float32 {
  17. // Get the scale information from the web browser directly
  18. return float32(js.Global().Get("devicePixelRatio").Float())
  19. }