internal/ui: merge init functions

The Go specification doesn't determine the order of init functions.
In order to reduce unexpected behavior, merge some init functions.
This commit is contained in:
Hajime Hoshi 2023-10-15 00:15:20 +09:00
parent 567e2fa04c
commit 2a8d8d71fc
2 changed files with 11 additions and 22 deletions

View File

@ -121,6 +121,9 @@ const (
) )
func init() { func init() {
// Lock the main thread.
runtime.LockOSThread()
theUI.userInterfaceImpl = userInterfaceImpl{ theUI.userInterfaceImpl = userInterfaceImpl{
runnableOnUnfocused: true, runnableOnUnfocused: true,
minWindowWidthInDIP: glfw.DontCare, minWindowWidthInDIP: glfw.DontCare,
@ -140,9 +143,7 @@ func init() {
savedCursorY: math.NaN(), savedCursorY: math.NaN(),
} }
theUI.iwindow.ui = &theUI.userInterfaceImpl theUI.iwindow.ui = &theUI.userInterfaceImpl
}
func init() {
hideConsoleWindowOnWindows() hideConsoleWindowOnWindows()
if err := initialize(); err != nil { if err := initialize(); err != nil {
@ -869,11 +870,6 @@ func (u *userInterfaceImpl) DeviceScaleFactor() float64 {
return f return f
} }
func init() {
// Lock the main thread.
runtime.LockOSThread()
}
// createWindow creates a GLFW window. // createWindow creates a GLFW window.
// //
// createWindow must be called from the main thread. // createWindow must be called from the main thread.

View File

@ -116,14 +116,6 @@ type userInterfaceImpl struct {
dropFileM sync.Mutex dropFileM sync.Mutex
} }
func init() {
theUI.userInterfaceImpl = userInterfaceImpl{
runnableOnUnfocused: true,
savedCursorX: math.NaN(),
savedCursorY: math.NaN(),
}
}
var ( var (
window = js.Global().Get("window") window = js.Global().Get("window")
document = js.Global().Get("document") document = js.Global().Get("document")
@ -133,14 +125,9 @@ var (
) )
var ( var (
documentHasFocus js.Value
documentHidden js.Value
)
func init() {
documentHasFocus = document.Get("hasFocus").Call("bind", document) 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) { func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
return window.Get("innerWidth").Int(), window.Get("innerHeight").Int() return window.Get("innerWidth").Int(), window.Get("innerHeight").Int()
@ -485,6 +472,12 @@ func (u *userInterfaceImpl) loop(game Game) <-chan error {
} }
func init() { func init() {
theUI.userInterfaceImpl = userInterfaceImpl{
runnableOnUnfocused: true,
savedCursorX: math.NaN(),
savedCursorY: math.NaN(),
}
// docuemnt is undefined on node.js // docuemnt is undefined on node.js
if !document.Truthy() { if !document.Truthy() {
return return