diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index c0370cc57..f42bc366b 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -121,6 +121,9 @@ const ( ) func init() { + // Lock the main thread. + runtime.LockOSThread() + theUI.userInterfaceImpl = userInterfaceImpl{ runnableOnUnfocused: true, minWindowWidthInDIP: glfw.DontCare, @@ -140,9 +143,7 @@ func init() { savedCursorY: math.NaN(), } theUI.iwindow.ui = &theUI.userInterfaceImpl -} -func init() { hideConsoleWindowOnWindows() if err := initialize(); err != nil { @@ -869,11 +870,6 @@ func (u *userInterfaceImpl) DeviceScaleFactor() float64 { return f } -func init() { - // Lock the main thread. - runtime.LockOSThread() -} - // createWindow creates a GLFW window. // // createWindow must be called from the main thread. diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index 2e72dc88d..02a235b53 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -116,14 +116,6 @@ type userInterfaceImpl struct { dropFileM sync.Mutex } -func init() { - theUI.userInterfaceImpl = userInterfaceImpl{ - runnableOnUnfocused: true, - savedCursorX: math.NaN(), - savedCursorY: math.NaN(), - } -} - var ( window = js.Global().Get("window") document = js.Global().Get("document") @@ -133,14 +125,9 @@ var ( ) var ( - documentHasFocus js.Value - documentHidden js.Value -) - -func init() { documentHasFocus = document.Get("hasFocus").Call("bind", document) - documentHidden = js.Global().Get("Object").Call("getOwnPropertyDescriptor", js.Global().Get("Document").Get("prototype"), "hidden").Get("get").Call("bind", document) -} + documentHidden = js.Global().Get("Object").Call("getOwnPropertyDescriptor", js.Global().Get("Document").Get("prototype"), "hidden").Get("get").Call("bind", document) +) func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) { return window.Get("innerWidth").Int(), window.Get("innerHeight").Int() @@ -485,6 +472,12 @@ func (u *userInterfaceImpl) loop(game Game) <-chan error { } func init() { + theUI.userInterfaceImpl = userInterfaceImpl{ + runnableOnUnfocused: true, + savedCursorX: math.NaN(), + savedCursorY: math.NaN(), + } + // docuemnt is undefined on node.js if !document.Truthy() { return