diff --git a/packages/frontend/src/_dev_boot_.ts b/packages/frontend/src/_dev_boot_.ts index 89509262c2..907e5ce7e7 100644 --- a/packages/frontend/src/_dev_boot_.ts +++ b/packages/frontend/src/_dev_boot_.ts @@ -7,11 +7,11 @@ // よって、devモードとして起動されるときはビルド時に組み込む形としておく。 // (pnpm start時はpugファイルの中で静的リソースとして読み込むようになっており、この問題は起こっていない) import '@tabler/icons-webfont/dist/tabler-icons.scss'; -import { isEmbedPage } from '@/scripts/embed-page.js'; +import { embedPage } from '@/config.js'; await main(); -if (isEmbedPage()) { +if (embedPage) { import('@/_embed_boot_.js'); } else { import('@/_boot_.js'); diff --git a/packages/frontend/src/account.ts b/packages/frontend/src/account.ts index beb36c9882..1b4752910f 100644 --- a/packages/frontend/src/account.ts +++ b/packages/frontend/src/account.ts @@ -14,7 +14,7 @@ import { apiUrl } from '@/config.js'; import { waiting, popup, popupMenu, success, alert } from '@/os.js'; import { misskeyApi } from '@/scripts/misskey-api.js'; import { unisonReload, reloadChannel } from '@/scripts/unison-reload.js'; -import { isEmbedPage } from '@/scripts/embed-page.js'; +import { embedPage } from '@/config.js'; // TODO: 他のタブと永続化されたstateを同期 @@ -23,7 +23,7 @@ type Account = Misskey.entities.MeDetailed & { token: string }; const accountData = miLocalStorage.getItem('account'); function initAccount() { - if (isEmbedPage()) return null; + if (embedPage) return null; if (accountData) return reactive(JSON.parse(accountData) as Account); return null; } @@ -85,13 +85,13 @@ export async function signout() { } export async function getAccounts(): Promise<{ id: Account['id'], token: Account['token'] }[]> { - if (isEmbedPage()) return []; + if (embedPage) return []; return (await get('accounts')) || []; } export async function addAccount(id: Account['id'], token: Account['token']) { - if (isEmbedPage()) return; + if (embedPage) return; const accounts = await getAccounts(); if (!accounts.some(x => x.id === id)) { @@ -194,7 +194,7 @@ export async function refreshAccount() { } export async function login(token: Account['token'], redirect?: string) { - if (isEmbedPage()) return; + if (embedPage) return; const showing = ref(true); popup(defineAsyncComponent(() => import('@/components/MkWaitingDialog.vue')), { diff --git a/packages/frontend/src/config.ts b/packages/frontend/src/config.ts index 277dfc12aa..2bec5ae262 100644 --- a/packages/frontend/src/config.ts +++ b/packages/frontend/src/config.ts @@ -21,6 +21,7 @@ export const version = _VERSION_; export const instanceName = siteName === 'Misskey' || siteName == null ? host : siteName; export const ui = miLocalStorage.getItem('ui'); export const debug = miLocalStorage.getItem('debug') === 'true'; +export const embedPage = location.pathname.startsWith('/embed'); export function updateLocale(newLocale): void { locale = newLocale; diff --git a/packages/frontend/src/local-storage.ts b/packages/frontend/src/local-storage.ts index 59e7333fbc..95b0165c19 100644 --- a/packages/frontend/src/local-storage.ts +++ b/packages/frontend/src/local-storage.ts @@ -47,20 +47,20 @@ const safeSessionStorage = new Map(); export const miLocalStorage = { getItem: (key: Keys): string | null => { - if (isEmbedPage()) { + if (embedPage) { return safeSessionStorage.get(key) ?? null; } return window.localStorage.getItem(key); }, setItem: (key: Keys, value: string): void => { - if (isEmbedPage()) { + if (embedPage) { safeSessionStorage.set(key, value); } else { window.localStorage.setItem(key, value); } }, removeItem: (key: Keys): void => { - if (isEmbedPage()) { + if (embedPage) { safeSessionStorage.delete(key); } else { window.localStorage.removeItem(key); @@ -78,7 +78,7 @@ export const miLocalStorage = { }, }; -if (isEmbedPage()) { +if (embedPage) { initEmbedPageLocalStorage(); if (_DEV_) console.warn('Using safeSessionStorage as localStorage alternative'); } diff --git a/packages/frontend/src/os.ts b/packages/frontend/src/os.ts index a85b2875fe..5ea49df20f 100644 --- a/packages/frontend/src/os.ts +++ b/packages/frontend/src/os.ts @@ -24,7 +24,7 @@ import MkContextMenu from '@/components/MkContextMenu.vue'; import { MenuItem } from '@/types/menu.js'; import copyToClipboard from '@/scripts/copy-to-clipboard.js'; import { showMovedDialog } from '@/scripts/show-moved-dialog.js'; -import { isEmbedPage } from '@/scripts/embed-page.js'; +import { embedPage } from '@/config.js'; export const openingWindowsCount = ref(0); @@ -173,7 +173,7 @@ export async function popup( events: ComponentEmit = {} as ComponentEmit, disposeEvent?: keyof ComponentEmit, ): Promise<{ dispose: () => void }> { - if (isEmbedPage()) return { dispose: () => {} }; + if (embedPage) return { dispose: () => {} }; markRaw(component); @@ -633,8 +633,8 @@ export function popupMenu(items: MenuItem[], src?: HTMLElement | EventTarget | n } export function contextMenu(items: MenuItem[], ev: MouseEvent): Promise { - if (isEmbedPage()) return Promise.resolve(); - + if (embedPage) return Promise.resolve(); + ev.preventDefault(); return new Promise(resolve => { let dispose; diff --git a/packages/frontend/src/scripts/embed-page.ts b/packages/frontend/src/scripts/embed-page.ts index f50cf98a74..74d22b05fb 100644 --- a/packages/frontend/src/scripts/embed-page.ts +++ b/packages/frontend/src/scripts/embed-page.ts @@ -4,17 +4,14 @@ */ import { miLocalStorage } from "@/local-storage.js"; import type { Keys } from "@/local-storage.js"; - -export function isEmbedPage() { - return location.pathname.startsWith('/embed'); -} +import { embedPage } from "@/config.js"; /** * EmbedページではlocalStorageを使用できないようにしているが、 * 動作に必要な値はsafeSessionStorage(miLocalStorage内のやつ)に移動する */ export function initEmbedPageLocalStorage() { - if (!isEmbedPage()) { + if (!embedPage) { return; } diff --git a/packages/frontend/src/scripts/idb-proxy.ts b/packages/frontend/src/scripts/idb-proxy.ts index 35cf4a885f..d3399073a8 100644 --- a/packages/frontend/src/scripts/idb-proxy.ts +++ b/packages/frontend/src/scripts/idb-proxy.ts @@ -10,12 +10,12 @@ import { set as iset, del as idel, } from 'idb-keyval'; -import { isEmbedPage } from './embed-page.js'; +import { embedPage } from '@/config.js'; import { miLocalStorage } from '@/local-storage.js'; const PREFIX = 'idbfallback::'; -let idbAvailable = typeof window !== 'undefined' ? !!(window.indexedDB && typeof window.indexedDB.open === 'function' && !isEmbedPage()) : true; +let idbAvailable = typeof window !== 'undefined' ? !!(window.indexedDB && typeof window.indexedDB.open === 'function' && !embedPage) : true; // iframe.contentWindow.indexedDB.deleteDatabase() がchromeのバグで使用できないため、indexedDBを無効化している。 // バグが治って再度有効化するのであれば、cypressのコマンド内のコメントアウトを外すこと diff --git a/packages/frontend/src/scripts/theme.ts b/packages/frontend/src/scripts/theme.ts index 60045ac9f0..4075cb36a5 100644 --- a/packages/frontend/src/scripts/theme.ts +++ b/packages/frontend/src/scripts/theme.ts @@ -11,7 +11,7 @@ import { globalEvents } from '@/events.js'; import lightTheme from '@/themes/_light.json5'; import darkTheme from '@/themes/_dark.json5'; import { miLocalStorage } from '@/local-storage.js'; -import { isEmbedPage } from '@/scripts/embed-page.js'; +import { embedPage } from '@/config.js'; export type Theme = { id: string; @@ -96,7 +96,7 @@ export function applyTheme(theme: Theme, persist = true) { document.documentElement.style.setProperty(`--${k}`, v.toString()); } - if (!isEmbedPage()) { + if (!embedPage) { document.documentElement.style.setProperty('color-scheme', colorScheme); } diff --git a/packages/frontend/src/stream.ts b/packages/frontend/src/stream.ts index 2723857e38..41b2a29b68 100644 --- a/packages/frontend/src/stream.ts +++ b/packages/frontend/src/stream.ts @@ -8,7 +8,7 @@ import { markRaw } from 'vue'; import { $i } from '@/account.js'; import { wsOrigin } from '@/config.js'; import { StreamMock } from '@/scripts/stream-mock.js'; -import { isEmbedPage } from '@/scripts/embed-page.js'; +import { embedPage } from '@/config.js'; // heart beat interval in ms const HEART_BEAT_INTERVAL = 1000 * 60; @@ -21,7 +21,7 @@ export function useStream(): Misskey.IStream { if (stream) return stream; // TODO: No Websocketモードもここで判定 - if (isEmbedPage()) { + if (embedPage) { stream = markRaw(new StreamMock(wsOrigin, null)); return stream; } else {