-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-entry.js
74 lines (68 loc) · 1.67 KB
/
app-entry.js
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
70
71
72
73
74
const { app, BrowserWindow, ipcMain, dialog } = require('electron');
const path = require('path');
const fs = require('fs');
const isPro = process.env.NODE_ENV !== 'development';
function renderWindow() {
const mainWindow = new BrowserWindow({
width: 750,
height: 550,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
// preload: path.resolve(__dirname, 'preload.js')
},
});
if (isPro) {
mainWindow.loadURL(
require('url').format({
pathname: path.join(__dirname, 'build/index.html'),
protocol: 'file:',
slashes: true,
}),
);
} else {
mainWindow.loadURL('http://localhost:8000/');
// 打开开发者工具,默认不打开
mainWindow.webContents.openDevTools();
}
ipcMain.on('read-laihuo-excel', async (evt) => {
const { filePaths } = await dialog.showOpenDialog({
filters: [
{
name: 'Excel',
extensions: ['xlsx'],
},
],
});
evt.reply(
'read-laihuo-success',
filePaths[0],
fs.readFileSync(filePaths[0]),
);
});
ipcMain.on('read-fahuo-excel', async (evt) => {
const { filePaths } = await dialog.showOpenDialog({
filters: [
{
name: 'Excel',
extensions: ['xlsx'],
},
],
});
evt.reply(
'read-fahuo-success',
filePaths[0],
fs.readFileSync(filePaths[0]),
);
});
}
app.whenReady().then(() => {
renderWindow();
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) renderWindow();
});
});
app.on('window-all-closed', () => {
if (process.platform === 'darwin') return;
app.quit();
});