This commit is contained in:
tamaina
2021-02-15 06:05:18 +09:00
parent a8c4c74954
commit bf1db27824
15 changed files with 435 additions and 169 deletions

View File

@@ -61,11 +61,14 @@ import * as sound from '@/scripts/sound';
import { $i, refreshAccount, login, updateAccount, signout } from '@/account';
import { defaultStore, ColdDeviceStorage } from '@/store';
import { fetchInstance, instance } from '@/instance';
import { makeHotkey } from './scripts/hotkey';
import { search } from './scripts/search';
import { getThemes } from './theme-store';
import { initializeSw } from './scripts/initialize-sw';
import { reloadChannel } from './scripts/unison-reload';
import { makeHotkey } from '@/scripts/hotkey';
import { search } from '@/scripts/search';
import { getThemes } from '@/theme-store';
import { initializeSw } from '@/scripts/initialize-sw';
import { reloadChannel } from '@/scripts/unison-reload';
import { deleteLoginId } from '@/scripts/login-id';
import { getAccountFromId } from '@/scripts/get-account-from-id';
import { SwMessage } from '@/sw/types';
console.info(`Misskey v${version}`);
@@ -142,6 +145,25 @@ const html = document.documentElement;
html.setAttribute('lang', lang);
//#endregion
//#region loginId
const params = new URLSearchParams(location.href);
const loginId = params.get('loginId');
if (loginId) {
const target = deleteLoginId(location.toString());
if (!$i || $i.id !== loginId) {
const account = await getAccountFromId(loginId);
if (account) {
login(account.token, target)
}
}
history.replaceState({ misskey: 'loginId' }, '', target)
}
//#endregion
//#region Fetch user
if ($i && $i.token) {
if (_DEV_) {
@@ -188,7 +210,7 @@ fetchInstance().then(() => {
stream.init($i);
const app = createApp(await (
window.location.search === '?zen' ? import('@/ui/zen.vue') :
location.search === '?zen' ? import('@/ui/zen.vue') :
!$i ? import('@/ui/visitor.vue') :
ui === 'deck' ? import('@/ui/deck.vue') :
ui === 'desktop' ? import('@/ui/desktop.vue') :
@@ -217,6 +239,33 @@ components(app);
await router.isReady();
//#region Listen message from SW
navigator.serviceWorker.addEventListener('message', ev => {
if (_DEV_) {
console.log('sw msg', ev.data);
}
const data = ev.data as SwMessage;
if (data.type !== 'order') return;
if (data.loginId !== $i?.id) {
return getAccountFromId(data.loginId).then(account => {
if (!account) return;
return login(account.token, data.url);
})
}
switch (data.order) {
case 'post':
return post(data.options);
case 'push':
return router.push(data.url);
default:
return;
}
});
//#endregion
//document.body.innerHTML = '<div id="app"></div>';
app.mount('body');