Merge branch 'sw-notification-action' of https://github.com/tamaina/misskey into sw-notification-action
This commit is contained in:
commit
5db8a56e5f
7 changed files with 80 additions and 41 deletions
|
@ -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,6 +55,7 @@ export default defineComponent({
|
|||
const sideViewHook = inject('sideViewHook', null);
|
||||
|
||||
//#region Listen message from SW
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.addEventListener('message', ev => {
|
||||
if (_DEV_) {
|
||||
console.log('sw msg', ev.data);
|
||||
|
@ -94,6 +95,7 @@ export default defineComponent({
|
|||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
uploads,
|
||||
|
|
Loading…
Reference in a new issue