forked from mirror/misskey
Merge branch 'sw-notification-action' of https://github.com/tamaina/misskey into sw-notification-action
This commit is contained in:
commit
5db8a56e5f
@ -1,4 +1,4 @@
|
||||
import { get, set } from 'idb-keyval';
|
||||
import { get, set } from '@/scripts/idb-proxy';
|
||||
import { reactive } from 'vue';
|
||||
import { apiUrl } from '@/config';
|
||||
import { waiting } from '@/os';
|
||||
|
@ -242,7 +242,7 @@ export default defineComponent({
|
||||
addAcount() {
|
||||
os.popup(import('./signin-dialog.vue'), {}, {
|
||||
done: async res => {
|
||||
addAccount(res.id, res.i);
|
||||
await addAccount(res.id, res.i);
|
||||
os.success();
|
||||
},
|
||||
}, 'closed');
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
import '@/style.scss';
|
||||
|
||||
import { set } from 'idb-keyval';
|
||||
import { set } from '@/scripts/idb-proxy';
|
||||
|
||||
// TODO: そのうち消す
|
||||
if (localStorage.getItem('vuex') != null) {
|
||||
@ -69,9 +69,9 @@ import { isMobile } from '@/scripts/is-mobile';
|
||||
import { getThemes } from '@/theme-store';
|
||||
import { initializeSw } from '@/scripts/initialize-sw';
|
||||
import { reload, reloadChannel } from '@/scripts/unison-reload';
|
||||
import { reactionPicker } from '@/scripts/reaction-picker';
|
||||
import { deleteLoginId } from '@/scripts/login-id';
|
||||
import { getAccountFromId } from '@/scripts/get-account-from-id';
|
||||
import { reactionPicker } from '@/scripts/reaction-picker';
|
||||
|
||||
console.info(`Misskey v${version}`);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { get } from 'idb-keyval';
|
||||
import { get } from '@/scripts/idb-proxy';
|
||||
|
||||
export async function getAccountFromId(id: string) {
|
||||
const accounts = await get('accounts') as { token: string; id: string; }[];
|
||||
|
34
src/client/scripts/idb-proxy.ts
Normal file
34
src/client/scripts/idb-proxy.ts
Normal file
@ -0,0 +1,34 @@
|
||||
// FirefoxのプライベートモードなどではindexedDBが使用不可能なので、使う
|
||||
import {
|
||||
get as iget,
|
||||
set as iset,
|
||||
del as idel,
|
||||
} from 'idb-keyval';
|
||||
|
||||
const fallbackName = (key: string) => `idbfallback::${key}`;
|
||||
|
||||
let idbAvailable = typeof window !== 'undefined' ? !!window.indexedDB : true;
|
||||
|
||||
if (idbAvailable) {
|
||||
try {
|
||||
const request = indexedDB.open('keyval-store');
|
||||
if (request.error) idbAvailable = false;
|
||||
} catch (e) {
|
||||
idbAvailable = false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function get(key: string) {
|
||||
if (idbAvailable) return iget(key);
|
||||
return JSON.parse(localStorage.getItem(fallbackName(key)));
|
||||
}
|
||||
|
||||
export async function set(key: string, val: any) {
|
||||
if (idbAvailable) return iset(key, val);
|
||||
return localStorage.setItem(fallbackName(key), JSON.stringify(val));
|
||||
}
|
||||
|
||||
export async function del(key: string) {
|
||||
if (idbAvailable) return idel(key);
|
||||
return localStorage.removeItem(fallbackName(key));
|
||||
}
|
@ -32,7 +32,10 @@ self.addEventListener('activate', ev => {
|
||||
|
||||
//#region When: Fetching
|
||||
self.addEventListener('fetch', ev => {
|
||||
// Nothing to do
|
||||
ev.respondWith(
|
||||
fetch(ev.request)
|
||||
.catch(() => new Response(`Offline. Service Worker @${_VERSION_}`, { status: 200 }))
|
||||
);
|
||||
});
|
||||
//#endregion
|
||||
|
||||
|
@ -55,44 +55,46 @@ export default defineComponent({
|
||||
const sideViewHook = inject('sideViewHook', null);
|
||||
|
||||
//#region Listen message from SW
|
||||
navigator.serviceWorker.addEventListener('message', ev => {
|
||||
if (_DEV_) {
|
||||
console.log('sw msg', ev.data);
|
||||
}
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.addEventListener('message', ev => {
|
||||
if (_DEV_) {
|
||||
console.log('sw msg', ev.data);
|
||||
}
|
||||
|
||||
const data = ev.data as SwMessage;
|
||||
if (data.type !== 'order') return;
|
||||
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);
|
||||
});
|
||||
}
|
||||
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':
|
||||
if (data.url.startsWith('/my/messaging')) {
|
||||
if (router.currentRoute.value.path === data.url) return;
|
||||
if (ColdDeviceStorage.get('chatOpenBehavior') === 'window') return pageWindow(data.url);
|
||||
if (ColdDeviceStorage.get('chatOpenBehavior') === 'popout') return popout(data.url);
|
||||
}
|
||||
if (router.currentRoute.value.path === data.url) {
|
||||
return window.scroll({ top: 0, behavior: 'smooth' });
|
||||
}
|
||||
if (navHook) {
|
||||
return navHook(data.url);
|
||||
}
|
||||
if (sideViewHook && defaultStore.state.defaultSideView && data.url !== '/') {
|
||||
return sideViewHook(data.url);
|
||||
}
|
||||
return router.push(data.url);
|
||||
default:
|
||||
return;
|
||||
}
|
||||
});
|
||||
switch (data.order) {
|
||||
case 'post':
|
||||
return post(data.options);
|
||||
case 'push':
|
||||
if (data.url.startsWith('/my/messaging')) {
|
||||
if (router.currentRoute.value.path === data.url) return;
|
||||
if (ColdDeviceStorage.get('chatOpenBehavior') === 'window') return pageWindow(data.url);
|
||||
if (ColdDeviceStorage.get('chatOpenBehavior') === 'popout') return popout(data.url);
|
||||
}
|
||||
if (router.currentRoute.value.path === data.url) {
|
||||
return window.scroll({ top: 0, behavior: 'smooth' });
|
||||
}
|
||||
if (navHook) {
|
||||
return navHook(data.url);
|
||||
}
|
||||
if (sideViewHook && defaultStore.state.defaultSideView && data.url !== '/') {
|
||||
return sideViewHook(data.url);
|
||||
}
|
||||
return router.push(data.url);
|
||||
default:
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user