From 572e475b394aab0fd752783da8648b4f096653fd Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 26 Dec 2020 13:57:25 +0900 Subject: [PATCH] clean up --- package.json | 1 - src/client/db.ts | 68 --------------------------- src/client/pages/settings/deck.vue | 2 - src/client/pages/settings/general.vue | 31 +----------- yarn.lock | 5 -- 5 files changed, 1 insertion(+), 106 deletions(-) delete mode 100644 src/client/db.ts diff --git a/package.json b/package.json index 4b6b7b4f4e..2448da9082 100644 --- a/package.json +++ b/package.json @@ -154,7 +154,6 @@ "http-proxy-agent": "4.0.1", "http-signature": "1.3.5", "https-proxy-agent": "5.0.0", - "idb-keyval": "3.2.0", "insert-text-at-cursor": "0.3.0", "is-root": "2.1.0", "is-svg": "4.2.1", diff --git a/src/client/db.ts b/src/client/db.ts deleted file mode 100644 index 3000a0c968..0000000000 --- a/src/client/db.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { Store } from 'idb-keyval'; -// Provide functions from idb-keyval -export { get, set, del, clear, keys } from 'idb-keyval'; - -//#region Construct DB -export const clientDb = { - i18n: new Store('MisskeyClient', 'i18n') -}; -//#endregion - -//#region Provide some tool functions -function openTransaction(store: Store, mode: IDBTransactionMode): Promise{ - return store._dbp.then(db => db.transaction(store.storeName, mode)); -} - -export function entries(store: Store): Promise<[IDBValidKey, unknown][]> { - const entries: [IDBValidKey, unknown][] = []; - - return store._withIDBStore('readonly', store => { - store.openCursor().onsuccess = function () { - if (!this.result) return; - entries.push([this.result.key, this.result.value]); - this.result.continue(); - }; - }).then(() => entries); -} - -export async function bulkGet(keys: IDBValidKey[], store: Store): Promise<[IDBValidKey, unknown][]> { - const valPromises: Promise<[IDBValidKey, unknown]>[] = []; - - const tx = await openTransaction(store, 'readwrite'); - const st = tx.objectStore(store.storeName); - for (const key of keys) { - valPromises.push(new Promise((resolve, reject) => { - const getting = st.get(key); - getting.onsuccess = function (e) { - return resolve([key, this.result]); - }; - getting.onerror = function (e) { - return reject(this.error); - }; - })); - } - return new Promise((resolve, reject) => { - tx.oncomplete = () => resolve(Promise.all(valPromises)); - tx.abort = tx.onerror = () => reject(tx.error); - }); -} - -export async function bulkSet(map: [IDBValidKey, any][], store: Store): Promise { - const tx = await openTransaction(store, 'readwrite'); - const st = tx.objectStore(store.storeName); - for (const [key, value] of map) { - st.put(value, key); - } - return new Promise((resolve, reject) => { - tx.oncomplete = () => resolve(); - tx.abort = tx.onerror = () => reject(tx.error); - }); -} - -export function count(store: Store): Promise { - let req: IDBRequest; - return store._withIDBStore('readonly', store => { - req = store.count(); - }).then(() => req.result); -} -//#endregion diff --git a/src/client/pages/settings/deck.vue b/src/client/pages/settings/deck.vue index 4b672af82d..7b6824d10e 100644 --- a/src/client/pages/settings/deck.vue +++ b/src/client/pages/settings/deck.vue @@ -36,8 +36,6 @@ import FormSelect from '@/components/form/select.vue'; import FormRadios from '@/components/form/radios.vue'; import FormBase from '@/components/form/base.vue'; import FormGroup from '@/components/form/group.vue'; -import { clientDb, set } from '@/db'; -import * as os from '@/os'; import { deckStore } from '@/ui/deck/deck-store'; export default defineComponent({ diff --git a/src/client/pages/settings/general.vue b/src/client/pages/settings/general.vue index e6bb1b8a77..8869644ce7 100644 --- a/src/client/pages/settings/general.vue +++ b/src/client/pages/settings/general.vue @@ -77,8 +77,6 @@ {{ $ts.deck }} - - {{ $ts.cacheClear }} @@ -94,8 +92,6 @@ import FormLink from '@/components/form/link.vue'; import FormButton from '@/components/form/button.vue'; import MkLink from '@/components/link.vue'; import { langs } from '@/config'; -import { clientDb, set } from '@/db'; -import * as os from '@/os'; import { defaultStore } from '@/store'; import { ColdDeviceStorage } from '@/store'; @@ -149,14 +145,7 @@ export default defineComponent({ watch: { lang() { localStorage.setItem('lang', this.lang); - - return set('_version_', `changeLang-${(new Date()).toJSON()}`, clientDb.i18n) - .then(() => location.reload()) - .catch(() => { - os.dialog({ - type: 'error', - }); - }); + location.reload(); }, fontSize() { @@ -185,23 +174,5 @@ export default defineComponent({ mounted() { this.$emit('info', this.INFO); }, - - methods: { - cacheClear() { - // Clear cache (service worker) - try { - navigator.serviceWorker.controller.postMessage('clear'); - - navigator.serviceWorker.getRegistrations().then(registrations => { - for (const registration of registrations) registration.unregister(); - }); - } catch (e) { - console.error(e); - } - - // Force reload - location.reload(true); - } - } }); diff --git a/yarn.lock b/yarn.lock index 7e3088744e..96fd4e7e64 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4955,11 +4955,6 @@ icss-utils@^5.0.0: resolved "https://registry.yarnpkg.com/icss-utils/-/icss-utils-5.0.0.tgz#03ed56c3accd32f9caaf1752ebf64ef12347bb84" integrity sha512-aF2Cf/CkEZrI/vsu5WI/I+akFgdbwQHVE9YRZxATrhH4PVIe6a3BIjwjEcW+z+jP/hNh+YvM3lAAn1wJQ6opSg== -idb-keyval@3.2.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/idb-keyval/-/idb-keyval-3.2.0.tgz#cbbf354deb5684b6cdc84376294fc05932845bd6" - integrity sha512-slx8Q6oywCCSfKgPgL0sEsXtPVnSbTLWpyiDcu6msHOyKOLari1TD1qocXVCft80umnkk3/Qqh3lwoFt8T/BPQ== - ieee754@1.1.13, ieee754@^1.1.13, ieee754@^1.1.4: version "1.1.13" resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.13.tgz#ec168558e95aa181fd87d37f55c32bbcb6708b84"