Add new EJS_fullscreenOnLoaded option

This commit is contained in:
Ethan O'Brien 2023-08-12 11:10:30 -05:00
parent 41676496e8
commit e24cc0a84b
2 changed files with 49 additions and 32 deletions

View file

@ -995,6 +995,13 @@ class EmulatorJS {
this.virtualGamepad.style.display = "";
}
this.handleResize();
if (this.config.fullscreenOnLoad) {
try {
this.toggleFullscreen(true);
} catch(e) {
if (this.debug) console.warn("Could not fullscreen on load");
}
}
} catch(e) {
console.warn("failed to start game", e);
this.textElem.innerText = this.localization("Failed to start game");
@ -1614,43 +1621,52 @@ class EmulatorJS {
})
const enter = addButton("Enter Fullscreen", '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M208 281.4c-12.5-12.5-32.76-12.5-45.26-.002l-78.06 78.07l-30.06-30.06c-6.125-6.125-14.31-9.367-22.63-9.367c-4.125 0-8.279 .7891-12.25 2.43c-11.97 4.953-19.75 16.62-19.75 29.56v135.1C.0013 501.3 10.75 512 24 512h136c12.94 0 24.63-7.797 29.56-19.75c4.969-11.97 2.219-25.72-6.938-34.87l-30.06-30.06l78.06-78.07c12.5-12.49 12.5-32.75 .002-45.25L208 281.4zM487.1 0h-136c-12.94 0-24.63 7.797-29.56 19.75c-4.969 11.97-2.219 25.72 6.938 34.87l30.06 30.06l-78.06 78.07c-12.5 12.5-12.5 32.76 0 45.26l22.62 22.62c12.5 12.5 32.76 12.5 45.26 0l78.06-78.07l30.06 30.06c9.156 9.141 22.87 11.84 34.87 6.937C504.2 184.6 512 172.9 512 159.1V23.1C512 10.74 501.3 0 487.1 0z"/></svg>', () => {
if (this.elements.parent.requestFullscreen) {
this.elements.parent.requestFullscreen();
} else if (this.elements.parent.mozRequestFullScreen) {
this.elements.parent.mozRequestFullScreen();
} else if (this.elements.parent.webkitRequestFullscreen) {
this.elements.parent.webkitRequestFullscreen();
} else if (this.elements.parent.msRequestFullscreen) {
this.elements.parent.msRequestFullscreen();
}
exit.style.display = "";
enter.style.display = "none";
if (this.isMobile) {
try {
screen.orientation.lock(this.getCore(true) === "nds" ? "portrait" : "landscape").catch(e => {});;
} catch(e) {}
}
this.toggleFullscreen(true);
});
const exit = addButton("Exit Fullscreen", '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M215.1 272h-136c-12.94 0-24.63 7.797-29.56 19.75C45.47 303.7 48.22 317.5 57.37 326.6l30.06 30.06l-78.06 78.07c-12.5 12.5-12.5 32.75-.0012 45.25l22.62 22.62c12.5 12.5 32.76 12.5 45.26 .0013l78.06-78.07l30.06 30.06c6.125 6.125 14.31 9.367 22.63 9.367c4.125 0 8.279-.7891 12.25-2.43c11.97-4.953 19.75-16.62 19.75-29.56V296C239.1 282.7 229.3 272 215.1 272zM296 240h136c12.94 0 24.63-7.797 29.56-19.75c4.969-11.97 2.219-25.72-6.938-34.87l-30.06-30.06l78.06-78.07c12.5-12.5 12.5-32.76 .0002-45.26l-22.62-22.62c-12.5-12.5-32.76-12.5-45.26-.0003l-78.06 78.07l-30.06-30.06c-9.156-9.141-22.87-11.84-34.87-6.937c-11.97 4.953-19.75 16.62-19.75 29.56v135.1C272 229.3 282.7 240 296 240z"/></svg>', () => {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
exit.style.display = "none";
enter.style.display = "";
if (this.isMobile) {
try {
screen.orientation.unlock();
} catch(e) {}
}
this.toggleFullscreen(false);
});
exit.style.display = "none";
this.toggleFullscreen = (fullscreen) => {
if (fullscreen) {
if (this.elements.parent.requestFullscreen) {
this.elements.parent.requestFullscreen();
} else if (this.elements.parent.mozRequestFullScreen) {
this.elements.parent.mozRequestFullScreen();
} else if (this.elements.parent.webkitRequestFullscreen) {
this.elements.parent.webkitRequestFullscreen();
} else if (this.elements.parent.msRequestFullscreen) {
this.elements.parent.msRequestFullscreen();
}
exit.style.display = "";
enter.style.display = "none";
if (this.isMobile) {
try {
screen.orientation.lock(this.getCore(true) === "nds" ? "portrait" : "landscape").catch(e => {});;
} catch(e) {}
}
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
exit.style.display = "none";
enter.style.display = "";
if (this.isMobile) {
try {
screen.orientation.unlock();
} catch(e) {}
}
}
}
this.addEventListener(document, "webkitfullscreenchange mozfullscreenchange fullscreenchange", (e) => {
if (e.target !== this.elements.parent) return;
if (document.fullscreenElement === null) {

View file

@ -61,6 +61,7 @@
config.volume = window.EJS_volume;
config.defaultControllers = window.EJS_defaultControls;
config.startOnLoad = window.EJS_startOnLoaded;
config.fullscreenOnLoad = window.EJS_fullscreenOnLoaded;
config.filePaths = window.EJS_paths;
config.loadState = window.EJS_loadStateURL;
config.cacheLimit = window.EJS_CacheLimit;