Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for login and event processing on loading #591

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/Event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -98,14 +100,27 @@ 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

const now = new Date(getTimePinnedToLoadDate())
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)
Expand Down
41 changes: 26 additions & 15 deletions src/Synergism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -6478,8 +6491,6 @@ window.addEventListener('load', async () => {

corruptionButtonsAdd()
corruptionLoadoutTableCreate()

handleLogin().catch(console.error)
})

window.addEventListener('unload', () => {
Expand Down
Loading