forked from Alen-gao/Music
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
74 lines (64 loc) · 1.93 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
73
74
var app = require('app'); // Module to control application life.
var ipc = require('ipc');
var Tray = require('tray');
var Menu = require('menu');
var path = require('path');
var powerSaveBlocker = require('power-save-blocker');
var BrowserWindow = require('browser-window'); // Module to create native browser window.
// Report crashes to our server.
require('crash-reporter').start();
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
var mainWindow = null;
var appIcon = null;
// Quit when all windows are closed.
app.on('window-all-closed', function() {
if (process.platform != 'darwin') {
app.quit();
}
});
// app.on('closed')
// This method will be called when Electron has done everything
// initialization and ready for creating browser windows.
app.on('ready', function() {
// Create the browser window.
var ico = path.join(__dirname, 'images', 'ico.png');
mainWindow = new BrowserWindow({
width: 990
,height: 620
,frame: false
,icon: ico
});
// mainWindow.setFullScreen(true);
//set tray icon
appIcon = new Tray(ico);
var blocker_id = null;
var contextMenu = Menu.buildFromTemplate([
{ label: '退出',
accelerator: 'Command+Q',
selector: 'terminate:',
click: function() {
mainWindow.close();
mainWindow = null;
}
}
]);
appIcon.setToolTip('Play Music');
appIcon.setContextMenu(contextMenu);
// and load the index.html of the app.
mainWindow.loadUrl('file://' + __dirname + '/index.html');
// Emitted when the window is closed.
ipc.on('close', function(event, arg) {
mainWindow.close();
mainWindow = null;
});
ipc.on('maximize', function(event, arg) {
mainWindow.maximize();
});
ipc.on('minimize', function(event, arg) {
mainWindow.minimize();
});
ipc.on('restore', function(event, arg) {
mainWindow.restore();
});
});