Skip to content

Commit

Permalink
Refactor tab activation handling in saveDb function (#352)
Browse files Browse the repository at this point in the history
# PR Checklist
- [ ] Did you check if it works normally in all models? *ignore this
when it dosen't uses models*
- [ ] Did you check if it works normally in all of web, local and node
hosted versions? if it dosen't, did you blocked it in those versions?
- [ ] Did you added a type def?

# Description
  • Loading branch information
kwaroran authored Apr 8, 2024
2 parents e8dc68b + 653fb6f commit 2f51f26
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/ts/storage/globalApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,17 @@ export async function saveDb(){
})
let gotChannel = false
const sessionID = v4()
const channel = new BroadcastChannel('risu-save-channel')
channel.onmessage = async (ev) => {
if(ev.data === sessionID){
return
}
if(!gotChannel){
gotChannel = true
await alertNormalWait(language.activeTabChange)
gotChannel = false
const channel = BroadcastChannel ? (new BroadcastChannel('risu-active')): null
if(channel){
channel.onmessage = async (ev) => {
if(ev.data === sessionID){
return
}
if(!gotChannel){
gotChannel = true
await alertNormalWait(language.activeTabChange)
gotChannel = false
}
}
}
let savetrys = 0
Expand All @@ -281,7 +283,9 @@ export async function saveDb(){
await sleep(1000)
continue
}
channel.postMessage(sessionID)
if(channel){
channel.postMessage(sessionID)
}
changed = false
let db = get(DataBase)
db.saveTime = Math.floor(Date.now() / 1000)
Expand Down

0 comments on commit 2f51f26

Please sign in to comment.