Compare commits

..
3 Commits
Author SHA1 Message Date
wonder b5b0d415ac 🔧Chore: IPC 通信 2025-10-30 09:08:49 +08:00
wonder 9897662b35 ✨Feat: 显示系统运行环境 2025-10-30 08:55:54 +08:00
wonder 9ab9b380de ✨Feat: 监听关闭事件 2025-10-30 08:41:34 +08:00
4 changed files with 30 additions and 1 deletions
+2
View File
@@ -16,5 +16,7 @@
<body> <body>
<h1>Hello Electron</h1> <h1>Hello Electron</h1>
<p>👋</p> <p>👋</p>
<p id="info"></p>
</body> </body>
<script src="renderer.js"></script>
</html> </html>
+11 -1
View File
@@ -1,14 +1,24 @@
const { app, BrowserWindow } = require("electron"); const { app, BrowserWindow, ipcMain } = require("electron");
const path = require("node:path");
const createWindow = () => { const createWindow = () => {
const win = new BrowserWindow({ const win = new BrowserWindow({
width: 800, width: 800,
height: 600, height: 600,
webPreferences: {
preload: path.join(__dirname, "preload.js"),
},
}); });
win.loadFile("index.html"); win.loadFile("index.html");
}; };
app.whenReady().then(() => { app.whenReady().then(() => {
ipcMain.handle("ping", () => "pong");
createWindow(); createWindow();
}); });
app.on("window-all-closed", () => {
if (process.platform !== "darwin") app.quit();
});
+8
View File
@@ -0,0 +1,8 @@
const { contextBridge, ipcRenderer } = require("electron");
contextBridge.exposeInMainWorld("versions", {
node: () => process.versions.node,
chrome: () => process.versions.chrome,
electron: () => process.versions.electron,
ping: () => ipcRenderer.invoke("ping"),
});
+9
View File
@@ -0,0 +1,9 @@
const func = async () => {
const response = await window.versions.ping();
console.log(response);
};
func();
const information = document.getElementById("info");
information.innerText = `Node.js version: ${window.versions.node()}\nChrome version: ${window.versions.chrome()}\nElectron version: ${window.versions.electron()}`;