8a6f73c5ff
* Revert "Revert #8098"
This reverts commit 8b9dc962ae
.
* fix
* use deepClone instead of deepclone
* defaultStore.loaded
* fix load
* wait ready
* use top-level await, await in device-kind.ts
33 lines
838 B
TypeScript
33 lines
838 B
TypeScript
import { post } from '@/os';
|
|
import { $i, login } from '@/account';
|
|
import { getAccountFromId } from '@/scripts/get-account-from-id';
|
|
import { mainRouter } from '@/router';
|
|
|
|
export function swInject() {
|
|
navigator.serviceWorker.addEventListener('message', ev => {
|
|
if (_DEV_) {
|
|
console.log('sw msg', ev.data);
|
|
}
|
|
|
|
if (ev.data.type !== 'order') return;
|
|
|
|
if (ev.data.loginId !== $i?.id) {
|
|
return getAccountFromId(ev.data.loginId).then(account => {
|
|
if (!account) return;
|
|
return login(account.token, ev.data.url);
|
|
});
|
|
}
|
|
|
|
switch (ev.data.order) {
|
|
case 'post':
|
|
return post(ev.data.options);
|
|
case 'push':
|
|
if (mainRouter.currentRoute.value.path === ev.data.url) {
|
|
return window.scroll({ top: 0, behavior: 'smooth' });
|
|
}
|
|
return mainRouter.push(ev.data.url);
|
|
default:
|
|
return;
|
|
}
|
|
});
|
|
}
|