flat: 暂存
This commit is contained in:
92
src/main/index.ts
Normal file
92
src/main/index.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
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 { 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建主窗口
|
||||
*/
|
||||
function createWindow(): void {
|
||||
const mainWindow = new BrowserWindow({
|
||||
width: 1080,
|
||||
height: 670,
|
||||
show: false,
|
||||
autoHideMenuBar: true,
|
||||
...(process.platform === "linux" ? { icon } : {}),
|
||||
webPreferences: {
|
||||
preload,
|
||||
sandbox: false,
|
||||
},
|
||||
});
|
||||
|
||||
mainWindow.on("ready-to-show", () => {
|
||||
mainWindow.show();
|
||||
});
|
||||
|
||||
// mainWindow.webContents.openDevTools();
|
||||
|
||||
mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||
shell.openExternal(details.url);
|
||||
return { action: "deny" };
|
||||
});
|
||||
|
||||
if (is.dev && ELECTRON_RENDERER_URL) {
|
||||
mainWindow.loadURL(ELECTRON_RENDERER_URL);
|
||||
} else {
|
||||
mainWindow.loadFile(indexHtml);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 准备好后
|
||||
*/
|
||||
app.whenReady().then(() => {
|
||||
electronApp.setAppUserModelId("com.electron");
|
||||
|
||||
app.on("browser-window-created", (_, window) => {
|
||||
optimizer.watchWindowShortcuts(window);
|
||||
});
|
||||
|
||||
// 直播相关处理
|
||||
setupLiveHandlers();
|
||||
|
||||
setupPromptHandlers();
|
||||
|
||||
createWindow();
|
||||
|
||||
app.on("activate", function () {
|
||||
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* 退出应用
|
||||
*/
|
||||
app.on("window-all-closed", () => {
|
||||
if (process.platform !== "darwin") {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user