From 91503405b4e58cb9d39c0441d86ff540a27931e6 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 7 Jan 2023 10:13:02 +0900 Subject: refactor(client): typed localStorage --- packages/frontend/src/init.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'packages/frontend/src/init.ts') diff --git a/packages/frontend/src/init.ts b/packages/frontend/src/init.ts index 45ade64127..bd515f47ea 100644 --- a/packages/frontend/src/init.ts +++ b/packages/frontend/src/init.ts @@ -9,9 +9,12 @@ import '@/style.scss'; //#region account indexedDB migration import { set } from '@/scripts/idb-proxy'; -if (localStorage.getItem('accounts') != null) { - set('accounts', JSON.parse(localStorage.getItem('accounts'))); - localStorage.removeItem('accounts'); +{ + const accounts = miLocalStorage.getItem('accounts'); + if (accounts) { + set('accounts', JSON.parse(accounts)); + miLocalStorage.removeItem('accounts'); + } } //#endregion @@ -40,6 +43,7 @@ import { reloadChannel } from '@/scripts/unison-reload'; import { reactionPicker } from '@/scripts/reaction-picker'; import { getUrlWithoutLoginId } from '@/scripts/login-id'; import { getAccountFromId } from '@/scripts/get-account-from-id'; +import { miLocalStorage } from './local-storage'; (async () => { console.info(`Misskey v${version}`); @@ -154,7 +158,7 @@ import { getAccountFromId } from '@/scripts/get-account-from-id'; const fetchInstanceMetaPromise = fetchInstance(); fetchInstanceMetaPromise.then(() => { - localStorage.setItem('v', instance.version); + miLocalStorage.setItem('v', instance.version); // Init service worker initializeSw(); @@ -223,12 +227,12 @@ import { getAccountFromId } from '@/scripts/get-account-from-id'; } // クライアントが更新されたか? - const lastVersion = localStorage.getItem('lastVersion'); + const lastVersion = miLocalStorage.getItem('lastVersion'); if (lastVersion !== version) { - localStorage.setItem('lastVersion', version); + miLocalStorage.setItem('lastVersion', version); // テーマリビルドするため - localStorage.removeItem('theme'); + miLocalStorage.removeItem('theme'); try { // 変なバージョン文字列来るとcompareVersionsでエラーになるため if (lastVersion != null && compareVersions(version, lastVersion) === 1) { @@ -244,7 +248,7 @@ import { getAccountFromId } from '@/scripts/get-account-from-id'; // NOTE: この処理は必ず↑のクライアント更新時処理より後に来ること(テーマ再構築のため) watch(defaultStore.reactiveState.darkMode, (darkMode) => { applyTheme(darkMode ? ColdDeviceStorage.get('darkTheme') : ColdDeviceStorage.get('lightTheme')); - }, { immediate: localStorage.theme == null }); + }, { immediate: miLocalStorage.getItem('theme') == null }); const darkTheme = computed(ColdDeviceStorage.makeGetterSetter('darkTheme')); const lightTheme = computed(ColdDeviceStorage.makeGetterSetter('lightTheme')); @@ -341,7 +345,7 @@ import { getAccountFromId } from '@/scripts/get-account-from-id'; }); } - const lastUsed = localStorage.getItem('lastUsed'); + const lastUsed = miLocalStorage.getItem('lastUsed'); if (lastUsed) { const lastUsedDate = parseInt(lastUsed, 10); // 二時間以上前なら @@ -351,7 +355,7 @@ import { getAccountFromId } from '@/scripts/get-account-from-id'; })); } } - localStorage.setItem('lastUsed', Date.now().toString()); + miLocalStorage.setItem('lastUsed', Date.now().toString()); if ('Notification' in window) { // 許可を得ていなかったらリクエスト -- cgit v1.2.3-freya