internal/ui: refactoring

This commit is contained in:
Hajime Hoshi 2024-07-04 16:58:45 +09:00
parent 3a18b32cbd
commit ed73f028c7

View File

@ -729,14 +729,28 @@ func (u *UserInterface) forceUpdateOnMinimumFPSMode() {
}() }()
} }
func (u *UserInterface) initOnMainThread(options *RunOptions) error { func (u *UserInterface) shouldFocusFirst(options *RunOptions) bool {
if !options.InitUnfocused && window.Truthy() { if options.InitUnfocused {
return false
}
if !window.Truthy() {
return false
}
// Do not focus the canvas when the current document is in an iframe. // Do not focus the canvas when the current document is in an iframe.
// Otherwise, the parent page tries to focus the iframe on every loading, which is annoying (#1373). // Otherwise, the parent page tries to focus the iframe on every loading, which is annoying (#1373).
isInIframe := !window.Get("location").Equal(window.Get("parent").Get("location")) parent := window.Get("parent")
isInIframe := !window.Get("location").Equal(parent.Get("location"))
if !isInIframe { if !isInIframe {
canvas.Call("focus") return true
} }
return false
}
func (u *UserInterface) initOnMainThread(options *RunOptions) error {
if u.shouldFocusFirst(options) {
canvas.Call("focus")
} }
g, lib, err := newGraphicsDriver(&graphicsDriverCreatorImpl{ g, lib, err := newGraphicsDriver(&graphicsDriverCreatorImpl{