mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-23 17:10:39 +01:00
refactor: init.ts周りのeslintエラーと型の修正 (#10157)
* refactor/miLocalStorageのメソッドに戻り値追加 * refactor/miLocalStorageのキーとしてdebugがconfig.tsに存在するので追加 * fix/JSON.parseにnullは入らないのでnullの時は分岐させてnullにする * refactor/修正したファイルの型調整+記法の統一 * fix/型のためにlangがnullの時はhtmlの言語の設定をしない * refactor/catchで何もしないと警告が出るので修正 * refactor/細かい点の修正 * refactor/変数の二重定義になっていた二重定義になっていたので修正 * refactor/importの整理(通常のimportは最初に処理されるので影響はない想定) * fix/vueファイルに型を与えてインポート時の型エラーを防ぐ * refactor/開発環境のみで利用するので,eslintの設定を変更する * fix/vueの定義を最小限にする * fallback language to 'en-US' * remove accounts migration * fix:vueの型定義ファイルを消す --------- Co-authored-by: tamaina <tamaina@hotmail.co.jp>
This commit is contained in:
parent
dffefdad95
commit
463446795d
3 changed files with 27 additions and 36 deletions
|
@ -1,21 +1,22 @@
|
||||||
import { miLocalStorage } from "./local-storage";
|
import { miLocalStorage } from './local-storage';
|
||||||
|
|
||||||
const address = new URL(location.href);
|
const address = new URL(location.href);
|
||||||
const siteName = (document.querySelector('meta[property="og:site_name"]') as HTMLMetaElement)?.content;
|
const siteName = document.querySelector<HTMLMetaElement>('meta[property="og:site_name"]')?.content;
|
||||||
|
|
||||||
export const host = address.host;
|
export const host = address.host;
|
||||||
export const hostname = address.hostname;
|
export const hostname = address.hostname;
|
||||||
export const url = address.origin;
|
export const url = address.origin;
|
||||||
export const apiUrl = url + '/api';
|
export const apiUrl = url + '/api';
|
||||||
export const wsUrl = url.replace('http://', 'ws://').replace('https://', 'wss://') + '/streaming';
|
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 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 version = _VERSION_;
|
||||||
export const instanceName = siteName === 'Misskey' ? host : siteName;
|
export const instanceName = siteName === 'Misskey' ? host : siteName;
|
||||||
export const ui = miLocalStorage.getItem('ui');
|
export const ui = miLocalStorage.getItem('ui');
|
||||||
export const debug = miLocalStorage.getItem('debug') === 'true';
|
export const debug = miLocalStorage.getItem('debug') === 'true';
|
||||||
|
|
||||||
export function updateLocale(newLocale) {
|
export function updateLocale(newLocale): void {
|
||||||
locale = newLocale;
|
locale = newLocale;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,18 +6,6 @@ import 'vite/modulepreload-polyfill';
|
||||||
|
|
||||||
import '@/style.scss';
|
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 { computed, createApp, watch, markRaw, version as vueVersion, defineAsyncComponent } from 'vue';
|
||||||
import { compareVersions } from 'compare-versions';
|
import { compareVersions } from 'compare-versions';
|
||||||
import JSON5 from 'json5';
|
import JSON5 from 'json5';
|
||||||
|
@ -42,11 +30,11 @@ import { reloadChannel } from '@/scripts/unison-reload';
|
||||||
import { reactionPicker } from '@/scripts/reaction-picker';
|
import { reactionPicker } from '@/scripts/reaction-picker';
|
||||||
import { getUrlWithoutLoginId } from '@/scripts/login-id';
|
import { getUrlWithoutLoginId } from '@/scripts/login-id';
|
||||||
import { getAccountFromId } from '@/scripts/get-account-from-id';
|
import { getAccountFromId } from '@/scripts/get-account-from-id';
|
||||||
import { deckStore } from './ui/deck/deck-store';
|
import { deckStore } from '@/ui/deck/deck-store';
|
||||||
import { miLocalStorage } from './local-storage';
|
import { miLocalStorage } from '@/local-storage';
|
||||||
import { claimAchievement, claimedAchievements } from './scripts/achievements';
|
import { claimAchievement, claimedAchievements } from '@/scripts/achievements';
|
||||||
import { fetchCustomEmojis } from './custom-emojis';
|
import { fetchCustomEmojis } from '@/custom-emojis';
|
||||||
import { mainRouter } from './router';
|
import { mainRouter } from '@/router';
|
||||||
|
|
||||||
console.info(`Misskey v${version}`);
|
console.info(`Misskey v${version}`);
|
||||||
|
|
||||||
|
@ -55,7 +43,9 @@ if (_DEV_) {
|
||||||
|
|
||||||
console.info(`vue ${vueVersion}`);
|
console.info(`vue ${vueVersion}`);
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
(window as any).$i = $i;
|
(window as any).$i = $i;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
(window as any).$store = defaultStore;
|
(window as any).$store = defaultStore;
|
||||||
|
|
||||||
window.addEventListener('error', event => {
|
window.addEventListener('error', event => {
|
||||||
|
@ -184,7 +174,7 @@ fetchInstanceMetaPromise.then(() => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fetchCustomEmojis();
|
await fetchCustomEmojis();
|
||||||
} catch (err) {}
|
} catch (err) { /* empty */ }
|
||||||
|
|
||||||
const app = createApp(
|
const app = createApp(
|
||||||
new URLSearchParams(window.location.search).has('zen') ? defineAsyncComponent(() => import('@/ui/zen.vue')) :
|
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
|
// https://github.com/misskey-dev/misskey/pull/8575#issuecomment-1114239210
|
||||||
// なぜかinit.tsの内容が2回実行されることがあるため、mountするdivを1つに制限する
|
// なぜかinit.tsの内容が2回実行されることがあるため、mountするdivを1つに制限する
|
||||||
const rootEl = (() => {
|
const rootEl = ((): HTMLElement => {
|
||||||
const MISSKEY_MOUNT_DIV_ID = 'misskey_app';
|
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');
|
console.warn('multiple import detected');
|
||||||
return currentEl;
|
return currentRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rootEl = document.createElement('div');
|
const root = document.createElement('div');
|
||||||
rootEl.id = MISSKEY_MOUNT_DIV_ID;
|
root.id = MISSKEY_MOUNT_DIV_ID;
|
||||||
document.body.appendChild(rootEl);
|
document.body.appendChild(root);
|
||||||
return rootEl;
|
return root;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
app.mount(rootEl);
|
app.mount(rootEl);
|
||||||
|
@ -256,8 +246,7 @@ if (lastVersion !== version) {
|
||||||
popup(defineAsyncComponent(() => import('@/components/MkUpdated.vue')), {}, {}, 'closed');
|
popup(defineAsyncComponent(() => import('@/components/MkUpdated.vue')), {}, {}, 'closed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) { /* empty */ }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await defaultStore.ready;
|
await defaultStore.ready;
|
||||||
|
|
|
@ -24,6 +24,7 @@ type Keys =
|
||||||
'customCss' |
|
'customCss' |
|
||||||
'message_drafts' |
|
'message_drafts' |
|
||||||
'scratchpad' |
|
'scratchpad' |
|
||||||
|
'debug' |
|
||||||
`miux:${string}` |
|
`miux:${string}` |
|
||||||
`ui:folder:${string}` |
|
`ui:folder:${string}` |
|
||||||
`themes:${string}` |
|
`themes:${string}` |
|
||||||
|
@ -32,7 +33,7 @@ type Keys =
|
||||||
'emojis' // DEPRECATED, stored in indexeddb (13.9.0~);
|
'emojis' // DEPRECATED, stored in indexeddb (13.9.0~);
|
||||||
|
|
||||||
export const miLocalStorage = {
|
export const miLocalStorage = {
|
||||||
getItem: (key: Keys) => window.localStorage.getItem(key),
|
getItem: (key: Keys): string | null => window.localStorage.getItem(key),
|
||||||
setItem: (key: Keys, value: string) => window.localStorage.setItem(key, value),
|
setItem: (key: Keys, value: string): void => window.localStorage.setItem(key, value),
|
||||||
removeItem: (key: Keys) => window.localStorage.removeItem(key),
|
removeItem: (key: Keys): void => window.localStorage.removeItem(key),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue