-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.development.js
executable file
·121 lines (105 loc) · 2.7 KB
/
main.development.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
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
import { app, BrowserWindow, Menu, shell, Tray } from 'electron';
let menu;
let template;
let mainWindow = null;
let tray = null;
if (process.env.NODE_ENV === 'development') {
require('electron-debug')(); // eslint-disable-line global-require
}
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});
const installExtensions = async () => {
if (process.env.NODE_ENV === 'development') {
const installer = require('electron-devtools-installer'); // eslint-disable-line global-require
const extensions = [
'REACT_DEVELOPER_TOOLS',
'REDUX_DEVTOOLS'
];
const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
for (const name of extensions) {
try {
await installer.default(installer[name], forceDownload);
} catch (e) {} // eslint-disable-line
}
}
};
app.on('ready', async () => {
await installExtensions();
mainWindow = new BrowserWindow({
show: false,
width: 318,
height: 500,
frame: false,
resizable: process.env.NODE_ENV === 'development'
});
mainWindow.loadURL(`file://${__dirname}/app/app.html`);
mainWindow.webContents.on('did-finish-load', () => {
const contextMenu = Menu.buildFromTemplate([
{
label: 'Bring to top',
click() {
mainWindow.show();
mainWindow.focus();
}
},
{
label: 'Quit',
click() {
app.quit();
}
}
]);
tray = new Tray(`${__dirname}/app/tray.png`);
tray.setToolTip('Electron Music Player Tutorial');
mainWindow.show();
mainWindow.focus();
tray.setContextMenu(contextMenu);
});
mainWindow.on('closed', () => {
mainWindow = null;
});
if (process.env.NODE_ENV === 'development') {
mainWindow.webContents.on('context-menu', (e, props) => {
const { x, y } = props;
Menu.buildFromTemplate([{
label: 'Inspect element',
click() {
mainWindow.inspectElement(x, y);
}
}]).popup(mainWindow);
});
}
if (process.platform === 'darwin') {
template = [{
label: 'MusicPlayer',
submenu: [{
label: 'About Music Player',
selector: 'orderFrontStandardAboutPanel:'
}, {
type: 'separator'
}, {
label: 'Quit',
accelerator: 'Command+Q',
click() {
app.quit();
}
}]
}];
menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
} else {
template = [{
label: '&File',
submenu: [{
label: '&Exit',
accelerator: 'Alt+f4',
click() {
app.quit();
}
}]
}];
menu = Menu.buildFromTemplate(template);
mainWindow.setMenu(menu);
}
});