diff --git a/src/Event.ts b/src/Event.ts index 0f6b79750..31afb2359 100644 --- a/src/Event.ts +++ b/src/Event.ts @@ -73,6 +73,8 @@ let nowEvent: EventData | null = null export const getEvent = () => nowEvent +let cacheEvents: EventData[] | null = null + export const eventCheck = async () => { if (!player.dayCheck) { return @@ -98,6 +100,19 @@ export const eventCheck = async () => { } }) + cacheEvents = events + + eventUpdate() +} + +export const eventUpdate = async () => { + if (cacheEvents === null) { + await eventCheck() + } + if (cacheEvents === null) { + return + } + const activeEvents: EventData[] = [] nowEvent = null @@ -105,7 +120,7 @@ export const eventCheck = async () => { let start: Date let end: Date - for (const event of events) { + for (const event of cacheEvents) { // TODO: use setDate instead to set the correct day. start = new Date(event.start) end = new Date(event.end) diff --git a/src/Synergism.ts b/src/Synergism.ts index d69d052b6..05a3dca7c 100644 --- a/src/Synergism.ts +++ b/src/Synergism.ts @@ -142,7 +142,10 @@ import { DOMCacheGetOrSet } from './Cache/DOM' import { checkVariablesOnLoad } from './CheckVariables' import { lastUpdated, prod, testing, version } from './Config' import { WowCubes, WowHypercubes, WowPlatonicCubes, WowTesseracts } from './CubeExperimental' -import { eventCheck } from './Event' +import { + eventCheck, + eventUpdate +} from './Event' import { AbyssHepteract, AcceleratorBoostHepteract, @@ -6355,6 +6358,28 @@ export const reloadShit = async (reset = false) => { await loadSynergy() } + // wait for login and event acquisition on loading + // export or singularity won't update them + if (saveCheck.canSave) { + await Promise.allSettled([ + handleLogin().catch(console.error), + eventCheck() + .finally(() => { + setInterval( + () => + eventCheck().catch((error: Error) => { + console.error(error) + }), + 15_000 + ) + }) + ]) + } else { + eventUpdate() + } + cacheReinitialize() + dailyResetCheck() + if (!reset) { await calculateOffline() } else { @@ -6392,23 +6417,11 @@ export const reloadShit = async (reset = false) => { changeSubTab(Tabs.Singularity, { page: 0 }) // set 'singularity main' changeSubTab(Tabs.Settings, { page: 0 }) // set 'statistics main' - dailyResetCheck() setInterval(dailyResetCheck, 30000) constantIntervals() changeTabColor() - eventCheck() - .catch(() => {}) - .finally(() => { - setInterval( - () => - eventCheck().catch((error: Error) => { - console.error(error) - }), - 15_000 - ) - }) showExitOffline() clearTimeout(preloadDeleteGame) @@ -6478,8 +6491,6 @@ window.addEventListener('load', async () => { corruptionButtonsAdd() corruptionLoadoutTableCreate() - - handleLogin().catch(console.error) }) window.addEventListener('unload', () => {