This commit is contained in:
syuilo 2024-08-29 18:38:05 +09:00
parent 9ba5f1f271
commit 05899455a8
2 changed files with 7 additions and 25 deletions

View File

@ -15,7 +15,6 @@ import { updateI18n } from '@/i18n.js';
import { $i, refreshAccount, login } from '@/account.js'; import { $i, refreshAccount, login } from '@/account.js';
import { defaultStore, ColdDeviceStorage } from '@/store.js'; import { defaultStore, ColdDeviceStorage } from '@/store.js';
import { fetchInstance, instance } from '@/instance.js'; import { fetchInstance, instance } from '@/instance.js';
import type { IRouter } from '@/nirax.js';
import { deviceKind } from '@/scripts/device-kind.js'; import { deviceKind } from '@/scripts/device-kind.js';
import { reloadChannel } from '@/scripts/unison-reload.js'; import { reloadChannel } from '@/scripts/unison-reload.js';
import { getUrlWithoutLoginId } from '@/scripts/login-id.js'; import { getUrlWithoutLoginId } from '@/scripts/login-id.js';
@ -23,22 +22,10 @@ import { getAccountFromId } from '@/scripts/get-account-from-id.js';
import { deckStore } from '@/ui/deck/deck-store.js'; import { deckStore } from '@/ui/deck/deck-store.js';
import { miLocalStorage } from '@/local-storage.js'; import { miLocalStorage } from '@/local-storage.js';
import { fetchCustomEmojis } from '@/custom-emojis.js'; import { fetchCustomEmojis } from '@/custom-emojis.js';
import { createMainRouter } from '@/router/definition.js';
import { setupRouter } from '@/router/main.js'; import { setupRouter } from '@/router/main.js';
import { createMainRouter } from '@/router/definition.js';
export type CommonBootOptions = { export async function common(createVue: () => App<Element>) {
forceColorMode: 'dark' | 'light' | 'auto';
routerFactory: ((path: string) => IRouter);
};
const defaultCommonBootOptions: CommonBootOptions = {
forceColorMode: 'auto',
routerFactory: createMainRouter,
};
export async function common(createVue: () => App<Element>, partialOptions?: Partial<CommonBootOptions>) {
const bootOptions = Object.assign(defaultCommonBootOptions, partialOptions);
console.info(`Misskey v${version}`); console.info(`Misskey v${version}`);
if (_DEV_) { if (_DEV_) {
@ -180,19 +167,15 @@ export async function common(createVue: () => App<Element>, partialOptions?: Par
}); });
//#region Sync dark mode //#region Sync dark mode
if (ColdDeviceStorage.get('syncDeviceDarkMode') && bootOptions.forceColorMode === 'auto') { if (ColdDeviceStorage.get('syncDeviceDarkMode')) {
defaultStore.set('darkMode', isDeviceDarkmode()); defaultStore.set('darkMode', isDeviceDarkmode());
} }
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (mql) => { window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (mql) => {
if (ColdDeviceStorage.get('syncDeviceDarkMode') && bootOptions.forceColorMode === 'auto') { if (ColdDeviceStorage.get('syncDeviceDarkMode')) {
defaultStore.set('darkMode', mql.matches); defaultStore.set('darkMode', mql.matches);
} }
}); });
if (bootOptions.forceColorMode !== 'auto') {
defaultStore.set('darkMode', bootOptions.forceColorMode === 'dark');
}
//#endregion //#endregion
fetchInstanceMetaPromise.then(() => { fetchInstanceMetaPromise.then(() => {
@ -257,7 +240,7 @@ export async function common(createVue: () => App<Element>, partialOptions?: Par
const app = createVue(); const app = createVue();
setupRouter(app, bootOptions.routerFactory); setupRouter(app, createMainRouter);
if (_DEV_) { if (_DEV_) {
app.config.performance = true; app.config.performance = true;

View File

@ -5,13 +5,12 @@
import { createApp, defineAsyncComponent } from 'vue'; import { createApp, defineAsyncComponent } from 'vue';
import { common } from './common.js'; import { common } from './common.js';
import type { CommonBootOptions } from './common.js';
import { emojiPicker } from '@/scripts/emoji-picker.js'; import { emojiPicker } from '@/scripts/emoji-picker.js';
export async function subBoot(options?: Partial<CommonBootOptions>) { export async function subBoot() {
const { isClientUpdated } = await common(() => createApp( const { isClientUpdated } = await common(() => createApp(
defineAsyncComponent(() => import('@/ui/minimum.vue')), defineAsyncComponent(() => import('@/ui/minimum.vue')),
), options); ));
emojiPicker.init(); emojiPicker.init();
} }