This repository has been archived by the owner on Oct 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
app.js
executable file
·210 lines (210 loc) · 5.52 KB
/
app.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
206
207
208
209
210
/*
* @author Matthew James <[email protected]>
* App behaviour class
*/
const OS = require('os');
const FS = require('fs');
const request = require('request');
const electron = require('electron');
const BrowserWindow = electron.BrowserWindow;
const app = electron.app;
const sanitize = require('sanitize-filename')
const MXM = require('node-unofficialmxm');
//Let's load up our application
if(typeof(electron) != 'object' && !electron.app){
console.log('The Electron installation cannot be found. Aborting...');
process.exit(-1);
}
App = (function(){
let _spotify;
class App {
constructor(){
this.settings = require('./app-settings')(
`${App.paths.home}/preferences.json`,
{
CloseToTray: true,
CloseToController: false,
ShowApplicationMenu: true,
ShowTray: true,
TrayIcon: 'lime',
Notifications: {
ShowTrackChange: true,
ShowPlaybackPlaying: true,
ShowPlaybackPaused: true,
ShowPlaybackStopped: true,
OnlyWhenFocused: true
},
NavBar: {
Follow: true,
User: true,
Radio: true,
YourMusic: true,
Browse: true,
Settings: true,
Search: true,
Sing: true
},
AlbumCacheDisabled: false,
Theme: 'dark',
StartOnLogin: false,
StartHidden: false,
lastURL: null
}
);
this.settings.open((err, data) => {
if(err){
console.log("The settings are corrupt, cannot continue.");
process.exit(-1);
}
});
this.dbus = require('./dbus')(App.names.process);
require('./plugins')(app);
//Set Cache
app.setPath('userData', App.paths.home);
app.setPath('userCache', `${App.paths.home}/Cache`);
//Some fonts and images are not always served over HTTPS -_-
app.commandLine.appendSwitch('--allow-running-insecure-content');
app.commandLine.appendSwitch('--ignore-certificate-errors');
//Set the name of the application
app.setName(App.names.process);
//Set the process name
process.title = App.names.process;
//When Electron has loaded, start opening the window.
app.on('ready', () => {
var Spotify = require('./windows/windows')(this, electron, BrowserWindow);
_spotify = new Spotify();
});
app.on('quit', () => {
console.log('Exiting...');
});
//Make sure we only run one instance of the application
var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) {
// Someone tried to run a second instance, we should focus our window.
if (_spotify) {
if (_spotify.isMinimized()) _spotify.restore();
_spotify.show();
_spotify.focus();
}
});
//Quit if we're trying to run another instance
if (shouldQuit) {
console.log('An instance is already running, exiting...');
app.quit();
return;
}
//Let's support OS X anyways.
app.on('activate', function () {
_spotify.show();
_spotify.unmaximize();
});
}
get VERSION(){
return electron.app.getVersion();
}
static get names(){
return {
process: 'spotifywebplayer',
service: 'Spotify Web Player',
project: 'Spotify Web Player for Linux'
}
}
get request(){
return request;
}
get names(){
return App.names;
}
static get HOST(){
return 'https://play.spotify.com';
}
get HOST(){
return App.HOST;
}
get electron(){
return electron;
}
get globalShortcut(){
return electron.globalShortcut;
}
get mxm(){
return MXM;
}
get process(){
return process;
}
get console(){
return console;
}
static get paths(){
var USER_PATH = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
var HOME_PATH = `${USER_PATH}/.spotifywebplayer`;
return {
user: USER_PATH,
home: HOME_PATH,
caches: {
lyrics: `${HOME_PATH}/LyricCache`,
albums: `${HOME_PATH}/AlbumCache`
},
icons: `${__dirname}/icons`,
themes: `${__dirname}/windows/spotify/themes`
}
}
get paths(){
return App.paths;
}
sanitizeFilename(filename){
return sanitize(filename);
}
getFilesInDir(filepath){
return FS.readdirSync(filepath);
}
checkPathExists(path, cb){
FS.access(path, FS.constants.R_OK || FS.constants.W_OK || FS.constants.F_OK, (err) => cb(err));
}
getUTF8File(filename, cb){
FS.readFile(filename, {encoding: 'utf-8'}, (err, data) => cb(err, data));
}
createUTF8File(filename, text, cb){
FS.writeFile(filename, text, {encoding: 'utf-8'}, (err) => cb(err));
}
createFile(filename, data, type, cb){
FS.writeFile(filename, data, type, (err) => cb(err));
}
readFile(filename, type, cb){
FS.readFile(filename, type, (err, data) => cb(err, data));
}
getImageFileAsBase64(filename, cb){
FS.readFile(filename, {encoding: 'base64'}, (err, data) => cb(err, data));
}
createDirectory(filepath, cb){
FS.mkdir(filepath, (err) => cb(err));
}
static get icon(){
return `${App.paths.icons}/spotify.png`;
}
get icon(){
return App.icon;
}
get os(){
return OS;
}
static get HOSTNAME(){
return os.hostname();
}
get HOSTNAME(){
return App.HOSTNAME;
}
static get FILEPATH(){
process.cwd();
}
get FILEPATH(){
App.FILEPATH;
}
get spotify(){
return _spotify;
}
}
return App;
})();
const APP = new App();
global.props = APP;