Skip to content

Commit 23ae08c

Browse files
committed
optimize feature disable and message display
1 parent 46b4739 commit 23ae08c

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

src/contents/index/mounter.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ function createMountPoints(plasmo: PlasmoSpec, info: StreamInfo): RootMountable[
6060

6161
const portals = await hook(settings, info)
6262
// 返回禁用狀態的話則直接跳過渲染
63-
if (!portals) {
63+
if (typeof portals === 'string') {
64+
toast.warning(portals, { position: 'top-center' })
65+
return
66+
} else if (!portals) {
6467
console.info(`房間 ${info.room} 已被 ${key} 功能禁用,已略過`)
6568
return
6669
}

src/features/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as recorder from './recorder'
55
import type { StreamInfo } from '~api/bilibili'
66
import type { Settings } from '~options/fragments'
77

8-
export type FeatureHookRender = (settings: Readonly<Settings>, info: StreamInfo) => Promise<(React.ReactPortal | React.ReactNode)[] | undefined>
8+
export type FeatureHookRender = (settings: Readonly<Settings>, info: StreamInfo) => Promise<(React.ReactPortal | React.ReactNode)[] | string | undefined>
99

1010
export type FeatureAppRender = React.FC<{}>
1111

src/features/jimaku/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const handler: FeatureHookRender = async (settings, info) => {
9595
if (noNativeVtuber && (await retryCatcher(() => isNativeVtuber(info.uid), 5))) {
9696
// do log
9797
console.info('檢測到為國V, 已略過')
98-
return undefined // 返回 undefined 以禁用此功能
98+
return undefined // 返回 undefined 以禁用此功能且不發送任何警告
9999
}
100100

101101
return [

src/features/recorder/index.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ import RecorderFeatureContext from "~contexts/RecorderFeatureContext";
22
import type { FeatureHookRender } from "~features";
33
import { sendMessager } from "~utils/messaging";
44
import RecorderLayer from "./components/RecorderLayer";
5-
import { toast } from "sonner";
65

76
export const FeatureContext = RecorderFeatureContext
87

98
const handler: FeatureHookRender = async (settings, info) => {
109

1110
const { error, data: urls } = await sendMessager('get-stream-urls', { roomId: info.room })
1211
if (error) {
13-
toast.error('启用快速切片功能失败: '+ error)
14-
return undefined // disable the feature
12+
console.warn('啟用快速切片功能失敗: ', error)
13+
return '啟用快速切片功能失敗: '+ error // 返回 string 以顯示錯誤
1514
}
1615

1716
return [

0 commit comments

Comments
 (0)