Skip to content

Commit

Permalink
optimize feature disable and message display
Browse files Browse the repository at this point in the history
  • Loading branch information
eric2788 committed Oct 17, 2024
1 parent e9d4558 commit c74a52c
Showing 4 changed files with 8 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/contents/index/mounter.tsx
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion src/features/index.ts
Original file line number Diff line number Diff line change
@@ -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<Settings>, info: StreamInfo) => Promise<(React.ReactPortal | React.ReactNode)[] | undefined>
export type FeatureHookRender = (settings: Readonly<Settings>, info: StreamInfo) => Promise<(React.ReactPortal | React.ReactNode)[] | string | undefined>

export type FeatureAppRender = React.FC<{}>

2 changes: 1 addition & 1 deletion src/features/jimaku/index.tsx
Original file line number Diff line number Diff line change
@@ -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 [
5 changes: 2 additions & 3 deletions src/features/recorder/index.tsx
Original file line number Diff line number Diff line change
@@ -2,16 +2,15 @@ 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

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 [

0 comments on commit c74a52c

Please sign in to comment.