Files
yuanhe-checkin-electron/electron/main.js
2025-11-20 10:00:02 +08:00

43 lines
934 B
JavaScript

const { app, BrowserWindow } = require("electron");
const path = require("path");
function createWindow() {
const win = new BrowserWindow({
width: 1080,
height: 1920,
webPreferences: {
preload: path.join(__dirname, "preload.js"),
nodeIntegration: false,
contextIsolation: true,
},
});
// 开发环境下加载 Vite 开发服务器地址
// 生产环境下加载打包后的 index.html
const isDev = !app.isPackaged;
if (isDev) {
win.loadURL("http://localhost:5173");
// 打开开发者工具
win.webContents.openDevTools();
} else {
win.loadFile(path.join(__dirname, "../dist/index.html"));
}
}
app.whenReady().then(() => {
createWindow();
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});