flat: 暂存
This commit is contained in:
@@ -1,31 +1,11 @@
|
||||
import { app, shell, BrowserWindow } from "electron";
|
||||
import { electronApp, optimizer, is } from "@electron-toolkit/utils";
|
||||
import icon from "../../resources/icon.png?asset";
|
||||
import { setupLiveHandlers } from "./ipc/live";
|
||||
import { setupPromptHandlers } from "./ipc/prompt";
|
||||
import { setupWorkflowHandlers } from "./ipc/workflow";
|
||||
import { preload, indexHtml, ELECTRON_RENDERER_URL } from "./config";
|
||||
|
||||
// 在开发环境下启用热重载
|
||||
if (is.dev) {
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
require("electron-reloader")(module, {
|
||||
debug: true,
|
||||
watchRenderer: true, // 同时监视渲染进程文件
|
||||
ignore: [
|
||||
/node_modules/,
|
||||
/dist/,
|
||||
/release/,
|
||||
/\.[\/\\]\./, // 忽略点文件
|
||||
/package(-lock)?\.json/,
|
||||
],
|
||||
});
|
||||
console.log("Electron hot reload enabled");
|
||||
} catch (err) {
|
||||
console.error("Error enabling hot reload:", err);
|
||||
}
|
||||
}
|
||||
// 简单的开发环境检测
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
|
||||
/**
|
||||
* 创建主窗口
|
||||
@@ -36,7 +16,6 @@ function createWindow(): void {
|
||||
height: 670,
|
||||
show: false,
|
||||
autoHideMenuBar: true,
|
||||
...(process.platform === "linux" ? { icon } : {}),
|
||||
webPreferences: {
|
||||
preload,
|
||||
sandbox: false,
|
||||
@@ -47,14 +26,24 @@ function createWindow(): void {
|
||||
mainWindow.show();
|
||||
});
|
||||
|
||||
// mainWindow.webContents.openDevTools();
|
||||
mainWindow.webContents.openDevTools();
|
||||
|
||||
mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||
shell.openExternal(details.url);
|
||||
return { action: "deny" };
|
||||
});
|
||||
|
||||
if (is.dev && ELECTRON_RENDERER_URL) {
|
||||
// 窗口关闭时强制清理资源并退出应用
|
||||
mainWindow.on("closed", () => {
|
||||
// 清理所有资源
|
||||
mainWindow.removeAllListeners();
|
||||
// 强制退出应用
|
||||
if (process.platform !== "darwin") {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
if (isDev && ELECTRON_RENDERER_URL) {
|
||||
mainWindow.loadURL(ELECTRON_RENDERER_URL);
|
||||
} else {
|
||||
mainWindow.loadFile(indexHtml);
|
||||
@@ -65,13 +54,9 @@ function createWindow(): void {
|
||||
* 准备好后
|
||||
*/
|
||||
app.whenReady().then(() => {
|
||||
electronApp.setAppUserModelId("com.electron");
|
||||
app.setAppUserModelId("com.electron");
|
||||
|
||||
app.on("browser-window-created", (_, window) => {
|
||||
optimizer.watchWindowShortcuts(window);
|
||||
});
|
||||
|
||||
// 直播相关处理
|
||||
// 直播相关处理
|
||||
setupLiveHandlers();
|
||||
|
||||
setupPromptHandlers();
|
||||
@@ -89,7 +74,27 @@ app.whenReady().then(() => {
|
||||
* 退出应用
|
||||
*/
|
||||
app.on("window-all-closed", () => {
|
||||
// 强制清理所有资源
|
||||
if (process.platform !== "darwin") {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
// 在开发环境中,确保进程正确退出
|
||||
app.on("before-quit", () => {
|
||||
// 清理所有资源
|
||||
const windows = BrowserWindow.getAllWindows();
|
||||
windows.forEach(window => {
|
||||
window.removeAllListeners();
|
||||
window.close();
|
||||
});
|
||||
});
|
||||
|
||||
// 处理进程退出信号
|
||||
process.on("SIGINT", () => {
|
||||
app.quit();
|
||||
});
|
||||
|
||||
process.on("SIGTERM", () => {
|
||||
app.quit();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user