From 2632e457bf8806064659806c3d5648a28e51ae4a Mon Sep 17 00:00:00 2001 From: eric2788 Date: Wed, 16 Oct 2024 21:45:00 +0800 Subject: [PATCH] optimize feature disable and message display --- src/contents/index/mounter.tsx | 5 ++++- src/features/index.ts | 2 +- src/features/jimaku/index.tsx | 2 +- src/features/recorder/index.tsx | 5 ++--- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/contents/index/mounter.tsx b/src/contents/index/mounter.tsx index 78da8e07..5f6bbf59 100644 --- a/src/contents/index/mounter.tsx +++ b/src/contents/index/mounter.tsx @@ -60,7 +60,10 @@ function createMountPoints(plasmo: PlasmoSpec, info: StreamInfo): RootMountable[ const portals = await hook(settings, info) // 返回禁用狀態的話則直接跳過渲染 - if (!portals) { + if (typeof portals === 'string') { + toast.warning(portals, { position: 'top-center' }) + return + } else if (!portals) { console.info(`房間 ${info.room} 已被 ${key} 功能禁用,已略過`) return } diff --git a/src/features/index.ts b/src/features/index.ts index d45cb98a..cabe45f6 100644 --- a/src/features/index.ts +++ b/src/features/index.ts @@ -5,7 +5,7 @@ import * as recorder from './recorder' import type { StreamInfo } from '~api/bilibili' import type { Settings } from '~options/fragments' -export type FeatureHookRender = (settings: Readonly, info: StreamInfo) => Promise<(React.ReactPortal | React.ReactNode)[] | undefined> +export type FeatureHookRender = (settings: Readonly, info: StreamInfo) => Promise<(React.ReactPortal | React.ReactNode)[] | string | undefined> export type FeatureAppRender = React.FC<{}> diff --git a/src/features/jimaku/index.tsx b/src/features/jimaku/index.tsx index ecea7963..cbd8441c 100644 --- a/src/features/jimaku/index.tsx +++ b/src/features/jimaku/index.tsx @@ -95,7 +95,7 @@ const handler: FeatureHookRender = async (settings, info) => { if (noNativeVtuber && (await retryCatcher(() => isNativeVtuber(info.uid), 5))) { // do log console.info('檢測到為國V, 已略過') - return undefined // 返回 undefined 以禁用此功能 + return undefined // 返回 undefined 以禁用此功能且不發送任何警告 } return [ diff --git a/src/features/recorder/index.tsx b/src/features/recorder/index.tsx index 3425bf33..0efc8ffd 100644 --- a/src/features/recorder/index.tsx +++ b/src/features/recorder/index.tsx @@ -2,7 +2,6 @@ import RecorderFeatureContext from "~contexts/RecorderFeatureContext"; import type { FeatureHookRender } from "~features"; import { sendMessager } from "~utils/messaging"; import RecorderLayer from "./components/RecorderLayer"; -import { toast } from "sonner"; export const FeatureContext = RecorderFeatureContext @@ -10,8 +9,8 @@ const handler: FeatureHookRender = async (settings, info) => { const { error, data: urls } = await sendMessager('get-stream-urls', { roomId: info.room }) if (error) { - toast.error('启用快速切片功能失败: '+ error) - return undefined // disable the feature + console.warn('啟用快速切片功能失敗: ', error) + return '啟用快速切片功能失敗: '+ error // 返回 string 以顯示錯誤 } return [