refactor(client): typed localStorage

This commit is contained in:
syuilo 2023-01-07 10:13:02 +09:00
parent a42b03c154
commit 91503405b4
25 changed files with 157 additions and 88 deletions

View file

@ -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) {
// 許可を得ていなかったらリクエスト