diff --git a/packages/frontend/src/config.ts b/packages/frontend/src/config.ts index 073b21a0a..24f60910d 100644 --- a/packages/frontend/src/config.ts +++ b/packages/frontend/src/config.ts @@ -1,21 +1,22 @@ -import { miLocalStorage } from "./local-storage"; +import { miLocalStorage } from './local-storage'; const address = new URL(location.href); -const siteName = (document.querySelector('meta[property="og:site_name"]') as HTMLMetaElement)?.content; +const siteName = document.querySelector('meta[property="og:site_name"]')?.content; export const host = address.host; export const hostname = address.hostname; export const url = address.origin; export const apiUrl = url + '/api'; export const wsUrl = url.replace('http://', 'ws://').replace('https://', 'wss://') + '/streaming'; -export const lang = miLocalStorage.getItem('lang'); +export const lang = miLocalStorage.getItem('lang') ?? 'en-US'; export const langs = _LANGS_; -export let locale = JSON.parse(miLocalStorage.getItem('locale')); +const preParseLocale = miLocalStorage.getItem('locale'); +export let locale = preParseLocale ? JSON.parse(preParseLocale) : null; export const version = _VERSION_; export const instanceName = siteName === 'Misskey' ? host : siteName; export const ui = miLocalStorage.getItem('ui'); export const debug = miLocalStorage.getItem('debug') === 'true'; -export function updateLocale(newLocale) { +export function updateLocale(newLocale): void { locale = newLocale; } diff --git a/packages/frontend/src/init.ts b/packages/frontend/src/init.ts index 5b3e7ec93..91cdc15ef 100644 --- a/packages/frontend/src/init.ts +++ b/packages/frontend/src/init.ts @@ -6,18 +6,6 @@ import 'vite/modulepreload-polyfill'; import '@/style.scss'; -//#region account indexedDB migration -import { set } from '@/scripts/idb-proxy'; - -{ - const accounts = miLocalStorage.getItem('accounts'); - if (accounts) { - set('accounts', JSON.parse(accounts)); - miLocalStorage.removeItem('accounts'); - } -} -//#endregion - import { computed, createApp, watch, markRaw, version as vueVersion, defineAsyncComponent } from 'vue'; import { compareVersions } from 'compare-versions'; import JSON5 from 'json5'; @@ -42,11 +30,11 @@ 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 { deckStore } from './ui/deck/deck-store'; -import { miLocalStorage } from './local-storage'; -import { claimAchievement, claimedAchievements } from './scripts/achievements'; -import { fetchCustomEmojis } from './custom-emojis'; -import { mainRouter } from './router'; +import { deckStore } from '@/ui/deck/deck-store'; +import { miLocalStorage } from '@/local-storage'; +import { claimAchievement, claimedAchievements } from '@/scripts/achievements'; +import { fetchCustomEmojis } from '@/custom-emojis'; +import { mainRouter } from '@/router'; console.info(`Misskey v${version}`); @@ -55,7 +43,9 @@ if (_DEV_) { console.info(`vue ${vueVersion}`); + // eslint-disable-next-line @typescript-eslint/no-explicit-any (window as any).$i = $i; + // eslint-disable-next-line @typescript-eslint/no-explicit-any (window as any).$store = defaultStore; window.addEventListener('error', event => { @@ -184,7 +174,7 @@ fetchInstanceMetaPromise.then(() => { try { await fetchCustomEmojis(); -} catch (err) {} +} catch (err) { /* empty */ } const app = createApp( new URLSearchParams(window.location.search).has('zen') ? defineAsyncComponent(() => import('@/ui/zen.vue')) : @@ -212,20 +202,20 @@ await deckStore.ready; // https://github.com/misskey-dev/misskey/pull/8575#issuecomment-1114239210 // なぜかinit.tsの内容が2回実行されることがあるため、mountするdivを1つに制限する -const rootEl = (() => { +const rootEl = ((): HTMLElement => { const MISSKEY_MOUNT_DIV_ID = 'misskey_app'; - const currentEl = document.getElementById(MISSKEY_MOUNT_DIV_ID); + const currentRoot = document.getElementById(MISSKEY_MOUNT_DIV_ID); - if (currentEl) { + if (currentRoot) { console.warn('multiple import detected'); - return currentEl; + return currentRoot; } - const rootEl = document.createElement('div'); - rootEl.id = MISSKEY_MOUNT_DIV_ID; - document.body.appendChild(rootEl); - return rootEl; + const root = document.createElement('div'); + root.id = MISSKEY_MOUNT_DIV_ID; + document.body.appendChild(root); + return root; })(); app.mount(rootEl); @@ -256,8 +246,7 @@ if (lastVersion !== version) { popup(defineAsyncComponent(() => import('@/components/MkUpdated.vue')), {}, {}, 'closed'); } } - } catch (err) { - } + } catch (err) { /* empty */ } } await defaultStore.ready; diff --git a/packages/frontend/src/local-storage.ts b/packages/frontend/src/local-storage.ts index 9a288f264..441a35747 100644 --- a/packages/frontend/src/local-storage.ts +++ b/packages/frontend/src/local-storage.ts @@ -24,6 +24,7 @@ type Keys = 'customCss' | 'message_drafts' | 'scratchpad' | + 'debug' | `miux:${string}` | `ui:folder:${string}` | `themes:${string}` | @@ -32,7 +33,7 @@ type Keys = 'emojis' // DEPRECATED, stored in indexeddb (13.9.0~); export const miLocalStorage = { - getItem: (key: Keys) => window.localStorage.getItem(key), - setItem: (key: Keys, value: string) => window.localStorage.setItem(key, value), - removeItem: (key: Keys) => window.localStorage.removeItem(key), + getItem: (key: Keys): string | null => window.localStorage.getItem(key), + setItem: (key: Keys, value: string): void => window.localStorage.setItem(key, value), + removeItem: (key: Keys): void => window.localStorage.removeItem(key), };