refactor(frontend): deviceKindの循環参照を除去

(cherry picked from commit 1ca471f57e968a1a6e2259bde4a7c6da1fe0c54e)
This commit is contained in:
taiyme 2024-10-29 18:59:49 +09:00 committed by kakkokari-gtyih
parent 87656ac749
commit 602f095649
3 changed files with 24 additions and 12 deletions

View File

@ -15,7 +15,7 @@ import { updateI18n, i18n } 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 { deviceKind } from '@/scripts/device-kind.js'; import { deviceKind, updateDeviceKind } 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';
import { getAccountFromId } from '@/scripts/get-account-from-id.js'; import { getAccountFromId } from '@/scripts/get-account-from-id.js';
@ -185,6 +185,10 @@ export async function common(createVue: () => App<Element>) {
} }
}); });
watch(defaultStore.reactiveState.overridedDeviceKind, (kind) => {
updateDeviceKind(kind);
}, { immediate: true });
watch(defaultStore.reactiveState.useBlurEffectForModal, v => { watch(defaultStore.reactiveState.useBlurEffectForModal, v => {
document.documentElement.style.setProperty('--MI-modalBgFilter', v ? 'blur(4px)' : 'none'); document.documentElement.style.setProperty('--MI-modalBgFilter', v ? 'blur(4px)' : 'none');
}, { immediate: true }); }, { immediate: true });

View File

@ -3,15 +3,22 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { defaultStore } from '@/store.js'; export type DeviceKind = 'smartphone' | 'tablet' | 'desktop';
await defaultStore.ready;
const ua = navigator.userAgent.toLowerCase(); const ua = navigator.userAgent.toLowerCase();
const isTablet = /ipad/.test(ua) || (/mobile|iphone|android/.test(ua) && window.innerWidth > 700); const isTablet = /ipad/.test(ua) || (/mobile|iphone|android/.test(ua) && window.innerWidth > 700);
const isSmartphone = !isTablet && /mobile|iphone|android/.test(ua); const isSmartphone = !isTablet && /mobile|iphone|android/.test(ua);
export const deviceKind: 'smartphone' | 'tablet' | 'desktop' = defaultStore.state.overridedDeviceKind ? defaultStore.state.overridedDeviceKind export const DEFAULT_DEVICE_KIND: DeviceKind = (
: isSmartphone ? 'smartphone' isSmartphone
: isTablet ? 'tablet' ? 'smartphone'
: 'desktop'; : isTablet
? 'tablet'
: 'desktop'
);
export let deviceKind: DeviceKind = DEFAULT_DEVICE_KIND;
export function updateDeviceKind(kind: DeviceKind | null) {
deviceKind = kind ?? DEFAULT_DEVICE_KIND;
}

View File

@ -8,8 +8,9 @@ import * as Misskey from 'misskey-js';
import { hemisphere } from '@@/js/intl-const.js'; import { hemisphere } from '@@/js/intl-const.js';
import lightTheme from '@@/themes/l-light.json5'; import lightTheme from '@@/themes/l-light.json5';
import darkTheme from '@@/themes/d-green-lime.json5'; import darkTheme from '@@/themes/d-green-lime.json5';
import { miLocalStorage } from './local-storage.js';
import type { SoundType } from '@/scripts/sound.js'; import type { SoundType } from '@/scripts/sound.js';
import { DEFAULT_DEVICE_KIND, type DeviceKind } from '@/scripts/device-kind.js';
import { miLocalStorage } from '@/local-storage.js';
import { Storage } from '@/pizzax.js'; import { Storage } from '@/pizzax.js';
import type { Ast } from '@syuilo/aiscript'; import type { Ast } from '@syuilo/aiscript';
@ -207,7 +208,7 @@ export const defaultStore = markRaw(new Storage('base', {
overridedDeviceKind: { overridedDeviceKind: {
where: 'device', where: 'device',
default: null as null | 'smartphone' | 'tablet' | 'desktop', default: null as DeviceKind | null,
}, },
serverDisconnectedBehavior: { serverDisconnectedBehavior: {
where: 'device', where: 'device',
@ -263,11 +264,11 @@ export const defaultStore = markRaw(new Storage('base', {
}, },
useBlurEffectForModal: { useBlurEffectForModal: {
where: 'device', where: 'device',
default: !/mobile|iphone|android/.test(navigator.userAgent.toLowerCase()), // 循環参照するのでdevice-kind.tsは参照できない default: DEFAULT_DEVICE_KIND === 'desktop',
}, },
useBlurEffect: { useBlurEffect: {
where: 'device', where: 'device',
default: !/mobile|iphone|android/.test(navigator.userAgent.toLowerCase()), // 循環参照するのでdevice-kind.tsは参照できない default: DEFAULT_DEVICE_KIND === 'desktop',
}, },
showFixedPostForm: { showFixedPostForm: {
where: 'device', where: 'device',