diff --git a/package.json b/package.json index 919689051..988bd9373 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "husky": "^8.0.3", "stylelint": "^14.8.2", "stylelint-config-standard": "^25.0.0", - "typescript": "^5.0.3" + "typescript": "^5.5.3" }, "scripts": { "lint": "npx @biomejs/biome lint .", diff --git a/src/Event.ts b/src/Event.ts index 6177c5c61..6b2b0a3ab 100644 --- a/src/Event.ts +++ b/src/Event.ts @@ -75,10 +75,6 @@ let nowEvent: EventData | null = null export const getEvent = () => nowEvent export const eventCheck = async () => { - if (!player.dayCheck) { - return - } - const response = await fetch('https://synergism.cc/api/v1/events/get') if (!response.ok) { diff --git a/src/ImportExport.ts b/src/ImportExport.ts index 27b8bd7ff..4318e68a9 100644 --- a/src/ImportExport.ts +++ b/src/ImportExport.ts @@ -311,7 +311,7 @@ export const resetGame = async (force = true) => { export const importData = async ( e: Event, - importFunc: (save: string | null) => Promise | Promise + importFunc: typeof importSynergism ) => { const element = e.target as HTMLInputElement const file = element.files![0] @@ -333,10 +333,10 @@ export const importData = async ( element.value = '' handleLastModified(file.lastModified) - return importFunc(save) + return importFunc(save, false) } -export const importSynergism = async (input: string | null, reset = false) => { +export const importSynergism = async (input: string | null, reset: boolean) => { if (typeof input !== 'string') { return Alert(i18next.t('importexport.unableImport')) } diff --git a/src/Synergism.ts b/src/Synergism.ts index 3e7733a51..1ffc90314 100644 --- a/src/Synergism.ts +++ b/src/Synergism.ts @@ -6161,11 +6161,13 @@ export const showExitOffline = () => { setTimeout(() => el.focus(), 100) } +let loggedIn = false + /** * Reloads shit. * @param reset if this param is passed, offline progression will not be calculated. */ -export const reloadShit = async (reset = false) => { +export const reloadShit = async (reset: boolean) => { clearTimers() // Shows a reset button when page loading seems to stop or cause an error @@ -6176,12 +6178,6 @@ export const reloadShit = async (reset = false) => { disableHotkeys() - // Wait a tick to continue. This is a (likely futile) attempt to see if this solves save corrupting. - // This ensures all queued tasks are executed before continuing on. - await new Promise((res) => { - setTimeout(res, 0) - }) - const save = (await localforage.getItem('Synergysave2')) ?? localStorage.getItem('Synergysave2') @@ -6213,6 +6209,18 @@ export const reloadShit = async (reset = false) => { } if (!reset) { + loggedIn ||= !!await Promise.allSettled([ + handleLogin(), + eventCheck() + .catch(console.error) + .finally(() => { + setInterval( + () => eventCheck().catch(console.error), + 15_000 + ) + }) + ]) + await calculateOffline() } else { player.worlds.reset() @@ -6256,17 +6264,6 @@ export const reloadShit = async (reset = false) => { constantIntervals() changeTabColor() - eventCheck() - .catch(() => {}) - .finally(() => { - setInterval( - () => - eventCheck().catch((error: Error) => { - console.error(error) - }), - 15_000 - ) - }) showExitOffline() clearTimeout(preloadDeleteGame) @@ -6331,13 +6328,10 @@ window.addEventListener('load', async () => { document.title = `Synergism v${version}` generateEventHandlers() - - void reloadShit() - corruptionButtonsAdd() corruptionLoadoutTableCreate() - handleLogin().catch(console.error) + reloadShit(false) }) window.addEventListener('unload', () => {