From 569db3dac7891a1b6f928e63e53e7595eaafba97 Mon Sep 17 00:00:00 2001 From: Ethan O'Brien <77750390+ethanaobrien@users.noreply.github.com> Date: Mon, 2 Oct 2023 18:13:15 -0500 Subject: [PATCH] Add safari mobile "workaround" for freezing --- data/emulator.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/data/emulator.js b/data/emulator.js index e33bf0c..6dc9b54 100644 --- a/data/emulator.js +++ b/data/emulator.js @@ -1093,6 +1093,10 @@ class EmulatorJS { if (this.debug) console.warn("Could not fullscreen on load"); } } + if (this.isSafari && this.isMobile) { + //Safari is --- funny + this.checkStarted(); + } } catch(e) { console.warn("failed to start game", e); this.textElem.innerText = this.localization("Failed to start game"); @@ -1101,6 +1105,33 @@ class EmulatorJS { } this.callEvent("start"); } + checkStarted() { + (async() => { + let sleep = (ms) => new Promise(r => setTimeout(r, ms)); + let state = "suspended"; + let popup; + while (state === "suspended") { + if (!window.AL) return; + window.AL.currentCtx.sources.forEach(ctx => { + state = ctx.gain.context.state; + }); + if (state !== "suspended") break; + if (!popup) { + popup = this.createPopup("", {}); + const button = this.createElement("button"); + button.innerText = "Click to resume Emulator"; + button.classList.add("ejs_menu_button"); + button.style.width = "25%"; + button.style.height = "25%"; + popup.appendChild(button); + popup.style["text-align"] = "center"; + popup.style["font-size"] = "28px"; + } + await sleep(10); + } + if (popup) this.closePopup(); + })(); + } bindListeners() { this.createContextMenu(); this.createBottomMenuBar();