Skip to content

🎬 火宝短剧 - 基于AI的一站式短剧生成平台 《一句话生成完整短剧,从剧本到成片全自动化》 Huobao Drama - An AI-Powered End-to-End Short Drama Generator "One Sentence to Complete Drama: Fully Automated from Script to Final Video"

TypeScript

fix(desktop): 外链一律转系统浏览器打开

Connor2c69b21bd4ea
diff --git a/desktop/src/main.ts b/desktop/src/main.ts
index aa5e929..75f12d9 100644
--- a/desktop/src/main.ts
+++ b/desktop/src/main.ts
@@ -8,7 +8,7 @@
* 后端可重启(startBackend):存储位置迁移 = 停后端 → 搬文件 → 换 currentDataDir →
* 重启后端(见 migrate.ts);backendRestarting 期间抑制「异常退出」弹窗。
*/
-import { app, BrowserWindow, dialog, ipcMain, utilityProcess } from 'electron'
+import { app, BrowserWindow, dialog, ipcMain, shell, utilityProcess } from 'electron'
import type { UtilityProcess } from 'electron'
import * as net from 'net'
import * as fs from 'fs'
@@ -213,6 +213,18 @@ function createWindow() {
// 页面标题自带产品名,避免文件路径兜底标题
mainWindow.on('page-title-updated', e => e.preventDefault())
mainWindow.on('closed', () => { mainWindow = null })
+ // 外链一律交给系统浏览器:应用内不弹新窗(如设置页「前往 api.firemux.com 获取 Key」)
+ const isAppUrl = (url: string) => url.startsWith(`http://127.0.0.1:${backendPort}`)
+ mainWindow.webContents.setWindowOpenHandler(({ url }) => {
+ if (/^https?:\/\//i.test(url) && !isAppUrl(url)) void shell.openExternal(url)
+ return { action: 'deny' }
+ })
+ // 主窗口意外导航到外部地址时同样拦下并转浏览器
+ mainWindow.webContents.on('will-navigate', (e, url) => {
+ if (isAppUrl(url)) return
+ e.preventDefault()
+ if (/^https?:\/\//i.test(url)) void shell.openExternal(url)
+ })
return mainWindow.loadURL(`http://127.0.0.1:${backendPort}`)
}