feat: 初始化项目
This commit is contained in:
46
electron/main.js
Normal file
46
electron/main.js
Normal file
@@ -0,0 +1,46 @@
|
||||
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, // 不要自带的窗口
|
||||
webPreferences: {
|
||||
preload: join(__dirname, "./preload/index.js"),
|
||||
},
|
||||
});
|
||||
|
||||
if (env === "development") {
|
||||
win.loadURL("http://localhost:5173");
|
||||
|
||||
// 打开开发工具 { mode: "detach" }
|
||||
// win.webContents.openDevTools();
|
||||
} 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();
|
||||
});
|
||||
Reference in New Issue
Block a user