app: [js] support for fullscreen mode

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
This commit is contained in:
Inkeliz
2021-03-25 13:18:48 +00:00
committed by Elias Naur
parent 3e525a0393
commit 416094a82c
+21
View File
@@ -77,7 +77,9 @@ func NewWindow(win Callbacks, opts *Options) error {
})
w.addEventListeners()
w.addHistory()
w.windowMode(opts.WindowMode)
w.w = win
go func() {
defer w.cleanup()
w.w.SetDriver(w)
@@ -536,6 +538,25 @@ func (w *window) config() (int, int, system.Insets, unit.Metric) {
}
}
func (w *window) windowMode(mode WindowMode) {
switch mode {
case Windowed:
if fs := w.document.Get("fullscreenElement"); !fs.Truthy() {
return // Browser is already Windowed.
}
if !w.document.Get("exitFullscreen").Truthy() {
return // Browser doesn't support such feature.
}
w.document.Call("exitFullscreen")
case Fullscreen:
elem := w.document.Get("documentElement")
if !elem.Get("requestFullscreen").Truthy() {
return // Browser doesn't support such feature.
}
elem.Call("requestFullscreen")
}
}
func Main() {
select {}
}