Optimize firefox startup

This commit is contained in:
suziwen 2024-08-14 09:47:41 +08:00
parent 480b1ae4a8
commit 8cdd8257f0

View File

@ -23,17 +23,26 @@ import "./js/background.js" // zeroBackground
const isFirefox = !!globalThis.localStorage
function detectPrivateMode(cb) {
var db,
var db, tempMode,
on = cb.bind(null, true),
off = cb.bind(null, false)
if (isFirefox) {
db = indexedDB.open("zeroOmega-test"), db.onerror = on, db.onsuccess = off
// in private mode, localStorage will be erased when browser restart
tempMode = localStorage.getItem('zeroOmega.isPrivateMode')
if (tempMode) {
tempMode == 'true' ? on() : off()
} else {
db = indexedDB.open("zeroOmega-test"), db.onerror = on, db.onsuccess = off
}
} else {
off()
}
}
detectPrivateMode(function (isPrivateMode) {
if (isFirefox) {
localStorage.setItem('zeroOmega.isPrivateMode', isPrivateMode ? 'true' : 'false')
}
if (isPrivateMode && isFirefox) {
// fake indexedDB