Merge branch 'migrate-accounts-to-idb' into sw-notification-action
This commit is contained in:
@@ -29,23 +29,23 @@ export async function signout() {
|
||||
//#endregion
|
||||
|
||||
//#region Remove push notification registration
|
||||
await navigator.serviceWorker.ready.then(async r => {
|
||||
const push = await r.pushManager.getSubscription();
|
||||
if (!push) return;
|
||||
return fetch(`${apiUrl}/sw/unregister`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
i: $i.token,
|
||||
endpoint: push.endpoint,
|
||||
}),
|
||||
});
|
||||
const registration = await navigator.serviceWorker.ready
|
||||
|
||||
const push = await registration.pushManager.getSubscription();
|
||||
if (!push) return;
|
||||
await fetch(`${apiUrl}/sw/unregister`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
i: $i.token,
|
||||
endpoint: push.endpoint,
|
||||
}),
|
||||
});
|
||||
//#endregion
|
||||
|
||||
document.cookie = `igi=; path=/`;
|
||||
|
||||
if (accounts.length > 0) login(accounts[0].token);
|
||||
else unisonReload(true);
|
||||
else unisonReload();
|
||||
}
|
||||
|
||||
export async function getAccounts(): Promise<{ id: Account['id'], token: Account['token'] }[]> {
|
||||
|
@@ -4,6 +4,7 @@ import {
|
||||
get as iget,
|
||||
set as iset,
|
||||
del as idel,
|
||||
createStore,
|
||||
} from 'idb-keyval';
|
||||
|
||||
const fallbackName = (key: string) => `idbfallback::${key}`;
|
||||
@@ -12,12 +13,7 @@ let idbAvailable = typeof window !== 'undefined' ? !!window.indexedDB : true;
|
||||
|
||||
if (idbAvailable) {
|
||||
try {
|
||||
const request = indexedDB.open('keyval-store');
|
||||
|
||||
await new Promise((res, rej) => {
|
||||
request.onerror = (e) => rej(e);
|
||||
request.onsuccess = (e) => res(e);
|
||||
});
|
||||
await createStore('keyval-store', 'keyval')
|
||||
} catch (e) {
|
||||
console.error('idb open error', e);
|
||||
idbAvailable = false;
|
||||
|
Reference in New Issue
Block a user