Refactor tab activation handling in saveDb function

This commit is contained in:
kwaroran
2024-04-08 23:46:34 +09:00
parent 8d094d5b66
commit 653fb6fa9f

View File

@@ -261,15 +261,17 @@ export async function saveDb(){
}) })
let gotChannel = false let gotChannel = false
const sessionID = v4() const sessionID = v4()
const channel = new BroadcastChannel('risu-save-channel') const channel = BroadcastChannel ? (new BroadcastChannel('risu-active')): null
channel.onmessage = async (ev) => { if(channel){
if(ev.data === sessionID){ channel.onmessage = async (ev) => {
return if(ev.data === sessionID){
} return
if(!gotChannel){ }
gotChannel = true if(!gotChannel){
await alertNormalWait(language.activeTabChange) gotChannel = true
gotChannel = false await alertNormalWait(language.activeTabChange)
gotChannel = false
}
} }
} }
let savetrys = 0 let savetrys = 0
@@ -281,7 +283,9 @@ export async function saveDb(){
await sleep(1000) await sleep(1000)
continue continue
} }
channel.postMessage(sessionID) if(channel){
channel.postMessage(sessionID)
}
changed = false changed = false
let db = get(DataBase) let db = get(DataBase)
db.saveTime = Math.floor(Date.now() / 1000) db.saveTime = Math.floor(Date.now() / 1000)