-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
134 lines (120 loc) · 3.41 KB
/
index.js
File metadata and controls
134 lines (120 loc) · 3.41 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
const electron = require('electron');
const path = require('path');
const {app, BrowserWindow, Menu, Notification, Tray} = electron;
let mainWindow;
let modalWindow;
let pyProcess = null;
let pyProcessPort = null;
const createNewWindow = () => {
modalWindow = new BrowserWindow({
width: 800,
height: 600,
title: "add New"
});
modalWindow.on('closed', () => {
modalWindow = null;
});
};
const createNewTray = () => {
const iconPath = path.join(__dirname, './resources/happy.png');
const tray = new Tray(iconPath);
const menuConf = Menu.buildFromTemplate([
{
label: 'Quit',
}
]);
tray.popUpContextMenu(menuConf);
};
const createPySubProcess = () => {
// let script = path.join(__dirname, 'backend', 'api.py');
let script = path.join(__dirname, 'pydist', 'api2', 'api2');
pyProcessPort = '4242';
// pyProcess = require('child_process').spawn('/anaconda3/envs/AIR/bin/python', [script, pyProcessPort]);
pyProcess = require('child_process').execFile(script, [pyProcessPort]);
if (process != null) {
console.log('child process success');
}
};
const exitPySubProcess = () => {
pyProcess.kill();
pyProcess = null;
pyProcess = null;
};
const menuTemplates = () => {
const baseTempate = [
{
label: 'File',
submenu:[
{
label: 'New Item',
accelerator: (process.platform === 'darwin' ? 'Command+' : 'Ctrl+') + 'N',
click() {
createNewWindow()
}
},
{
label: 'NOTIFICATION',
click() {
let myNotification = new Notification( {
title: "haha",
subtitle: "???",
body: '通知正文内容'
});
myNotification.onclick = () => {
console.log('通知被点击');
};
myNotification.show()
}
},
{
label: 'Quit',
click() {
app.quit()
}
}
]
}
];
if (process.platform === 'darwin') {
baseTempate.unshift({});
}
if (process.env.NODE_ENV !== 'production') {
baseTempate.push({
label: 'Debug',
submenu:[
{
label: "develop tool",
click(item, focusedWindow) {
focusedWindow.toggleDevTools()
}
}
]
});
}
return baseTempate;
};
app.on('ready', () => {
createPySubProcess();
mainWindow = new BrowserWindow({
width: 800,
height: 600,
frame: false,
resizable: false,
show: false,
});
mainWindow.loadFile('index.html');
mainWindow.on('closed', () => {
mainWindow = null;
});
createNewTray();
const mainMenu = Menu.buildFromTemplate(menuTemplates());
Menu.setApplicationMenu(mainMenu)
});
app.on('will-quit', () => {
exitPySubProcess()
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});