-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmain.js
72 lines (59 loc) · 1.56 KB
/
main.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
'use strict';
const ipc = require('electron').ipcMain;
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const Menu = electron.Menu;
const Tray = electron.Tray;
let mainWindow;
let appIcon;
function createWindow ()
{
mainWindow = new BrowserWindow({width: 982, height: 600, frame: false, resizable: false});
mainWindow.loadURL('file://' + __dirname + '/index.html');
//mainWindow.webContents.openDevTools();
mainWindow.on('closed', () =>
{
mainWindow = null;
app.quit();
});
}
function createTray()
{
appIcon = new Tray(__dirname + '/163Music.png');
var contextMenu = Menu.buildFromTemplate([
{ label: '⏯ Play / Pause', click: () => { playControl('playPause'); } },
{ label: '⏩ Next', click: () => { playControl('next'); } },
{ label: '⏪ Previous', click: () => { playControl('previous'); } },
{ type: 'separator' },
{ label: 'Main Window', click: ()=>{ windowControl('showMain'); } },
{ label: 'Quit', click: () => { app.quit(); }}
]);
appIcon.setToolTip('This is my application.');
appIcon.setContextMenu(contextMenu);
}
function playControl(cmd)
{
mainWindow.webContents.send("playControl", cmd);
}
function windowControl(cmd)
{
mainWindow.webContents.send("windowControl", cmd);
}
app.on('ready', () =>
{
createWindow();
createTray();
});
app.on('window-all-closed', () =>
{
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () =>
{
if (mainWindow === null) {
createWindow();
}
});