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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sing! Sync API functionality Should fix #66 Fixes #64 Fixes refresh bug
1 parent
fe88d06
commit 87504e8
Showing
31 changed files
with
1,855 additions
and
1,281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,10 @@ | |
* @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...'); | ||
|
@@ -21,43 +17,8 @@ App = (function(){ | |
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 | ||
} | ||
require('./defaults.json') | ||
); | ||
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); | ||
|
@@ -71,9 +32,19 @@ App = (function(){ | |
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(); | ||
this.settings.open((err, data) => { | ||
if(err){ | ||
console.log("The settings are corrupt, cannot continue."); | ||
process.exit(-1); | ||
} | ||
var Spotify = require('./windows/spotify/window'); | ||
_spotify = new Spotify(); | ||
}); | ||
}); | ||
this.setApplicationMenu = app.setApplicationMenu; | ||
this.quit = app.quit; | ||
this.openLink = electron.shell.openExternal; | ||
this.setLoginItemSettings = app.setLoginItemSettings; | ||
app.on('quit', () => { | ||
console.log('Exiting...'); | ||
}); | ||
|
@@ -98,7 +69,7 @@ App = (function(){ | |
_spotify.unmaximize(); | ||
}); | ||
} | ||
get VERSION(){ | ||
get version(){ | ||
return electron.app.getVersion(); | ||
} | ||
static get names(){ | ||
|
@@ -108,32 +79,14 @@ App = (function(){ | |
project: 'Spotify Web Player for Linux' | ||
} | ||
} | ||
get request(){ | ||
return request; | ||
} | ||
get names(){ | ||
return App.names; | ||
} | ||
static get HOST(){ | ||
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; | ||
get host(){ | ||
return App.host; | ||
} | ||
static get paths(){ | ||
var USER_PATH = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME']; | ||
|
@@ -185,35 +138,16 @@ App = (function(){ | |
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; | ||
} | ||
clearCache(){ | ||
_spotify.loadURL("about:blank"); | ||
_spotify.webContents.session.clearCache(() => { | ||
_spotify.webContents.session.clearStorageData(() => { | ||
console.log("Cleared session and cache."); | ||
_spotify.loadURL(this.HOST); | ||
}); | ||
}); | ||
} | ||
} | ||
return App; | ||
})(); | ||
const APP = new App(); | ||
global.props = APP; | ||
global.app = APP; | ||
process.on('SIGINT', () => { | ||
console.log('Received SIGINT (Ctrl-C). Exiting...'); | ||
app.quit(); | ||
process.exit(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"CloseToTray":true, | ||
"CloseToController":false, | ||
"ShowApplicationMenu":true, | ||
"ShowTray":true, | ||
"TrayIcon":"lime", | ||
"Notifications": { | ||
"ShowTrackChange":true, | ||
"ShowPlaybackPlaying":true, | ||
"ShowPlaybackPaused":true, | ||
"ShowPlaybackStopped":true, | ||
"OnlyWhenFocused":false | ||
}, | ||
"NavBar": { | ||
"Follow":true, | ||
"User":true, | ||
"Radio":true, | ||
"YourMusic":true, | ||
"Browse":true, | ||
"Settings":true, | ||
"Search":true, | ||
"Sing":true | ||
}, | ||
"AlbumArtSize": "large", | ||
"AlbumCacheDisabled":false, | ||
"Theme":"dark", | ||
"StartOnLogin":false, | ||
"StartHidden":false, | ||
"lastURL":"" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,11 @@ | |
* @author Matthew James <[email protected]> | ||
* Preload script for about window | ||
*/ | ||
global.remote = require('electron').remote; | ||
let props = remote.getGlobal('props'); | ||
global.props = props; | ||
|
||
global.MAIN = require('electron').ipcRenderer | ||
document.onreadystatechange = function(){ | ||
window.$ = window.jQuery = require('../spotify/jquery'); | ||
interface = require('../spotify/interface'); | ||
|
||
$('#logo').attr('src', __dirname + '/Spotify_Logo_RGB_White.png'); | ||
$('#app_title_and_version').html(props.names.project + '<br>v' + props.electron.app.getVersion()); | ||
|
||
libraries = { | ||
'Support Homepage': 'https://github.com/Quacky2200/Spotify-Web-Player-for-Linux', | ||
|
@@ -23,7 +19,7 @@ document.onreadystatechange = function(){ | |
}; | ||
html = ''; | ||
function click(){ | ||
props.electron.shell.openExternal($(this).attr('href')); | ||
MAIN.send('message-for-Spotify', `:eval('app.openLink(\`${$(this).attr('href')}\`)')`); | ||
return false; | ||
} | ||
for (var library in libraries){ | ||
|
@@ -32,4 +28,4 @@ document.onreadystatechange = function(){ | |
$('#libraries').html(html); | ||
//For all clicks, open externally | ||
$('a').click(click); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const {globalShortcut, BrowserWindow} = require('electron'); | ||
function Shortcuts(){ | ||
this.toggle = (toggle) => { | ||
if (toggle){ | ||
var showdevtools = function(){ | ||
var win = BrowserWindow.getFocusedWindow(); | ||
if (!win.isDevToolsOpened()){ | ||
win.openDevTools() | ||
} else { | ||
win.closeDevTools(); | ||
} | ||
} | ||
globalShortcut.register('CommandOrControl+Shift+I', showdevtools); | ||
globalShortcut.register('F12', showdevtools); | ||
globalShortcut.register('CommandOrControl+W', () => { | ||
BrowserWindow.getFocusedWindow().close() | ||
}); | ||
} else { | ||
globalShortcut.unregisterAll(); | ||
} | ||
} | ||
} | ||
module.exports = new Shortcuts(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const {BrowserWindow, ipcMain} = require('electron'); | ||
const shortcuts = require('./shortcuts'); | ||
class About extends BrowserWindow{ | ||
constructor(){ | ||
var ABOUT_WIDTH = 600; | ||
var ABOUT_HEIGHT = 525; | ||
super({ | ||
title: 'About', | ||
icon: App.icon, | ||
width: ABOUT_WIDTH, | ||
height: ABOUT_HEIGHT, | ||
minWidth: ABOUT_WIDTH, | ||
minHeight: ABOUT_HEIGHT, | ||
maxWidth: ABOUT_WIDTH, | ||
maxHeight: ABOUT_HEIGHT, | ||
resizable: false, | ||
show: false, | ||
webPreferences: {preload:`${__dirname}/preload.js`} | ||
}); | ||
this.loadURL(`file://${__dirname}/about.html`); | ||
this.setMenu(null); | ||
this.webContents.once('dom-ready', () => { | ||
theme = require('../spotify/theme'); | ||
this.do(` | ||
$('#app_title_and_version').html('${app.names.project}<br>v${app.version}'); | ||
`); | ||
ipcMain.on('message-for-About', function(e, a) { | ||
console.log('ABOUT EVAL:', a); | ||
if (typeof(a) !== 'string') return; | ||
if (a.match(/(:eval)/)) return eval(a.slice(7, a.length - 2)); | ||
}) | ||
theme.refresh(); | ||
this.show(); | ||
}); | ||
this.on('focus', () => shortcuts.toggle(true)); | ||
this.on('blur', () => shortcuts.toggle(false)); | ||
} | ||
do(str){ | ||
this.webContents.executeJavaScript(str); | ||
} | ||
doFunc(variables, func) { | ||
var vars = ""; | ||
for (var curvar in variables){ | ||
if (variables.hasOwnProperty(curvar)) { | ||
if (typeof(variables[curvar]) == 'function') { | ||
vars += `var ${curvar} = ${variables[curvar].toString()};\n`; | ||
} else if (typeof(variables[curvar]) == 'object'){ | ||
vars += `var ${curvar} = ${JSON.stringify(variables[curvar])};\n`; | ||
} else if (typeof(variables[curvar]) == 'string'){ | ||
vars += `var ${curvar} = \`${variables[curvar]}\`;\n`; | ||
} else { | ||
vars += `var ${curvar} = ${variables[curvar]};\n`; //Numbers, bools? | ||
} | ||
} | ||
} | ||
vars += `\n(${func.toString()})();\n`; | ||
this.do(vars) | ||
} | ||
} | ||
module.exports = About; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const {BrowserWindow} = require('electron'); | ||
class FacebookPopup extends BrowserWindow{ | ||
constructor(name, url, session){ | ||
super({ | ||
title: name, | ||
minWidth: 550, | ||
minHeight: 280, | ||
width: 550, | ||
height: 280, | ||
show: true, | ||
icon: App.icon, | ||
session: session, | ||
webPreferences: { | ||
preload: `${__dirname}/facebook/preload.js`, | ||
nodeIntegration: false, | ||
plugins: true | ||
} | ||
}); | ||
this.loadURL(url); | ||
this.setMenu(null); | ||
if(app.settings.ShowDevTools) this.openDevTools(); | ||
} | ||
} | ||
module.exports = FacebookPopup; |
Oops, something went wrong.