From fa8262af411c5f9f6968f8d6f64a0e3d639b5fde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ACT=E4=B8=B6=E6=B5=81=E6=98=9F=E9=9B=A8?= <1340145680@qq.com> Date: Tue, 31 Mar 2026 00:56:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=A0=E8=BD=BD=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/main.ts | 64 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/scripts/main.ts b/scripts/main.ts index 5a3b748..80da606 100644 --- a/scripts/main.ts +++ b/scripts/main.ts @@ -73,6 +73,52 @@ function requireWithCustomPaths(modulePath: string): any { } let mainWindow: BrowserWindow | null = null; +let loadingWindow: BrowserWindow | null = null; + +const loadingHtml = `data:text/html;charset=utf-8,${encodeURIComponent(` +
正在启动服务…
`)}`; + +function showLoading(): void { + loadingWindow = new BrowserWindow({ + width: 1000, + height: 700, + minWidth: 800, + minHeight: 500, + frame: false, + resizable: false, + maximizable: false, + minimizable: false, + show: true, + backgroundColor: "#ffffff", + autoHideMenuBar: true, + titleBarStyle: "hidden", + titleBarOverlay: { + color: "#ffffff", + symbolColor: "#333333", + height: 36, + }, + }); + loadingWindow.setMenuBarVisibility(false); + loadingWindow.removeMenu(); + loadingWindow.on("closed", () => { loadingWindow = null; }); + void loadingWindow.loadURL(loadingHtml); +} + +function closeLoading(): void { + if (loadingWindow && !loadingWindow.isDestroyed()) { + loadingWindow.close(); + loadingWindow = null; + } +} function createMainWindow(): void { const win = new BrowserWindow({ @@ -117,6 +163,9 @@ protocol.registerSchemesAsPrivileged([ ]); app.whenReady().then(async () => { + // 先显示加载窗口 + showLoading(); + try { let servePath: string; if (app.isPackaged) { @@ -169,6 +218,17 @@ app.whenReady().then(async () => { mainWindow?.webContents.openDevTools(); return { ok: true }; }, + openurlwithbrowser: () => { + const search = url.searchParams; + const targetUrl = search.get("url"); + if (targetUrl) { + const { shell } = require("electron"); + shell.openExternal(targetUrl); + return { ok: true }; + } else { + return { ok: false, error: "缺少url参数" }; + } + } }; const handler = handlers[pathname]; const responseData = handler ? handler() : { error: "未知接口" }; @@ -180,10 +240,12 @@ app.whenReady().then(async () => { }); }); + // 服务启动成功,关闭加载窗口,创建主窗口 + closeLoading(); createMainWindow(); } catch (err) { console.error("[服务启动失败]:", err); - // 如果服务启动失败,仍然创建窗口 + closeLoading(); createMainWindow(); } });