1
0
mirror of https://github.com/zumbiepig/MineXLauncher.git synced 2025-06-08 09:24:48 +00:00
This commit is contained in:
zumbiepig 2024-09-10 16:40:30 -07:00
parent 990099c935
commit f908f4bc72
No known key found for this signature in database
GPG Key ID: 17C891BE28B953DE
2 changed files with 38 additions and 16 deletions

View File

@ -4,7 +4,6 @@ const storage = {
get: function (key: string) { get: function (key: string) {
const item = localStorage.getItem('minexlauncher'); const item = localStorage.getItem('minexlauncher');
if (item !== null) { if (item !== null) {
//const decoded = atob(item);
const json = JSON.parse(item); const json = JSON.parse(item);
if (json[key] !== undefined) { if (json[key] !== undefined) {
return json[key]; return json[key];
@ -50,7 +49,7 @@ window.addEventListener('load', () => {
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
window.eaglercraftXOpts.joinServer = urlParams.get('server') ?? undefined; window.eaglercraftXOpts.joinServer = urlParams.get('server') ?? undefined;
window.eaglercraftXOpts.mods = storage.local.get('mods') ?? []; window.eaglercraftXOpts.Mods = storage.local.get('mods') ?? [];
history.replaceState({}, '', '/play'); history.replaceState({}, '', '/play');
main(); main();

View File

@ -104,14 +104,30 @@ const game = {
} }
storage.session.set('lastGame', selectedVersion); storage.session.set('lastGame', selectedVersion);
if (!window.gameWindow || window.gameWindow.closed) { storage.session.set('playingGame', true);
window.gameWindow = window.open(version, '_blank', 'popup'); const console = document.querySelector('.console') as HTMLElement | null;
storage.session.set('playingGame', false);
const console = document.querySelector(
'.console',
) as HTMLElement | null;
if (console) console.style.display = 'flex'; if (console) console.style.display = 'flex';
if (!window.gameWindow || window.gameWindow.closed) {
window.gameWindow = window.open('about:blank', '_blank', 'popup');
if (window.gameWindow) { 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 = () => { window.gameWindow.onload = () => {
if (window.gameWindow) { if (window.gameWindow) {
window.gameWindow.console.debug = (msg: string) => window.gameWindow.console.debug = (msg: string) =>
@ -126,13 +142,15 @@ const game = {
consoleLog('error', msg); consoleLog('error', msg);
} }
}; };
window.gameWindow.onbeforeunload = () => game.stop();
} }
} else { } else {
window.gameWindow.focus(); window.gameWindow.focus();
const console = document.querySelector( const console = document.querySelector(
'.console', '.console',
) as HTMLElement | null; ) as HTMLElement | null;
if (console) console.style.display = 'block'; if (console) console.style.display = 'flex';
} }
const waitForCrash = setInterval(() => { const waitForCrash = setInterval(() => {
@ -155,7 +173,7 @@ const game = {
stop: function (error?: string) { stop: function (error?: string) {
if (window !== window.top) window.top?.game.stop(error); if (window !== window.top) window.top?.game.stop(error);
else { else {
if (window.gameWindow) { if (window.gameWindow && !window.gameWindow.closed) {
window.gameWindow.onbeforeunload = null; window.gameWindow.onbeforeunload = null;
window.gameWindow.close(); window.gameWindow.close();
storage.session.set('playingGame', false); 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'); const newWindow = window.open('about:blank', '_blank', 'popup');
if (newWindow) { if (newWindow) {
newWindow.document.title = 'MineXLauncher'; if (options?.title) newWindow.document.title = options.title;
if (options?.favicon) {
const icon = newWindow.document.createElement('link'); const icon = newWindow.document.createElement('link');
icon.rel = 'icon'; icon.rel = 'icon';
icon.href = '/resources/images/icons/favicon.webp'; icon.href = options.favicon;
newWindow.document.head.append(icon); newWindow.document.head.append(icon);
}
const iframe = newWindow.document.createElement('iframe'); const iframe = newWindow.document.createElement('iframe');
iframe.src = url; iframe.src = url;