diff --git a/packages/frontend/src/_embed_boot_.ts b/packages/frontend/src/_embed_boot_.ts index 836e6865b6..36f5e6143d 100644 --- a/packages/frontend/src/_embed_boot_.ts +++ b/packages/frontend/src/_embed_boot_.ts @@ -12,33 +12,55 @@ import { createApp, defineAsyncComponent } from 'vue'; import { common } from '@/boot/common.js'; import type { CommonBootOptions } from '@/boot/common.js'; import { setIframeId, postMessageToParentWindow } from '@/scripts/post-message.js'; +import { parseEmbedParams } from '@/scripts/embed-page.js'; import { defaultStore } from '@/store.js'; const bootOptions: Partial = {}; -// カラーモードのオーバーライド const params = new URLSearchParams(location.search); -const color = params.get('colorMode'); -if (color && ['light', 'dark'].includes(color)) { - bootOptions.forceColorMode = color as 'light' | 'dark'; +const embedParams = parseEmbedParams(params); + +// カラーモードのオーバーライド +if (embedParams.colorMode != null) { + bootOptions.forceColorMode = embedParams.colorMode; } +// サイズの制限 +document.documentElement.style.maxWidth = '500px'; + +// サーバー起動の場合はもとから付与されているけど一応 +document.documentElement.classList.add('embed'); + // 外部タブでのstoreの変更の影響を受けないように defaultStore.setConfig({ disableMessageChannel: true, }); // iframeIdの設定 -window.addEventListener('message', event => { +function setIframeIdHandler(event: MessageEvent) { if (event.data?.type === 'misskey:embedParent:registerIframeId' && event.data.payload?.iframeId != null) { setIframeId(event.data.payload.iframeId); + window.removeEventListener('message', setIframeIdHandler); } -}); +} +window.addEventListener('message', setIframeIdHandler); // 起動 common(() => createApp( defineAsyncComponent(() => import('@/ui/embed.vue')), -), bootOptions).then(({ isClientUpdated }) => { +), bootOptions).then(async ({ app }) => { + //#region Embed Provide + app.provide('EMBED_PAGE', true); + app.provide('embedParams', embedParams); + //#endregion + + //#region defaultStoreを書き換え + await defaultStore.ready; + + defaultStore.set('sound_notUseSound', true); + defaultStore.set('showPreview', false); + //#endregion + // 起動完了を通知(このあとクライアント側から misskey:embedParent:registerIframeId が送信される) postMessageToParentWindow('misskey:embed:ready'); }); diff --git a/packages/frontend/src/ui/embed.vue b/packages/frontend/src/ui/embed.vue index 984b78c9a7..a505cbea14 100644 --- a/packages/frontend/src/ui/embed.vue +++ b/packages/frontend/src/ui/embed.vue @@ -26,13 +26,16 @@ SPDX-License-Identifier: AGPL-3.0-only