-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
205 lines (176 loc) · 6.2 KB
/
index.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
var spawn = require('child_process').fork;
console.log(`Master ${process.pid} is running`);
const path = require('path');
const electron = require('electron');
const { app, BrowserWindow, ipcMain } = electron;
const { autoUpdater } = require('electron-updater');
const isDev = require('electron-is-dev');
const Discord = require('discord-rpc');
const clientId = '842784561317937162';
// Discord Rich Presence
var activityCache;
var setActivity = (args) => {
activityCache = args;
};
const rpc = new Discord.Client({ transport: 'ipc' });
rpc.login({ clientId }).then(() => {
rpc.setActivity({
details: 'Starting up...',
largeImageKey: 'logo',
largeImageText: 'Spin Music Player',
startTimestamp: Date.now(),
});
if (activityCache) {
rpc.setActivity(activityCache);
}
setActivity = (args) => {
rpc.setActivity(args);
};
});
var fsThread;
function generateFsThread() {
// deepcode ignore IndirectCommandInjection: Use the enviroment variable __dirname in this situation has been considerated safe
fsThread = spawn(path.join(__dirname, 'child.js'));
function disconnectHandler() {
fsThread.removeAllListeners();
fsThread.kill();
generateFsThread();
}
fsThread.on('disconnect', disconnectHandler);
fsThread.on('error', disconnectHandler);
fsThread.on('exit', disconnectHandler);
}
if (isDev) {
const log = require('electron-log');
log.transports.file.level = 'debug';
autoUpdater.logger = log;
require('electron-reload')(__dirname);
}
/* Chrome cast testing, (all tests complete sucefully! keeping this comment here be the base of chromecast support code)
const ChromecastAPI = require('chromecast-api')
const client = new ChromecastAPI()
client.on('device', function (device) {
console.log("ABOBORA!");
var mediaURL = 'https://www.youtube.com/watch?v=D0hQI6MW0jc';
device.play(mediaURL, function (err) {
if (!err) console.log('Playing in your chromecast')
})
})
*/
function createWindow () {
const win = new BrowserWindow({
width: 900,
height: 610,
transparent: true,
frame: false,
movable: true,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
},
icon: path.resolve(__dirname, 'src', 'assets', 'images','logo.png'),
title: 'Spin Music Player',
});
ipcMain.on('synchronous-message', (event, args) => {
if (args !== 'maximize') {return;}
if (win.isMaximized()) {
win.unmaximize();
event.returnValue = 'screen.events.maximize.contract';
} else {
win.maximize();
event.returnValue = 'screen.events.maximize.fullscreen';
}
});
ipcMain.on('minimize', ()=>{win.minimize();});
win.loadFile('./src/pages/splashScreen/index.html');
win.removeMenu();
win.setThumbarButtons([{
tooltip: 'previous',
icon: path.resolve(__dirname, 'src', 'assets', 'images','previousbutton.png'),
flags: ['disabled'],
click () { console.log('button0 clicked.'); }
}, {
tooltip: 'PlayPause',
icon: path.resolve(__dirname, 'src', 'assets', 'images','playbutton.png'),
// flags: ['disabled'],
click () {
win.webContents.send('spinmp.timeline.pausePlay');
}
}, {
tooltip: 'next',
icon: path.resolve(__dirname, 'src', 'assets', 'images','nextbutton.png'),
flags: ['disabled'],
click () { console.log('button2 clicked.'); }
}]);
win.webContents.on('before-input-event', (event, input) => {
if (input.control && input.shift && input.key.toLowerCase() === 'i') {
event.preventDefault();
win.webContents.toggleDevTools();
}
});
/* win.setOverlayIcon(path.resolve(__dirname, 'src', 'assets', 'images','previousbutton.png'), 'Description for overlay')
win.flashFrame(true)*/
var avaliableUpdate = false;
var canUpdate = false;
autoUpdater.on('checking-for-update', () => {
win.webContents.send('checkingforupdate');
setTimeout(() => {
if (!canUpdate) {
win.webContents.send('updatenotavailable');
}
}, 15000);
});
autoUpdater.on('update-available', () => {
canUpdate = true;
win.webContents.send('downloadprogress', 0 + '%');
});
// eslint-disable-next-line no-unused-vars
autoUpdater.on('download-progress', (progress, bytesPsecound, percent, total, transferred) => {
win.webContents.send('downloadprogress', percent.toString() + '%');
});
autoUpdater.on('update-downloaded', (updateInfo) => {
avaliableUpdate = true;
win.webContents.send('updatedownloaded', JSON.stringify(updateInfo));
});
ipcMain.on('installupdate', () => {
if (avaliableUpdate) {
autoUpdater.quitAndInstall(true, true);
} else {
win.webContents.send('updateerror', 'no update to install');
}
});
generateFsThread();
fsThread.on('message', (msg) => {
win.webContents.send(msg.action, JSON.stringify(msg.content));
});
ipcMain.on('SubProcess.Fs.ReadDirAsync', (event, dir) => {
fsThread.send({action: 'Fs.ReadDirAsync', content: dir});
});
}
app.whenReady().then(createWindow);
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
ipcMain.on('app_version', (event) => {
if (!isDev) {
autoUpdater.checkForUpdatesAndNotify();
setInterval(() => {
autoUpdater.checkForUpdatesAndNotify();
}, 780000); // 13 minutes
}
event.sender.send('app_version', { version: app.getVersion(), rootPath: __dirname });
});
ipcMain.on('spinmp.loading.Loaded', () => {
setActivity({
details: 'Idle',
largeImageKey: 'logo',
state: `${rpc.user.username} is searching his files, or just AFK`,
startTimestamp: Date.now(),
});
});
ipcMain.on('spinmp.setActivity', (event, data) => {
setActivity(data);
});