Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
69 lines (59 loc) · 1.42 KB
/
Copy pathmain.js
File metadata and controls
69 lines (59 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const { app, BrowserWindow, ipcMain } = require('electron');
const fs = require('fs');
const path = require('path');
function createWindow() {
const win = new BrowserWindow({
width: 1200,
height: 900,
webPreferences: {
nodeIntegration: true,
},
});
// win.loadFile('./src/index.html')
/*
* 加载应用----- electron-quick-start中默认的加载入口
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
*/
// 加载应用----适用于 react 项目
win.loadURL('http://localhost:3000/');
win.webContents.openDevTools(); // 默认打开开发者工具 {mode:'detach'/'right'/'left'/'bottom'}
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
// 获取数据接口
ipcMain.on('getData', (event, arg) => {
fs.readFile(
path.join(__dirname, './src/config.json'),
'utf8',
(err, data) => {
event.sender.send('data-reply', data);
}
);
});
ipcMain.on('updateData', (event, arg) => {
fs.writeFile(
path.join(__dirname, './src/config.json'),
JSON.stringify(arg),
'utf8',
(err) => {
event.sender.send('data-reply', arg);
}
);
});
try {
// 热重载
require('electron-reloader')(module);
} catch (_) {}