Merge branch 'sw-notification-action' of https://github.com/tamaina/misskey into sw-notification-action

This commit is contained in:
tamaina 2021-03-18 21:05:17 +09:00
commit 5db8a56e5f
7 changed files with 80 additions and 41 deletions

View file

@ -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';

View file

@ -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');

View file

@ -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}`);

View file

@ -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; }[];

View 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));
}

View file

@ -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

View file

@ -55,6 +55,7 @@ export default defineComponent({
const sideViewHook = inject('sideViewHook', null); const sideViewHook = inject('sideViewHook', null);
//#region Listen message from SW //#region Listen message from SW
if ('serviceWorker' in navigator) {
navigator.serviceWorker.addEventListener('message', ev => { navigator.serviceWorker.addEventListener('message', ev => {
if (_DEV_) { if (_DEV_) {
console.log('sw msg', ev.data); console.log('sw msg', ev.data);
@ -94,6 +95,7 @@ export default defineComponent({
} }
}); });
} }
}
return { return {
uploads, uploads,