Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Commit

Permalink
Pre-release v1.0.40 Beta
Browse files Browse the repository at this point in the history
Sing! Sync API functionality
Should fix #66
Fixes #64
Fixes refresh bug
Quacky2200 committed Jan 24, 2017
1 parent fe88d06 commit 87504e8
Showing 31 changed files with 1,855 additions and 1,281 deletions.
112 changes: 23 additions & 89 deletions app.js
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);
});
30 changes: 30 additions & 0 deletions defaults.json
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":""
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "spotifywebplayer",
"productName": "Spotify Web Player for Linux",
"version": "1.0.35",
"version": "1.0.40",
"description": "An Electron wrapper of Spotify Web Player to increase desktop integration for a stable Spotify Player for Linux replacement",
"main": "main.js",
"postinstall": "install-app-deps",
12 changes: 4 additions & 8 deletions windows/about/preload.js
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);
};
};
23 changes: 23 additions & 0 deletions windows/about/shortcuts.js
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();
60 changes: 60 additions & 0 deletions windows/about/window.js
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;
6 changes: 3 additions & 3 deletions windows/facebook/preload.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const remote = require('electron').remote;
var props = remote.getGlobal('props');
var props = remote.getGlobal('app');
var popup = remote.getCurrentWindow();

//Thanks to http://stackoverflow.com/questions/12049620/how-to-get-get-variables-value-in-javascript
@@ -31,8 +31,8 @@ if(window.location.href.indexOf("oauth?") >= 0){
props.spotify.webContents.once('dom-ready', function(){
//Click the button again to make FB check the authentication with our newly created cookie
props.spotify.webContents.executeJavaScript("document.getElementById('fb-signup-btn').click();");
//Close the FB window, we don't need it anymore
//Close the FB window, we don't need it anymore
popup.close();
});
}
}
}
24 changes: 24 additions & 0 deletions windows/facebook/window.js
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;
Loading

0 comments on commit 87504e8

Please sign in to comment.