Web - try to detect native fullscreen (#106479)

* web - try to detect native fullscreen

* add logging for debugging

* throttle listener

* adjust

* .

* add check for windows
This commit is contained in:
Benjamin Pasero
2020-09-15 08:03:17 +02:00
committed by GitHub
parent e13875b77c
commit fcf3346a8e
2 changed files with 82 additions and 12 deletions

View File

@@ -1277,3 +1277,66 @@ export function triggerDownload(dataOrUri: Uint8Array | URI, name: string): void
// Ensure to remove the element from DOM eventually
setTimeout(() => document.body.removeChild(anchor));
}
export enum DetectedFullscreenMode {
/**
* The document is fullscreen, e.g. because an element
* in the document requested to be fullscreen.
*/
DOCUMENT = 1,
/**
* The browser is fullsreen, e.g. because the user enabled
* native window fullscreen for it.
*/
BROWSER
}
export interface IDetectedFullscreen {
/**
* Figure out if the document is fullscreen or the browser.
*/
mode: DetectedFullscreenMode;
/**
* Wether we know for sure that we are in fullscreen mode or
* it is a guess.
*/
guess: boolean;
}
export function detectFullscreen(): IDetectedFullscreen | null {
// Browser fullscreen: use DOM APIs to detect
if (document.fullscreenElement || (<any>document).webkitFullscreenElement || (<any>document).webkitIsFullScreen) {
return { mode: DetectedFullscreenMode.DOCUMENT, guess: false };
}
// There is no standard way to figure out if the browser
// is using native fullscreen. Via checking on screen
// height and comparing that to window height, we can guess
// it though.
if (window.innerHeight === screen.height) {
// if the height of the window matches the screen height, we can
// safely assume that the browser is fullscreen because no browser
// chrome is taking height away (e.g. like toolbars).
return { mode: DetectedFullscreenMode.BROWSER, guess: false };
}
if (platform.isMacintosh || platform.isLinux) {
// macOS and Linux do not properly report `innerHeight`, only Windows does
if (window.outerHeight === screen.height && window.outerWidth === screen.width) {
// if the height of the browser matches the screen height, we can
// only guess that we are in fullscreen. It is also possible that
// the user has turned off taskbars in the OS and the browser is
// simply able to span the entire size of the screen.
return { mode: DetectedFullscreenMode.BROWSER, guess: true };
}
}
// Not in fullscreen
return null;
}