This repository has been archived by the owner on Mar 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathmain.js
129 lines (111 loc) · 3.02 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
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
'use strict';
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const ipcMain = electron.ipcMain;
const Tray = electron.Tray;
const Menu = electron.Menu;
const Childprocess = require('child_process');
const path = require('path');
const http = require('http');
var server = require('./server/server');
let mainWindow;
var appIcon = null;
function createWindow () {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
nodeIntegration: 'iframe',
webSecurity: false,
},
title: 'CloudMusic',
frame: false,
icon: 'app/assets/icon.png',
});
mainWindow.loadURL('http://127.0.0.1:8080');
//mainWindow.loadURL('file://' + __dirname + '/index.html');
console.log('loadURL');
mainWindow.webContents.on('did-finish-load', function() {
var session = electron.session.defaultSession;
session.cookies.get({}, function(error, cookies) {
mainWindow.webContents.send('cookie', cookies);
});
});
//mainWindow.webContents.openDevTools();
mainWindow.on('closed', function() {
mainWindow = null;
});
server.listen(11015, function() {
console.log('cloud music server listening on port 11015...')
});
// Tray
appIcon = new Tray('./app/assets/tray.png');
const contextMenu = Menu.buildFromTemplate([
{ label: '播放/暂停', type: 'normal', click:
function(menuitem, window) {
mainWindow.webContents.send('playorpause');
}
},
{ label: '上一首', type: 'normal', click:
function(menuitem, window) {
mainWindow.webContents.send('previous');
}
},
{ label: '下一首', type: 'normal', click:
function(menuitem, window) {
mainWindow.webContents.send('next');
}
},
{ label: '隐藏/显示', type: 'normal', click:
function(menuitem, window) {
if (mainWindow.isVisible()) {
mainWindow.hide();
} else {
mainWindow.show();
}
}
},
{ label: '退出', type: 'normal', click:
function(menuitem, window) {
app.quit();
}
},
]);
appIcon.setToolTip('CloudMusic');
appIcon.setContextMenu(contextMenu);
ipcMain.on('hideapp', function(e) {
mainWindow.hide();
e.sender.send('hided');
});
ipcMain.on('minimize', function(e) {
mainWindow.minimize();
e.sender.send('minimize');
});
ipcMain.on('maximize', function(e) {
if (mainWindow.isMaximized()) {
mainWindow.unmaximize();
} else {
mainWindow.maximize();
}
e.sender.send('maximize');
});
}
app.on('ready', createWindow);
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', function () {
if (mainWindow === null) {
createWindow();
}
});
ipcMain.on('removecookie', function(e, url, name) {
var session = electron.session.fromPartition();
session.cookies.remove(url, name, function() {
console.log('remove', url, name);
e.returnValue = 'OK';
});
});