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
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
@@ -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)