From ec3be231ecb0bc2b4631253858cc83dea6db001e Mon Sep 17 00:00:00 2001 From: Haochen Duan Date: Thu, 8 Aug 2024 21:41:18 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/src/ipcListener/openPlayerHtml.mts | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/main/src/ipcListener/openPlayerHtml.mts b/packages/main/src/ipcListener/openPlayerHtml.mts index 6e2639ac..a3123ee8 100644 --- a/packages/main/src/ipcListener/openPlayerHtml.mts +++ b/packages/main/src/ipcListener/openPlayerHtml.mts @@ -1,6 +1,5 @@ import { BrowserWindow, ipcMain, nativeTheme, type IpcMainEvent } from 'electron'; import type { PlayerInfo } from '@48tools/48tools/src/components/basic/initialState/initialState.js'; -import type { Pocket48LiveType, Pocket48LiveMode } from '@48tools/48tools/src/services/48/enum.js'; import { isTest, titleBarIcon, createHtmlFilePath, createInitialState } from '../utils.mjs'; import { themeEvent, type ThemeValue } from './themeChange.mjs'; import { getStore } from '../store.mjs'; @@ -10,6 +9,14 @@ import { WinIpcChannel } from '../channelEnum.js'; /* 记录id和窗口的关系 */ export const playerWindowMaps: Map = new Map(); +interface PlayerInfoSearchParams extends Omit { + liveType: `${ PlayerInfo['liveType'] }`; + liveMode: `${ PlayerInfo['liveMode'] }`; + rtmpPort: `${ PlayerInfo['rtmpPort'] }`; + httpPort: `${ PlayerInfo['httpPort'] }`; + proxyPort: `${ PlayerInfo['proxyPort'] }`; +} + /** * 打开播放器页面 * @param { string } title - 窗口标题 @@ -27,7 +34,7 @@ function open(title: string, query: string): void { return; } - const player: Record = Object.fromEntries(searchParams); + const playerSearchParams: PlayerInfoSearchParams = Object.fromEntries(searchParams) as unknown as PlayerInfoSearchParams; let win: BrowserWindow | null = new BrowserWindow({ width: 643, @@ -50,13 +57,13 @@ function open(title: string, query: string): void { theme: getStore().get('theme') ?? 'system', commandLineOptions, playerInfo: { - ...player, - liveType: Number(player.liveType) as Pocket48LiveType, - liveMode: Number(player.liveMode) as Pocket48LiveMode, - rtmpPort: player.rtmpPort ? Number(player.rtmpPort) : undefined, - httpPort: player.httpPort ? Number(player.httpPort) : undefined, - proxyPort: player.proxyPort ? Number(player.proxyPort) : undefined - } as PlayerInfo, + ...playerSearchParams, + liveType: Number(playerSearchParams.liveType), + liveMode: Number(playerSearchParams.liveMode), + rtmpPort: playerSearchParams.rtmpPort ? Number(playerSearchParams.rtmpPort) : undefined, + httpPort: playerSearchParams.httpPort ? Number(playerSearchParams.httpPort) : undefined, + proxyPort: playerSearchParams.proxyPort ? Number(playerSearchParams.proxyPort) : undefined + }, isTest }));