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 { reactive } from 'vue';
|
||||||
import { apiUrl } from '@/config';
|
import { apiUrl } from '@/config';
|
||||||
import { waiting } from '@/os';
|
import { waiting } from '@/os';
|
||||||
|
|
|
@ -242,7 +242,7 @@ export default defineComponent({
|
||||||
addAcount() {
|
addAcount() {
|
||||||
os.popup(import('./signin-dialog.vue'), {}, {
|
os.popup(import('./signin-dialog.vue'), {}, {
|
||||||
done: async res => {
|
done: async res => {
|
||||||
addAccount(res.id, res.i);
|
await addAccount(res.id, res.i);
|
||||||
os.success();
|
os.success();
|
||||||
},
|
},
|
||||||
}, 'closed');
|
}, 'closed');
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
import '@/style.scss';
|
import '@/style.scss';
|
||||||
|
|
||||||
import { set } from 'idb-keyval';
|
import { set } from '@/scripts/idb-proxy';
|
||||||
|
|
||||||
// TODO: そのうち消す
|
// TODO: そのうち消す
|
||||||
if (localStorage.getItem('vuex') != null) {
|
if (localStorage.getItem('vuex') != null) {
|
||||||
|
@ -69,9 +69,9 @@ import { isMobile } from '@/scripts/is-mobile';
|
||||||
import { getThemes } from '@/theme-store';
|
import { getThemes } from '@/theme-store';
|
||||||
import { initializeSw } from '@/scripts/initialize-sw';
|
import { initializeSw } from '@/scripts/initialize-sw';
|
||||||
import { reload, reloadChannel } from '@/scripts/unison-reload';
|
import { reload, reloadChannel } from '@/scripts/unison-reload';
|
||||||
|
import { reactionPicker } from '@/scripts/reaction-picker';
|
||||||
import { deleteLoginId } from '@/scripts/login-id';
|
import { deleteLoginId } from '@/scripts/login-id';
|
||||||
import { getAccountFromId } from '@/scripts/get-account-from-id';
|
import { getAccountFromId } from '@/scripts/get-account-from-id';
|
||||||
import { reactionPicker } from '@/scripts/reaction-picker';
|
|
||||||
|
|
||||||
console.info(`Misskey v${version}`);
|
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) {
|
export async function getAccountFromId(id: string) {
|
||||||
const accounts = await get('accounts') as { token: string; id: string; }[];
|
const accounts = await get('accounts') as { token: string; id: string; }[];
|
||||||
|
|
|
@ -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
|
//#region When: Fetching
|
||||||
self.addEventListener('fetch', ev => {
|
self.addEventListener('fetch', ev => {
|
||||||
// Nothing to do
|
ev.respondWith(
|
||||||
|
fetch(ev.request)
|
||||||
|
.catch(() => new Response(`Offline. Service Worker @${_VERSION_}`, { status: 200 }))
|
||||||
|
);
|
||||||
});
|
});
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
|
|
@ -55,44 +55,46 @@ export default defineComponent({
|
||||||
const sideViewHook = inject('sideViewHook', null);
|
const sideViewHook = inject('sideViewHook', null);
|
||||||
|
|
||||||
//#region Listen message from SW
|
//#region Listen message from SW
|
||||||
navigator.serviceWorker.addEventListener('message', ev => {
|
if ('serviceWorker' in navigator) {
|
||||||
if (_DEV_) {
|
navigator.serviceWorker.addEventListener('message', ev => {
|
||||||
console.log('sw msg', ev.data);
|
if (_DEV_) {
|
||||||
}
|
console.log('sw msg', ev.data);
|
||||||
|
}
|
||||||
|
|
||||||
const data = ev.data as SwMessage;
|
const data = ev.data as SwMessage;
|
||||||
if (data.type !== 'order') return;
|
if (data.type !== 'order') return;
|
||||||
|
|
||||||
if (data.loginId !== $i?.id) {
|
if (data.loginId !== $i?.id) {
|
||||||
return getAccountFromId(data.loginId).then(account => {
|
return getAccountFromId(data.loginId).then(account => {
|
||||||
if (!account) return;
|
if (!account) return;
|
||||||
return login(account.token, data.url);
|
return login(account.token, data.url);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (data.order) {
|
switch (data.order) {
|
||||||
case 'post':
|
case 'post':
|
||||||
return post(data.options);
|
return post(data.options);
|
||||||
case 'push':
|
case 'push':
|
||||||
if (data.url.startsWith('/my/messaging')) {
|
if (data.url.startsWith('/my/messaging')) {
|
||||||
if (router.currentRoute.value.path === data.url) return;
|
if (router.currentRoute.value.path === data.url) return;
|
||||||
if (ColdDeviceStorage.get('chatOpenBehavior') === 'window') return pageWindow(data.url);
|
if (ColdDeviceStorage.get('chatOpenBehavior') === 'window') return pageWindow(data.url);
|
||||||
if (ColdDeviceStorage.get('chatOpenBehavior') === 'popout') return popout(data.url);
|
if (ColdDeviceStorage.get('chatOpenBehavior') === 'popout') return popout(data.url);
|
||||||
}
|
}
|
||||||
if (router.currentRoute.value.path === data.url) {
|
if (router.currentRoute.value.path === data.url) {
|
||||||
return window.scroll({ top: 0, behavior: 'smooth' });
|
return window.scroll({ top: 0, behavior: 'smooth' });
|
||||||
}
|
}
|
||||||
if (navHook) {
|
if (navHook) {
|
||||||
return navHook(data.url);
|
return navHook(data.url);
|
||||||
}
|
}
|
||||||
if (sideViewHook && defaultStore.state.defaultSideView && data.url !== '/') {
|
if (sideViewHook && defaultStore.state.defaultSideView && data.url !== '/') {
|
||||||
return sideViewHook(data.url);
|
return sideViewHook(data.url);
|
||||||
}
|
}
|
||||||
return router.push(data.url);
|
return router.push(data.url);
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue