From f908f4bc724c64023a947d077ef209ae9c5c2684 Mon Sep 17 00:00:00 2001 From: zumbiepig <121742281+zumbiepig@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:40:30 -0700 Subject: [PATCH] . --- .../scripts/eagler-launch/1.8.8/main.ts | 3 +- src/resources/scripts/main.ts | 51 ++++++++++++++----- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/resources/scripts/eagler-launch/1.8.8/main.ts b/src/resources/scripts/eagler-launch/1.8.8/main.ts index 6838aa6..e7120de 100644 --- a/src/resources/scripts/eagler-launch/1.8.8/main.ts +++ b/src/resources/scripts/eagler-launch/1.8.8/main.ts @@ -4,7 +4,6 @@ const storage = { get: function (key: string) { const item = localStorage.getItem('minexlauncher'); if (item !== null) { - //const decoded = atob(item); const json = JSON.parse(item); if (json[key] !== undefined) { return json[key]; @@ -50,7 +49,7 @@ window.addEventListener('load', () => { const urlParams = new URLSearchParams(window.location.search); window.eaglercraftXOpts.joinServer = urlParams.get('server') ?? undefined; - window.eaglercraftXOpts.mods = storage.local.get('mods') ?? []; + window.eaglercraftXOpts.Mods = storage.local.get('mods') ?? []; history.replaceState({}, '', '/play'); main(); diff --git a/src/resources/scripts/main.ts b/src/resources/scripts/main.ts index e9d90cf..e6c4f64 100644 --- a/src/resources/scripts/main.ts +++ b/src/resources/scripts/main.ts @@ -104,14 +104,30 @@ const game = { } storage.session.set('lastGame', selectedVersion); + storage.session.set('playingGame', true); + const console = document.querySelector('.console') as HTMLElement | null; + if (console) console.style.display = 'flex'; + if (!window.gameWindow || window.gameWindow.closed) { - window.gameWindow = window.open(version, '_blank', 'popup'); - storage.session.set('playingGame', false); - const console = document.querySelector( - '.console', - ) as HTMLElement | null; - if (console) console.style.display = 'flex'; + window.gameWindow = window.open('about:blank', '_blank', 'popup'); if (window.gameWindow) { + window.gameWindow.document.title = 'MineXLauncher'; + const icon = window.gameWindow.document.createElement('link'); + icon.rel = 'icon'; + icon.href = '/resources/images/icons/favicon.webp'; + window.gameWindow.document.head.append(icon); + + const iframe = window.gameWindow.document.createElement('iframe'); + iframe.src = version; + iframe.width = '100%'; + iframe.height = '100%'; + iframe.style.position = 'fixed'; + iframe.style.top = '0'; + iframe.style.left = '0'; + iframe.style.border = 'none'; + window.gameWindow.onbeforeunload = () => window.gameWindow?.close(); + window.gameWindow.document.body.append(iframe); + window.gameWindow.onload = () => { if (window.gameWindow) { window.gameWindow.console.debug = (msg: string) => @@ -126,13 +142,15 @@ const game = { consoleLog('error', msg); } }; + + window.gameWindow.onbeforeunload = () => game.stop(); } } else { window.gameWindow.focus(); const console = document.querySelector( '.console', ) as HTMLElement | null; - if (console) console.style.display = 'block'; + if (console) console.style.display = 'flex'; } const waitForCrash = setInterval(() => { @@ -155,7 +173,7 @@ const game = { stop: function (error?: string) { if (window !== window.top) window.top?.game.stop(error); else { - if (window.gameWindow) { + if (window.gameWindow && !window.gameWindow.closed) { window.gameWindow.onbeforeunload = null; window.gameWindow.close(); storage.session.set('playingGame', false); @@ -273,14 +291,19 @@ const navigate = { }, }; -function openAboutBlank(url: string): Window | null { +function openAboutBlank( + url: string, + options?: { title?: string; favicon?: string }, +): Window | null { const newWindow = window.open('about:blank', '_blank', 'popup'); if (newWindow) { - newWindow.document.title = 'MineXLauncher'; - const icon = newWindow.document.createElement('link'); - icon.rel = 'icon'; - icon.href = '/resources/images/icons/favicon.webp'; - newWindow.document.head.append(icon); + if (options?.title) newWindow.document.title = options.title; + if (options?.favicon) { + const icon = newWindow.document.createElement('link'); + icon.rel = 'icon'; + icon.href = options.favicon; + newWindow.document.head.append(icon); + } const iframe = newWindow.document.createElement('iframe'); iframe.src = url;