forked from nukeop/nuclear
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.prod.js
91 lines (75 loc) · 2 KB
/
main.prod.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
require('babel-polyfill');
const { app, ipcMain, nativeImage, BrowserWindow, Menu, Tray } = require('electron');
const platform = require('electron-platform');
const path = require('path');
const url = require('url');
const getOption = require('./store').getOption;
let win;
let tray;
let icon = nativeImage.createFromPath(path.resolve(__dirname, 'resources', 'media', 'icon.png'));
function changeWindowTitle(artist, title) {
win.setTitle(`${artist} - ${title} - Nuclear Music Player`);
}
function createWindow() {
win = new BrowserWindow({
width: 1366,
height: 768,
frame: !getOption('framelessWindow'),
icon: icon,
show: false,
webPreferences: {
experimentalFeatures: true,
webSecurity: false
},
additionalArguments: [
getOption('disableGPU') && '--disable-gpu'
]
});
win.setTitle('Nuclear Music Player');
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}));
win.once('ready-to-show', () => {
win.show();
});
win.on('closed', () => {
win = null;
});
// MacOS specific
if (platform.isDarwin) {
app.dock.setIcon(icon);
icon = nativeImage.createFromPath(path.resolve(__dirname, 'resources', 'media', 'icon_apple.png'));
}
const trayMenu = Menu.buildFromTemplate([
{label: 'Quit', type: 'normal', click:
(menuItem, browserWindow, event) => {
app.quit();
}
}
]);
tray = new Tray(icon);
tray.setTitle('Nuclear Music Player');
tray.setToolTip('Nuclear Music Player');
tray.setContextMenu(trayMenu);
ipcMain.on('close', () => {
app.quit();
});
ipcMain.on('minimize', () => {
win.minimize();
});
ipcMain.on('maximize', () => {
win.isMaximized() ? win.unmaximize() : win.maximize();
});
ipcMain.on('songChange', (event, arg) => {
if (arg === null) {
return;
}
changeWindowTitle(arg.artist, arg.name);
});
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
app.quit();
});