Files
zn-ai/electron/main.js
2025-09-23 18:57:14 +08:00

48 lines
1.1 KiB
JavaScript

const { app, ipcMain, BrowserWindow } = require("electron");
const { join } = require("path");
const createTray = require("../controller/tray");
// 映射页面
const env = app.isPackaged ? "production" : "development";
const createWindow = () => {
const win = new BrowserWindow({
width: 800,
height: 600,
// frame: false, // 不要自带的窗口
title: "China Fellou Plus",
webPreferences: {
preload: join(__dirname, "../preload/index.js"),
},
});
if (env === "development") {
win.loadURL("http://localhost:5173");
// 打开开发工具 { mode: "detach" }
win.webContents.openDevTools({ mode: "detach" });
} else {
win.loadFile("../dist/index.html");
}
// 系统托盘
createTray(app, win);
};
ipcMain.handle("sent-event", (event, params) => {
console.log(params);
return "1111";
});
app.whenReady().then(() => {
createWindow();
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") app.quit();
});