Appearance
cx
Appearance
首先创建一个新的目录,例如 client,然后进行初始化。
npm init -ynpm install --save-dev electron<!-- index.html 负责的是我们桌面应用的视图。 -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!-- 书写桌面程序界面的 -->
<h1>Hello Electron</h1>
<p>Hello from Electron!!!</p>
</body>
</html>// main.js
const { app, BrowserWindow } = require("electron");
// 创建窗口的方法
const createWindow = () => {
const win = new BrowserWindow({
width: 800,
height: 600,
});
win.loadFile("index.html");
};
// whenReady是一个生命周期方法,会在 Electron 完成应用初始化后调用
// 返回一个 promise
app.whenReady().then(() => {
createWindow();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
}){
"main": "main.js",
"scripts": {
"start": "electron ."
}
}为了将 Electron 的不同类型的进程桥接在一起,我们需要使用被称为 预加载 的特殊脚本