fix: 提升Windows分发包启动兼容性
This commit is contained in:
1 parent
5de47ee420
commit
cb68af5a0f
3 files changed
+92
-5
No files matched your search
+28
-1
@@ -7,11 +7,17 @@ import { createDemoFlow, createExampleFlows, createFlow, deleteFlow, getFlow, li
|
||||
import { capabilityCount, capabilityIds } from "./engine/registry";
|
||||
import { closeBrowserSession, startRun, stopRun } from "./run/manager";
|
||||
import { fixtureUrl, startFixtureServer, stopFixtureServer } from "./fixture/server";
|
||||
import { logMain } from "./logger";
|
||||
|
||||
let mainWindow: BrowserWindow | null = null;
|
||||
|
||||
if (process.env.RPA_ENABLE_GPU !== "1") app.disableHardwareAcceleration();
|
||||
process.on("uncaughtException", (error) => logMain("uncaughtException", error.stack || error.message));
|
||||
process.on("unhandledRejection", (reason) => logMain("unhandledRejection", reason instanceof Error ? reason.stack || reason.message : String(reason)));
|
||||
|
||||
function createWindow(): void {
|
||||
const e2e = process.env.RPA_E2E === "1";
|
||||
logMain("createWindow", { packaged: app.isPackaged, appPath: app.getAppPath(), userData: app.getPath("userData") });
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 1440,
|
||||
height: 900,
|
||||
@@ -34,7 +40,18 @@ function createWindow(): void {
|
||||
}
|
||||
});
|
||||
|
||||
mainWindow.on("ready-to-show", () => { if (!e2e) mainWindow?.show(); });
|
||||
let shown = false;
|
||||
const showWindow = (source: string) => {
|
||||
if (e2e || shown || !mainWindow || mainWindow.isDestroyed()) return;
|
||||
shown = true;
|
||||
logMain("showWindow", source);
|
||||
mainWindow.show();
|
||||
mainWindow.focus();
|
||||
};
|
||||
const showFallback = setTimeout(() => showWindow("fallback-timeout"), 5000);
|
||||
mainWindow.on("ready-to-show", () => { clearTimeout(showFallback); showWindow("ready-to-show"); });
|
||||
mainWindow.on("unresponsive", () => logMain("window-unresponsive"));
|
||||
mainWindow.on("responsive", () => logMain("window-responsive"));
|
||||
mainWindow.on("closed", () => {
|
||||
mainWindow = null;
|
||||
});
|
||||
@@ -42,6 +59,14 @@ function createWindow(): void {
|
||||
if (/^https?:/i.test(url)) void shell.openExternal(url);
|
||||
return { action: "deny" };
|
||||
});
|
||||
mainWindow.webContents.on("did-fail-load", (_event, code, description, url) => {
|
||||
logMain("did-fail-load", { code, description, url });
|
||||
showWindow("did-fail-load");
|
||||
});
|
||||
mainWindow.webContents.on("render-process-gone", (_event, details) => logMain("render-process-gone", details));
|
||||
mainWindow.webContents.on("console-message", (_event, level, message, line, sourceId) => {
|
||||
if (level >= 2) logMain("renderer-console", { level, message, line, sourceId });
|
||||
});
|
||||
|
||||
const devUrl = process.env.ELECTRON_RENDERER_URL;
|
||||
if (devUrl) {
|
||||
@@ -121,10 +146,12 @@ if (!gotLock) {
|
||||
});
|
||||
|
||||
app.whenReady().then(async () => {
|
||||
logMain("app-ready", { electron: process.versions.electron, chrome: process.versions.chrome, node: process.versions.node });
|
||||
try {
|
||||
await startFixtureServer(Number(process.env.RPA_FIXTURE_PORT || 17863));
|
||||
} catch (error) {
|
||||
console.warn("local fixture server unavailable", error);
|
||||
logMain("fixture-server-failed", error instanceof Error ? error.stack || error.message : String(error));
|
||||
}
|
||||
registerIpc();
|
||||
createWindow();
|
||||
|
||||
Reference in new issue
Block a user