1
0
mirror of https://github.com/zumbiepig/MineXLauncher.git synced 2025-06-26 10:05:10 +00:00

test offline and pwa

This commit is contained in:
zumbiepig
2024-08-18 20:31:12 -07:00
parent e2a68dd82a
commit 8673dce8a0
12 changed files with 786 additions and 74 deletions

View File

@@ -1,5 +1,13 @@
interface BeforeInstallPromptEvent extends Event {
readonly platforms: string[];
readonly userChoice: Promise<{ outcome: 'accepted' | 'dismissed'; platform: string }>;
prompt(): Promise<{ outcome: 'accepted' | 'dismissed'; platform: string }>;
}
let selectedVersion: string | undefined;
const launcherVersion = '1.5';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let installPwaEvent: BeforeInstallPromptEvent;
const theme = {
load: function (themeToLoad?: string) {
@@ -265,23 +273,22 @@ const detect = {
},
};
if (detect.mobile()) {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = '/resources/styles/mobile.css';
document.head.appendChild(link);
}
theme.load();
if (window.location.pathname === '/') {
window.addEventListener('beforeinstallprompt', (event) => {
installPwaEvent = event as BeforeInstallPromptEvent;
});
} else {
document.addEventListener('DOMContentLoaded', () => {
// @ts-expect-error 123
delete window.installPwaEvent;
if (window.location.pathname !== '/') {
document.addEventListener('DOMContentLoaded', function () {
const profileName = document.getElementById('profile-name');
if (profileName) {
profileName.textContent = storage.local.get('username');
}
});
document.addEventListener('DOMContentLoaded', function () {
document.addEventListener('DOMContentLoaded', () => {
const lastVersion = storage.local.get('lastVersion');
if (lastVersion !== null && lastVersion < launcherVersion) {
alert(`MineXLauncher has been updated to v${launcherVersion}!
@@ -292,3 +299,11 @@ Changes in v${launcherVersion}:
}
});
}
if (detect.mobile()) {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = '/resources/styles/mobile.css';
document.head.appendChild(link);
}
theme.load();

View File

@@ -1,5 +1,5 @@
if (window.location.pathname === '/settings/') {
document.addEventListener('DOMContentLoaded', function () {
document.addEventListener('DOMContentLoaded', () => {
const profileName = document.getElementById('profile-name');
const usernameInput = document.getElementById('username-input') as HTMLInputElement;
const themeSelect = document.getElementById('theme-select') as HTMLSelectElement;
@@ -7,7 +7,7 @@ if (window.location.pathname === '/settings/') {
usernameInput.placeholder = storage.local.get('username') ?? '';
themeSelect.value = storage.local.get('theme') ?? '';
usernameInput.addEventListener('input', function () {
usernameInput.addEventListener('input', () => {
let username = usernameInput.value.replace(/[^A-Za-z0-9]/g, '_').substring(0, 16);
usernameInput.value = username;
while (username.length < 3) {
@@ -19,28 +19,28 @@ if (window.location.pathname === '/settings/') {
}
});
themeSelect.addEventListener('change', function () {
themeSelect.addEventListener('change', () => {
theme.set(themeSelect.value);
});
});
}
if (window.location.pathname === '/welcome.html') {
document.addEventListener('DOMContentLoaded', function () {
document.addEventListener('DOMContentLoaded', () => {
const setupForm = document.getElementById('setup-form') as HTMLFormElement;
const usernameInput = document.getElementById('username-input') as HTMLInputElement;
const themeSelect = document.getElementById('theme-select') as HTMLSelectElement;
usernameInput.addEventListener('input', function () {
usernameInput.addEventListener('input', () => {
const username = usernameInput.value.replace(/[^A-Za-z0-9]/g, '_').substring(0, 16);
usernameInput.value = username;
});
themeSelect.addEventListener('change', function () {
themeSelect.addEventListener('change', () => {
theme.load(themeSelect.value);
});
setupForm.addEventListener('submit', function (event) {
setupForm.addEventListener('submit', (event) => {
event.preventDefault();
let username = usernameInput.value.replace(/[^A-Za-z0-9]/g, '_').substring(0, 16);
@@ -56,6 +56,12 @@ if (window.location.pathname === '/welcome.html') {
storage.local.set('username', username);
storage.local.set('theme', themeSelect.value);
storage.local.set('lastVersion', launcherVersion);
try {
// @ts-expect-error 123
window.top?.installPwaEvent.prompt();
} catch (error) {
console.warn('Failed to prompt PWA install:', error);
}
// @ts-expect-error 123
window.top.location.href = '/';
}