From d3587fc8cb366d5b923f44d4b1ef7ecd8621d21b Mon Sep 17 00:00:00 2001 From: Matthew James Date: Sat, 14 Jan 2017 20:08:34 +0000 Subject: [PATCH] Indentation Fixes --- app.js | 104 +++---- dbus.js | 15 +- main.js | 18 +- windows/about/about.html | 18 +- windows/about/preload.js | 3 +- windows/facebook/preload.js | 52 ++-- windows/preferences/preferences.html | 118 +++---- windows/preferences/preload.js | 25 +- windows/spotify/base-theme.css | 16 +- windows/spotify/controller.js | 18 +- windows/spotify/interface.js | 22 +- windows/spotify/preload.js | 288 ++++++++--------- windows/spotify/shortcut-bar.js | 42 +-- windows/spotify/tray.js | 34 +- windows/spotify/user.js | 12 +- windows/windows.js | 450 +++++++++++++-------------- 16 files changed, 609 insertions(+), 626 deletions(-) diff --git a/app.js b/app.js index 7b4cca6..ba962cf 100755 --- a/app.js +++ b/app.js @@ -20,42 +20,42 @@ App = (function(){ 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){ + `${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); @@ -75,27 +75,27 @@ App = (function(){ _spotify = new Spotify(); }); app.on('quit', () => { - console.log('Exiting...'); + 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(); - } + // 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; + 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(); + _spotify.show(); + _spotify.unmaximize(); }); } get VERSION(){ @@ -205,12 +205,12 @@ App = (function(){ } clearCache(){ _spotify.loadURL("about:blank"); - _spotify.webContents.session.clearCache(() => { - _spotify.webContents.session.clearStorageData(() => { - console.log("Cleared session and cache."); - _spotify.loadURL(this.HOST); - }); - }); + _spotify.webContents.session.clearCache(() => { + _spotify.webContents.session.clearStorageData(() => { + console.log("Cleared session and cache."); + _spotify.loadURL(this.HOST); + }); + }); } } return App; diff --git a/dbus.js b/dbus.js index 8e8c828..4413578 100644 --- a/dbus.js +++ b/dbus.js @@ -17,12 +17,9 @@ module.exports = function(appName){ class DBusMediaKeys extends EventEmitter{ constructor(bus){ super(); - bus.getInterface('org.gnome.SettingsDaemon', '/org/gnome/SettingsDaemon/MediaKeys', 'org.gnome.SettingsDaemon.MediaKeys', (err, iface) => { if(err) return console.log(err); - iface.on('MediaPlayerKeyPressed', (n, value) => { - this.emit(value); - }); + iface.on('MediaPlayerKeyPressed', (n, value) => this.emit(value)); iface.GrabMediaPlayerKeys(0, 'org.gnome.SettingsDaemon.MediaKeys'); }); } @@ -31,11 +28,11 @@ module.exports = function(appName){ constructor(appName) { super(); this._player = Player({ - name: appName, - identity: appName, - supportedUriSchemes: ['http'], - supportedMimeTypes: ['application/www-url'], - desktopEntry: appName + name: appName, + identity: appName, + supportedUriSchemes: ['http'], + supportedMimeTypes: ['application/www-url'], + desktopEntry: appName }); } on(name, func){ diff --git a/main.js b/main.js index d66b202..dd00ea6 100755 --- a/main.js +++ b/main.js @@ -7,20 +7,20 @@ if (typeof electron == 'string'){ console.log(`Starting up app with Electron found at "${electron}"`); ls.stdout.on('data', function(data) { - console.log(data.toString()); - }); + console.log(data.toString()); + }); - ls.stderr.on('data', function(data) { - console.log(data.toString()); + ls.stderr.on('data', function(data) { + console.log(data.toString()); }); - ls.on('close', function(code) { - console.log(`child process exited with code ${code}`); - }); + ls.on('close', function(code) { + console.log(`child process exited with code ${code}`); + }); //process.exit(0); } else if (typeof electron == 'object' && electron.app){ require('./app'); } else { - console.log('Cannot start up. Exiting...'); + console.log('Cannot start up. Exiting...'); process.exit(-1); -} +} \ No newline at end of file diff --git a/windows/about/about.html b/windows/about/about.html index 096d193..46b2547 100755 --- a/windows/about/about.html +++ b/windows/about/about.html @@ -2,17 +2,17 @@ - -

Spotify Web Player for Linux

-
+ +

Spotify Web Player for Linux

+
\ No newline at end of file diff --git a/windows/about/preload.js b/windows/about/preload.js index 3270ab2..408f9cc 100755 --- a/windows/about/preload.js +++ b/windows/about/preload.js @@ -32,5 +32,4 @@ document.onreadystatechange = function(){ $('#libraries').html(html); //For all clicks, open externally $('a').click(click); -}; - +}; \ No newline at end of file diff --git a/windows/facebook/preload.js b/windows/facebook/preload.js index af8704d..a28f9da 100755 --- a/windows/facebook/preload.js +++ b/windows/facebook/preload.js @@ -5,34 +5,34 @@ var popup = remote.getCurrentWindow(); //Thanks to http://stackoverflow.com/questions/12049620/how-to-get-get-variables-value-in-javascript var uriQuery = {}; if(document.location.toString().indexOf('?') !== -1) { - var query = document.location - .toString() - // get the query string - .replace(/^.*?\?/, '') - // and remove any existing hash string (thanks, @vrijdenker) - .replace(/#.*$/, '') - .split('&'); + var query = document.location + .toString() + // get the query string + .replace(/^.*?\?/, '') + // and remove any existing hash string (thanks, @vrijdenker) + .replace(/#.*$/, '') + .split('&'); - for(var i=0, l=query.length; i= 0){ - if(!!uriQuery.app_id){ - //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 - popup.close(); - } else if (!!uriQuery.redirect_uri){ - popup.hide(); - props.spotify.loadURL(props.HOST + '/?'); - 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 - popup.close(); - }); - } + if(!!uriQuery.app_id){ + //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 + popup.close(); + } else if (!!uriQuery.redirect_uri){ + popup.hide(); + props.spotify.loadURL(props.HOST + '/?'); + 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 + popup.close(); + }); + } } \ No newline at end of file diff --git a/windows/preferences/preferences.html b/windows/preferences/preferences.html index b01cfd7..8f3c0cc 100755 --- a/windows/preferences/preferences.html +++ b/windows/preferences/preferences.html @@ -2,65 +2,65 @@ diff --git a/windows/preferences/preload.js b/windows/preferences/preload.js index e70f34f..37a16b5 100755 --- a/windows/preferences/preload.js +++ b/windows/preferences/preload.js @@ -14,17 +14,17 @@ let autolaunch = new AutoLaunch({ global.props = props; var deleteFolderRecursive = function(path) { - if( fs.existsSync(path) ) { - fs.readdirSync(path).forEach(function(file,index){ - var curPath = path + "/" + file; - if(fs.lstatSync(curPath).isDirectory()) { // recurse - deleteFolderRecursive(curPath); - } else { // delete file - fs.unlinkSync(curPath); - } - }); - fs.rmdirSync(path); - } + if( fs.existsSync(path) ) { + fs.readdirSync(path).forEach(function(file,index){ + var curPath = path + "/" + file; + if(fs.lstatSync(curPath).isDirectory()) { // recurse + deleteFolderRecursive(curPath); + } else { // delete file + fs.unlinkSync(curPath); + } + }); + fs.rmdirSync(path); + } }; document.onreadystatechange = function(){ if (document.readyState !== 'complete') return; @@ -105,5 +105,4 @@ document.onreadystatechange = function(){ deleteFolderRecursive(props.lyricCache); }); interface.refresh(); -}; - +}; \ No newline at end of file diff --git a/windows/spotify/base-theme.css b/windows/spotify/base-theme.css index 4e400a3..04a94c6 100755 --- a/windows/spotify/base-theme.css +++ b/windows/spotify/base-theme.css @@ -1,25 +1,13 @@ #notification-area{display:none;} - #cookie-compliance{display:none !important;} #header #appName{height: 0;overflow: hidden;display:none !important;} #now-playing-widgets{display:none !important;} .etched-top::before{background-color:#343434 !important;} html, body{width: 100%;height:100%;border:0 !important;margin:0;padding:0;} .ads-leaderboard-container{display:none !important;} -/*#window_advert{position: fixed; display:none;height:100%;width:100%;background:rgba(0,0,0,0.75);z-index:10000} -:not(#advert) > #hpto-container{display:none;} -#window_advert_container{display:table;position:relative;width:100%;height:100%} -#advert_container{display:table-cell;vertical-align:middle;text-align:center} -#advert{position:relative;text-align:right;display:inline-block;border-radius:10px;overflow:hidden;min-height:240px;min-width: 800px;max-width: 75%;} -#advert a, #advert a:hover, #advert a:active, #advert a:visited{display:block;position:absolute;width:100%;height:100%;left:0;top:0;border:none;text-decoration: none} -#advert #hpto-container .hpto-button{background:rgba(0,0,0,0.75);padding:5px;display:inline-block;border-radius:5px;margin:10px;} -#advert #hpto-container{position:relative;display: inline-block; width: 900px;height: 270px;background-size: cover;} -#window_advert #advert #hpto-container iframe {background-color: none !important} -*/ div.upperLeft{position: initial !important;height: auto !important;left: initial !important;right: initial !important;} div.section-divider{margin-top: 25px !important ;} -#hpto-container{animation: advertisementSlide 1s; animation-delay: 2s; animation-timing-function: linear; transform-origin: center top;} - +#hpto-container{animation: advertisementSlide 1s; animation-timing-function: linear; transform-origin: center top;} @keyframes advertisementSlide{ from {transform: scale(1, 0);} to {transform:scale(1,1);} @@ -29,4 +17,4 @@ div.section-divider{margin-top: 25px !important ;} #infobar table tr {} #infobar table tr td {text-align: center} #infobar table tr td a {border: none !important} -#infobar table tr td a.fullscreen img{transform: rotate(90deg);} +#infobar table tr td a.fullscreen img{transform: rotate(90deg);} \ No newline at end of file diff --git a/windows/spotify/controller.js b/windows/spotify/controller.js index 6c6963b..ad9330f 100755 --- a/windows/spotify/controller.js +++ b/windows/spotify/controller.js @@ -213,15 +213,15 @@ module.exports = (function() { var album = this.track.album.match(/(?:(?! [^\w]).)*/)[0]; var file = (this.track.art ? `${filepath}/${props.sanitizeFilename(album)}.jpeg` : process.cwd() + '/icons/spotify.png'); props.checkPathExists(file, (err) => { - if (err) return props.request(this.track.art, {encoding: 'binary'}, (error, response, body) => { - if(error) return cb(err);//console.log(error); - props.createFile(file, body, 'binary', (err) => { - if (err) return cb(err);//console.log(err); - cb(null, file); - }); + if (err) return props.request(this.track.art, {encoding: 'binary'}, (error, response, body) => { + if(error) return cb(err);//console.log(error); + props.createFile(file, body, 'binary', (err) => { + if (err) return cb(err);//console.log(err); + cb(null, file); + }); }); - cb(null, file); - }); + cb(null, file); + }); } if (!this.albumCacheDisabled) props.checkPathExists(filepath, (err) => { if (err) return props.createDirectory(filepath, (err) => { @@ -250,4 +250,4 @@ module.exports = (function() { } } return Controller; -})(); +})(); \ No newline at end of file diff --git a/windows/spotify/interface.js b/windows/spotify/interface.js index a86797b..c4c21d4 100755 --- a/windows/spotify/interface.js +++ b/windows/spotify/interface.js @@ -15,13 +15,13 @@ module.exports = (function() { const ALL_IFRAMES = "div[id*='section-'] iframe[id*='app-spotify:'], #app-player, #context-actions"; //Reduce the prevelence of advertisements let tameAdvertisements = function(){ - var frames = $('.root iframe') + var frames = $('.root iframe'); for (var i = 0; i < frames.length; i++) { var frame = $(frames[i]).contents(); var advertContainer = "#header.container,.hpto-container" var potentialAdvert = $(advertContainer, frame); if ($(potentialAdvert).has("#hpto") && $(`body > *:last-child:not(${advertContainer})`, frame).length == 1){ - //Place the advert onto the bottom if it's at the top + //Place the advert onto the bottom if it's at the top var advert = potentialAdvert.detach(); advert.appendTo($('body', frame)); } @@ -42,7 +42,7 @@ module.exports = (function() { //Load the base theme props.getUTF8File(`${__dirname}/base-theme.css`, (err, data) => { if (err) return console.error(err); - CURRENT_THEME.BASETHEME_CACHE = `/* Base Theming */\n${data}`; + CURRENT_THEME.BASETHEME_CACHE = `/* Base Theming */\n${data}`; }) //Load current theme into cache loadTheme(props.settings.Theme, (err) => { @@ -110,16 +110,16 @@ module.exports = (function() { tameAdvertisements(); var interfaceClass = 'controlbot'; CSS = ``; - $('body').prepend(CSS); - $('body', $(ALL_IFRAMES).contents()).prepend(CSS); - $('style.controlbot:not(:first-child)', $(ALL_IFRAMES).contents()).remove(); + $('body').prepend(CSS); + $('body', $(ALL_IFRAMES).contents()).prepend(CSS); + $('style.controlbot:not(:first-child)', $(ALL_IFRAMES).contents()).remove(); $('style.controlbot:not(:first-child)').remove(); - //Always make sure sing button is at the bottom - $('li').has('#nav-sing').appendTo('#nav-items'); - //Hide the ugly flash player box - $('#core object').height(0).width(0); + //Always make sure sing button is at the bottom + $('li').has('#nav-sing').appendTo('#nav-items'); + //Hide the ugly flash player box + $('#core object').height(0).width(0); } } } return new Interface(); -})(); +})(); \ No newline at end of file diff --git a/windows/spotify/preload.js b/windows/spotify/preload.js index 42e66b2..9499479 100644 --- a/windows/spotify/preload.js +++ b/windows/spotify/preload.js @@ -10,156 +10,156 @@ window.require = require; window._loaded = false; //If the window is a pop-up window if (window.opener){ - var popupWindow = remote.getCurrentWindow(); - //Set our default properties for the popup window and escape. - popupWindow.setSize(800, 600); - popupWindow.setMenu(null); - popupWindow.show(); - return; + var popupWindow = remote.getCurrentWindow(); + //Set our default properties for the popup window and escape. + popupWindow.setSize(800, 600); + popupWindow.setMenu(null); + popupWindow.show(); + return; } /* * Make sure to run everything when we are ready */ document.onreadystatechange = function(){ - window.props = remote.getGlobal('props'); - window.$ = window.jQuery = require('./jquery'); - window.interface = require('./interface'); - if (_loaded) return; - //Load our theming - interface.refresh(); - /* - * Check for any updates and show an update button when one is available - */ - function checkForUpdates(){ - $.getJSON("https://api.github.com/repos/Quacky2200/Spotify-Web-Player-for-Linux/releases", (data) => { - var updateAvailable = (() => { - var version_update_tag = data[0].tag_name.match(/([0-9\.]+)/)[1].split('.'); - var version_now_tag = props.electron.app.getVersion().match(/([0-9\.]+)/)[1].split('.'); - for(var num in version_update_tag){ - if(parseInt(version_update_tag[num]) > parseInt(version_now_tag[num])) { - return true; - } else if (parseInt(version_update_tag[num]) < parseInt(version_now_tag[num])){ - return false - } - } - })(); - if(updateAvailable){ - var updateAvailableButtonIcon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAMAAABrrFhUAAAA21BMVEX///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////8AAABm7yWAAAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfgCRsAHhHuaRzgAAAD9ElEQVR42u2dvY7aQBhF50oUrqjcrKjpqFZCgnbe/6GiREqyq7AbsOf7m3vPA4DPsTFmZmxaE0IIIYQQQgghhBBCCCGEEEIIIYQI4oBPHBZa9Y8cmeUJIqx4lhnt3/ASp8n0sQFy/YkSYAcT6J+xD+bdP8HpEENg9wdWbv2qBwHAXQCDOdfSv2A8TF/+1QvACHb/KgUA7gIAd4EjuAu8A9wFzP3TXBFdrp+G9d38MxwCX47uLsD0BW5IQJj9HTlYZz2/pT4EkApyffeRUuSDXN+1ALgDIC3s/mD39yhwB3eAFaAuAHAHyO//ZxCC1d/0EFjJA9wB7gIgDwDyAGX8jdYVoxAKQO4Pdn+Lk0CtAGD3VwB2fwVYyP1HjwnUCwB2fwVgHAYxCwAF4A5wYw/gs0EKoABZA6zsAaAAFQMc2AM0BRjFpWaAy7AA16InQST7BPgHGLV4vm6AQQdB5QBDFo+XDjDiICgeAPQBQB9g74mgfgBc2QPs+Bic/bYh4Qjhu+smpBsjPTlvgXGAV+8tX913gfUw+Us/D28Bx2CmiYKQ988zVRL09mkmizBvAATqVwmAuQOEbkSOOfjEl+PxAToIAiDMP0uAc5R/lgBfbccClgDIeiEaGwBEAZD0KiwyALgCwGoCvGwAsAW4JLsE81+PG7IQNm0AEAZY81yABS1JV4Ac119xAQ7sAWDwrm/NlJ4+AHohf5gcdr2O/++TAIoU6EYngeGv28v4w+jE26v4WwWwKGAzXPvzlU3uiO01/GF36dFL+P/6GkCBAnbTFYYXn72CPyz/9qUX8Ifpr4+e3982wJgCttOVxr8/e3Z/6wD7C5hP11u/Qc/tD/sH5PbU/nAYguqZ/T0CbC/g4O8SYGsBD3+fANsKuPg7BdhSwMffK8DrBZz8D24TET2lPxa/mZie0R+eU1E9ob9rgOcL+Pn7Bni2gKO/c4DnCnj6H8c9HGVYAU9/uK0OfL6Aq7/htMDWAr7+EQG+L+Dsf4wI8F0BZ3+zqdGtBbz9YXSD+NYC7v5oQYfA4wJR/iGPC+4Z/CMD/FsgwP/kvE782wIB/ghanPmwQIR/dICPBWL9wx6b30P9Q9bKPy4Q7h/33Pwe5x9zv8yjAhn8A/86oQf5o2UpkMOfLsCpkRdo5AHib1aKZWUPkOF+tXz+PAUaeYBzIy+Q57bVfP4MBf4zM3kn9w+ZJUnlP/mHIPRhqlX8Jy4Q+Djt5Nc/FN8FLy7UZfefrcCW/5qi3v1zJThuvmOJevfPkmD3favk+rUTDHt6QUn7UxvJnXbn+z9xM/Jrb4JfSYbyf58+fE2pfliaEEIIIYQQQgghhBBCCCGEEEIIIcRjfgDj86cKVDgsEwAAAABJRU5ErkJggg=='; - button = ` -
  • - - - Update - -
  • - - `; - $('#main-nav #nav-items').append(button); - $('#nav-update').click(function(){ - props.electron.shell.openExternal($(this).attr('data-href')); - }); - } - }); - } - /* - * Handler for JSON messages from Spotify - */ - function onMessage(e){ - if(!(typeof e.data == 'string')) return - if (e.data.indexOf('USER_ACTIVE') > 0 || e.data.indexOf("spb-connected") > 0){ - //Whenever the user is active (or when the whole interface is loaded) - var loggedIn = user.isLoggedIn(); - //Try to prevent the window from moving away now that we're logged in - windowHook = loggedIn; - //Make sure to optionally show the Spotify tray icon - tray.toggleTray(loggedIn && props.settings.ShowTray); - //Make sure to optionally show the application menu - appMenu.toggleMenu(loggedIn && props.settings.ShowApplicationMenu); - //Make sure to set persistence - if (props.settings.lastURL !== window.location.href){ - props.settings.lastURL = window.location.href; - props.settings.save(); - } - } else if (e.data.indexOf("user:impression") > 0){ - if(e.data.indexOf('player_loaded') > -1) { - require('./shortcut-bar'); - var Controller = require('./controller'); - window.controller = new Controller(document.getElementById('app-player')); - var isFocusWorthy = () => { - return (props.settings.Notifications.OnlyWhenFocused ? !props.spotify.isFocused() : true); - }; - controller.albumCache = props.paths.caches.albums; - controller.albumCacheDisabled = props.settings.AlbumCacheDisabled; + window.props = remote.getGlobal('props'); + window.$ = window.jQuery = require('./jquery'); + window.interface = require('./interface'); + if (_loaded) return; + //Load our theming + interface.refresh(); + /* + * Check for any updates and show an update button when one is available + */ + function checkForUpdates(){ + $.getJSON("https://api.github.com/repos/Quacky2200/Spotify-Web-Player-for-Linux/releases", (data) => { + var updateAvailable = (() => { + var version_update_tag = data[0].tag_name.match(/([0-9\.]+)/)[1].split('.'); + var version_now_tag = props.electron.app.getVersion().match(/([0-9\.]+)/)[1].split('.'); + for(var num in version_update_tag){ + if(parseInt(version_update_tag[num]) > parseInt(version_now_tag[num])) { + return true; + } else if (parseInt(version_update_tag[num]) < parseInt(version_now_tag[num])){ + return false + } + } + })(); + if(updateAvailable){ + var updateAvailableButtonIcon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAMAAABrrFhUAAAA21BMVEX///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////8AAABm7yWAAAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfgCRsAHhHuaRzgAAAD9ElEQVR42u2dvY7aQBhF50oUrqjcrKjpqFZCgnbe/6GiREqyq7AbsOf7m3vPA4DPsTFmZmxaE0IIIYQQQgghhBBCCCGEEEIIIYQI4oBPHBZa9Y8cmeUJIqx4lhnt3/ASp8n0sQFy/YkSYAcT6J+xD+bdP8HpEENg9wdWbv2qBwHAXQCDOdfSv2A8TF/+1QvACHb/KgUA7gIAd4EjuAu8A9wFzP3TXBFdrp+G9d38MxwCX47uLsD0BW5IQJj9HTlYZz2/pT4EkApyffeRUuSDXN+1ALgDIC3s/mD39yhwB3eAFaAuAHAHyO//ZxCC1d/0EFjJA9wB7gIgDwDyAGX8jdYVoxAKQO4Pdn+Lk0CtAGD3VwB2fwVYyP1HjwnUCwB2fwVgHAYxCwAF4A5wYw/gs0EKoABZA6zsAaAAFQMc2AM0BRjFpWaAy7AA16InQST7BPgHGLV4vm6AQQdB5QBDFo+XDjDiICgeAPQBQB9g74mgfgBc2QPs+Bic/bYh4Qjhu+smpBsjPTlvgXGAV+8tX913gfUw+Us/D28Bx2CmiYKQ988zVRL09mkmizBvAATqVwmAuQOEbkSOOfjEl+PxAToIAiDMP0uAc5R/lgBfbccClgDIeiEaGwBEAZD0KiwyALgCwGoCvGwAsAW4JLsE81+PG7IQNm0AEAZY81yABS1JV4Ac119xAQ7sAWDwrm/NlJ4+AHohf5gcdr2O/++TAIoU6EYngeGv28v4w+jE26v4WwWwKGAzXPvzlU3uiO01/GF36dFL+P/6GkCBAnbTFYYXn72CPyz/9qUX8Ifpr4+e3982wJgCttOVxr8/e3Z/6wD7C5hP11u/Qc/tD/sH5PbU/nAYguqZ/T0CbC/g4O8SYGsBD3+fANsKuPg7BdhSwMffK8DrBZz8D24TET2lPxa/mZie0R+eU1E9ob9rgOcL+Pn7Bni2gKO/c4DnCnj6H8c9HGVYAU9/uK0OfL6Aq7/htMDWAr7+EQG+L+Dsf4wI8F0BZ3+zqdGtBbz9YXSD+NYC7v5oQYfA4wJR/iGPC+4Z/CMD/FsgwP/kvE782wIB/ghanPmwQIR/dICPBWL9wx6b30P9Q9bKPy4Q7h/33Pwe5x9zv8yjAhn8A/86oQf5o2UpkMOfLsCpkRdo5AHib1aKZWUPkOF+tXz+PAUaeYBzIy+Q57bVfP4MBf4zM3kn9w+ZJUnlP/mHIPRhqlX8Jy4Q+Djt5Nc/FN8FLy7UZfefrcCW/5qi3v1zJThuvmOJevfPkmD3favk+rUTDHt6QUn7UxvJnXbn+z9xM/Jrb4JfSYbyf58+fE2pfliaEEIIIYQQQgghhBBCCCGEEEIIIcRjfgDj86cKVDgsEwAAAABJRU5ErkJggg=='; + button = ` +
  • + + + Update + +
  • + + `; + $('#main-nav #nav-items').append(button); + $('#nav-update').click(function(){ + props.electron.shell.openExternal($(this).attr('data-href')); + }); + } + }); + } + /* + * Handler for JSON messages from Spotify + */ + function onMessage(e){ + if(!(typeof e.data == 'string')) return + if (e.data.indexOf('USER_ACTIVE') > 0 || e.data.indexOf("spb-connected") > 0){ + //Whenever the user is active (or when the whole interface is loaded) + var loggedIn = user.isLoggedIn(); + //Try to prevent the window from moving away now that we're logged in + windowHook = loggedIn; + //Make sure to optionally show the Spotify tray icon + tray.toggleTray(loggedIn && props.settings.ShowTray); + //Make sure to optionally show the application menu + appMenu.toggleMenu(loggedIn && props.settings.ShowApplicationMenu); + //Make sure to set persistence + if (props.settings.lastURL !== window.location.href){ + props.settings.lastURL = window.location.href; + props.settings.save(); + } + } else if (e.data.indexOf("user:impression") > 0){ + if(e.data.indexOf('player_loaded') > -1) { + require('./shortcut-bar'); + var Controller = require('./controller'); + window.controller = new Controller(document.getElementById('app-player')); + var isFocusWorthy = () => { + return (props.settings.Notifications.OnlyWhenFocused ? !props.spotify.isFocused() : true); + }; + controller.albumCache = props.paths.caches.albums; + controller.albumCacheDisabled = props.settings.AlbumCacheDisabled; - controller.on('Quit', () => { - tray.contextMenu.quit.click(); - }); + controller.on('Quit', () => { + tray.contextMenu.quit.click(); + }); - controller.on('Raise', () => { - props.spotify.show(); - props.spotify.focus(); - }); + controller.on('Raise', () => { + props.spotify.show(); + props.spotify.focus(); + }); - controller.on('trackChange', (controller) => { - sing.toggleButton(true); - interface.refresh(); - tray.toggleMediaButtons(controller.status !== 'Stopped'); - sing.load(controller.track.id, controller.track.name, controller.track.artists); - if(isFocusWorthy() && props.settings.Notifications.ShowTrackChange) controller.notify(); - }); + controller.on('trackChange', (controller) => { + sing.toggleButton(true); + interface.refresh(); + tray.toggleMediaButtons(controller.status !== 'Stopped'); + sing.load(controller.track.id, controller.track.name, controller.track.artists); + if(isFocusWorthy() && props.settings.Notifications.ShowTrackChange) controller.notify(); + }); - controller.on('playbackChange', (controller) => { - var notificationSwitchTable = { - Playing: props.settings.Notifications.ShowPlaybackPlaying, - Paused: props.settings.Notifications.ShowPlaybackPaused, - Stopped: props.settings.Notifications.ShowPlaybackStopped - }; - var isMediaSwitchable = controller.status != 'Stopped'; - if(isFocusWorthy() && notificationSwitchTable[controller.status]) controller.notify(); - sing.toggleButton(isMediaSwitchable); - sing.load(controller.track.id, controller.track.name, controller.track.artists); - tray.toggleMediaButtons(isMediaSwitchable); - controller.toggleGlobalMediaButtons(isMediaSwitchable); - }); - } - interface.refresh(); - } - } - //Make sure we don't get stuck when we cannot connect to Spotify - setInterval(() => { - if($('#modal-notification-area').is(':visible')) { - windowHook = false; - window.location.reload(); - } - }, 10000); - /** - * When the window closes, hide or close depending on preferred behaviour - */ - window.onbeforeunload = function(e) { - var alreadyHidden = props.spotify.isVisible() && !props.spotify.isMinimized(); - if(windowHook && alreadyHidden && ((props.settings.CloseToTray && props.settings.ShowTray) || props.settings.CloseToController)){ - props.spotify.hide(); - return false; - } else if (windowHook && alreadyHidden && props.settings.CloseToTray && !props.settings.ShowTray){ - props.spotify.minimize(); - return false; - } - controller.dispose(); - appMenu.toggleMenu(false); - tray.toggleTray(false); - }; - window.user = require('./user'); - window.tray = require('./tray'); - window.sing = require('./Sing!/sing'); - window.appMenu = require('./window-menu'); - //Check for message events from Spotify - window.addEventListener('message', onMessage); - checkForUpdates(); - //Check for updates every 6 hours (1/4 day) - setInterval(checkForUpdates, 2.16e+7); - _loaded = true; -} + controller.on('playbackChange', (controller) => { + var notificationSwitchTable = { + Playing: props.settings.Notifications.ShowPlaybackPlaying, + Paused: props.settings.Notifications.ShowPlaybackPaused, + Stopped: props.settings.Notifications.ShowPlaybackStopped + }; + var isMediaSwitchable = controller.status != 'Stopped'; + if(isFocusWorthy() && notificationSwitchTable[controller.status]) controller.notify(); + sing.toggleButton(isMediaSwitchable); + sing.load(controller.track.id, controller.track.name, controller.track.artists); + tray.toggleMediaButtons(isMediaSwitchable); + controller.toggleGlobalMediaButtons(isMediaSwitchable); + }); + } + interface.refresh(); + } + } + //Make sure we don't get stuck when we cannot connect to Spotify + setInterval(() => { + if($('#modal-notification-area').is(':visible')) { + windowHook = false; + window.location.reload(); + } + }, 10000); + /** + * When the window closes, hide or close depending on preferred behaviour + */ + window.onbeforeunload = function(e) { + var alreadyHidden = props.spotify.isVisible() && !props.spotify.isMinimized(); + if(windowHook && alreadyHidden && ((props.settings.CloseToTray && props.settings.ShowTray) || props.settings.CloseToController)){ + props.spotify.hide(); + return false; + } else if (windowHook && alreadyHidden && props.settings.CloseToTray && !props.settings.ShowTray){ + props.spotify.minimize(); + return false; + } + controller.dispose(); + appMenu.toggleMenu(false); + tray.toggleTray(false); + }; + window.user = require('./user'); + window.tray = require('./tray'); + window.sing = require('./Sing!/sing'); + window.appMenu = require('./window-menu'); + //Check for message events from Spotify + window.addEventListener('message', onMessage); + checkForUpdates(); + //Check for updates every 6 hours (1/4 day) + setInterval(checkForUpdates, 2.16e+7); + _loaded = true; +} \ No newline at end of file diff --git a/windows/spotify/shortcut-bar.js b/windows/spotify/shortcut-bar.js index 115da63..0bea042 100644 --- a/windows/spotify/shortcut-bar.js +++ b/windows/spotify/shortcut-bar.js @@ -8,33 +8,33 @@ var fullscreenButtonIcon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAA var exitButtonIcon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAAARVBMVEUAAACZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZkBVNYgAAAAFnRSTlMAAQMECQ8QGR4iJCw8RF+RqKvKzODmqz18nwAAAF1JREFUGFdlz9kSgCAIQFHIwnZb+f9PbUhLlPvknAdAYBXEmDePby4TcyB5oSbm3tIYqasIPBytInTSfTaZ5nTHjobWchbBtZiNgz1C3zXVH/pKROEfnxOsSNBQ2QMFEwvTxy9znQAAAABJRU5ErkJggg=='; let appPreferencesButton = `
    - - - - - - - -
    - - - - - - - -
    + + + + + + + +
    + + + + + + + +
    `; $('body', $('#app-player').contents()).append(appPreferencesButton); $('.info.appbutton', $('#app-player').contents()).click(() => { - props.spotify.showAbout(); + props.spotify.showAbout(); }); $('.fullscreen.appbutton', $('#app-player').contents()).click(() => { - props.spotify.setFullScreen(!props.spotify.isFullScreen()) + props.spotify.setFullScreen(!props.spotify.isFullScreen()) }); $('.preferences.appbutton', $('#app-player').contents()).click(() => { - props.spotify.showPreferences(); + props.spotify.showPreferences(); }); $('.quit.appbutton', $('#app-player').contents()).click(() => { - tray.contextMenu.quit.click(); -}); + tray.contextMenu.quit.click(); +}); \ No newline at end of file diff --git a/windows/spotify/tray.js b/windows/spotify/tray.js index a84f82f..848060e 100755 --- a/windows/spotify/tray.js +++ b/windows/spotify/tray.js @@ -31,28 +31,28 @@ const tray = { appPreferences: {label: "App Preferences", click: function(){ props.spotify.showPreferences(); }}, - logout: {label: "Logout", click: function(){ - user.logout(); - }}, - quit: {label: "Quit", click:function(){ - tray.toggleTray(false); - appMenu.toggleMenu(false); + logout: {label: "Logout", click: function(){ + user.logout(); + }}, + quit: {label: "Quit", click:function(){ + tray.toggleTray(false); + appMenu.toggleMenu(false); windowHook = false; props.electron.app.quit(); - }} + }} }, toggleTray: function(toggle){ if (toggle && props.settings.ShowTray){ if (!tray.appIcon) tray.appIcon = new Tray(`${props.paths.icons}/spotify-ico-small-${props.settings.TrayIcon}.png`); tray.appIcon.setContextMenu(Menu.buildFromTemplate([ - tray.contextMenu.togglePlayback, - tray.contextMenu.previous, - tray.contextMenu.next, - {type:'separator'}, - tray.contextMenu.toggleSpotifyAppearance, - tray.contextMenu.appPreferences, - tray.contextMenu.logout, - tray.contextMenu.quit + tray.contextMenu.togglePlayback, + tray.contextMenu.previous, + tray.contextMenu.next, + {type:'separator'}, + tray.contextMenu.toggleSpotifyAppearance, + tray.contextMenu.appPreferences, + tray.contextMenu.logout, + tray.contextMenu.quit ])); tray.appIcon.on('click', () => { props.spotify.show(); @@ -60,7 +60,7 @@ const tray = { }); } else if (!toggle && tray.appIcon != null){ tray.appIcon.destroy(); - tray.appIcon = null; + tray.appIcon = null; } }, toggleMediaButtons: function(toggle){ @@ -76,4 +76,4 @@ document.addEventListener("visibilitychange", function(){ tray.contextMenu.toggleSpotifyAppearance.label = (props.spotify.isMinimized() || !props.spotify.isVisible() ? 'Show' : 'Hide') + ' Spotify'; tray.toggleTray(props.settings.ShowTray); }); -module.exports = tray; +module.exports = tray; \ No newline at end of file diff --git a/windows/spotify/user.js b/windows/spotify/user.js index d823b3e..fd169d7 100755 --- a/windows/spotify/user.js +++ b/windows/spotify/user.js @@ -33,13 +33,13 @@ module.exports = { */ logout: function(){ tray.toggleMediaButtons(false); - tray.toggleTray(false); - appMenu.toggleMenu(false); - controller.dispose(); - props.settings.lastURL = null; - props.settings.save(); + tray.toggleTray(false); + appMenu.toggleMenu(false); + controller.dispose(); + props.settings.lastURL = null; + props.settings.save(); windowHook = false; if (!props.spotify.isVisible()) props.spotify.show(); props.clearCache(); } -}; +}; \ No newline at end of file diff --git a/windows/windows.js b/windows/windows.js index 0cf2618..9355514 100755 --- a/windows/windows.js +++ b/windows/windows.js @@ -4,229 +4,229 @@ */ //app from SWP4L App class, electron and electron's BrowserWindow (app !== electron.app) module.exports = function(app, electron, BrowserWindow){ - const {globalShortcut} = require('electron'); - let _preferencesInstance, _aboutInstance; - class Preferences extends BrowserWindow{ - constructor(){ - var PREF_WIDTH = 800; - var PREF_HEIGHT = 450; - super({ - title: 'Preferences', - icon: App.icon, - width: PREF_WIDTH, - height: PREF_HEIGHT, - minWidth: PREF_WIDTH, - minHeight: PREF_HEIGHT, - maxWidth: PREF_WIDTH, - maxHeight: PREF_HEIGHT, - resizable: false, - show: false, - webPreferences: {preload: `${__dirname}/preferences/preload.js`} - }); - this.loadURL(`file://${__dirname}/preferences/preferences.html`); - this.setMenu(null); - this.webContents.once('dom-ready', () => { - this.show(); - }); - var focusKeys = function(){ - 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', () => { - var win = BrowserWindow.getFocusedWindow(); - win.close(); - }); - } - this.on('focus', focusKeys); - this.on('blur', () => { - globalShortcut.unregisterAll(); - }); - } - } - 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}/about/preload.js`} - }); - this.loadURL(`file://${__dirname}/about/about.html`); - this.setMenu(null); - this.webContents.once('dom-ready', () => { - this.show(); - }); - var focusKeys = function(){ - 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', () => { - var win = BrowserWindow.getFocusedWindow(); - win.close(); - }); - } - this.on('focus', focusKeys); - this.on('blur', () => { - globalShortcut.unregisterAll(); - }); - } - } - 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(); - } - } - class Spotify extends BrowserWindow{ - constructor(){ - super({ - title: "Spotify Web Player", - icon: App.icon, - width: 1200, - height: 700, - show: true, - backgroundColor: "#121314", - minWidth: 800, - minHeight: 600, - webPreferences: { - nodeIntegration: false, - preload: `${__dirname}/spotify/preload.js`, - plugins: true, - webSecurity: false, - allowDisplayingInsecureContent: true, - allowRunningInsecureContent: true - } - }); - this.on('page-title-updated', function(event){ - event.preventDefault(); - }); - this.on('closed', () => { - electron.app.quit(); - process.exit(0); - }); - this.setMenu(null); - this.webContents.on('new-window', function(event, url, name, disposition){ - if(!~url.indexOf("facebook.com")) return; - (new FacebookPopup(name, url, this.webContents.session)).show(); - event.preventDefault(); - }); - this.webContents.once('dom-ready', () => { - this.show(); - if(app.settings.StartHidden) this.minimize(); - }); - this.webContents.session.setUserAgent('Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36'); - this.loadURL((app.settings.lastURL && app.settings.lastURL.indexOf('play.spotify.com') > -1 ? app.settings.lastURL : App.HOST)); - this.on('show', () => { - if(props.settings.ShowDevTools) this.openDevTools() - }); - var focusKeys = function(){ - globalShortcut.register('CommandOrControl+S', () => { - var win = BrowserWindow.getFocusedWindow(); - if (win == this) this.webContents.executeJavaScript('$(\'#suggest-area\').toggleClass(\'show\');'); - }); - globalShortcut.register('CommandOrControl+Shift+P', () => { - var win = BrowserWindow.getFocusedWindow(); - if (win == this) this.showPreferences(); - }); - globalShortcut.register('F1', () => { - var win = BrowserWindow.getFocusedWindow(); - if (win == this) this.showAbout(); - }); - globalShortcut.register('Shift+<', () => { - var win = BrowserWindow.getFocusedWindow(); - if (win == this) this.webContents.executeJavaScript('controller.previous();'); - }); - globalShortcut.register('Shift+>', () => { - var win = BrowserWindow.getFocusedWindow(); - if (win == this) this.webContents.executeJavaScript('controller.next();'); - }); - 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('F11', () => { - var win = BrowserWindow.getFocusedWindow(); - if (win == this) this.setFullScreen(!this.isFullScreen()); - }); - globalShortcut.register('CommandOrControl+Shift+L', () => { - var win = BrowserWindow.getFocusedWindow(); - if (win == this) this.webContents.executeJavaScript('user.logout()'); - }); - globalShortcut.register('CommandOrControl+W', () => { - var win = BrowserWindow.getFocusedWindow(); - win.close(); - }); - } - this.on('focus', focusKeys); - this.on('blur', () => { - globalShortcut.unregisterAll(); - }); - } - showAbout(){ - if(_aboutInstance) return this.AboutInstance.show(); - _aboutInstance = new About(); - _aboutInstance.on('closed', function(){ - _aboutInstance = null; - }); - } - get AboutInstance(){ - return _aboutInstance - } - get PreferenceInstance(){ - return _preferencesInstance; - } - showPreferences(){ - if(_preferencesInstance) return this.About.show(); - _preferencesInstance = new Preferences(); - _preferencesInstance.on('closed', function(){ - _preferencesInstance = null; - }) - } - } - return Spotify; + const {globalShortcut} = require('electron'); + let _preferencesInstance, _aboutInstance; + class Preferences extends BrowserWindow{ + constructor(){ + var PREF_WIDTH = 800; + var PREF_HEIGHT = 450; + super({ + title: 'Preferences', + icon: App.icon, + width: PREF_WIDTH, + height: PREF_HEIGHT, + minWidth: PREF_WIDTH, + minHeight: PREF_HEIGHT, + maxWidth: PREF_WIDTH, + maxHeight: PREF_HEIGHT, + resizable: false, + show: false, + webPreferences: {preload: `${__dirname}/preferences/preload.js`} + }); + this.loadURL(`file://${__dirname}/preferences/preferences.html`); + this.setMenu(null); + this.webContents.once('dom-ready', () => { + this.show(); + }); + var focusKeys = function(){ + 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', () => { + var win = BrowserWindow.getFocusedWindow(); + win.close(); + }); + } + this.on('focus', focusKeys); + this.on('blur', () => { + globalShortcut.unregisterAll(); + }); + } + } + 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}/about/preload.js`} + }); + this.loadURL(`file://${__dirname}/about/about.html`); + this.setMenu(null); + this.webContents.once('dom-ready', () => { + this.show(); + }); + var focusKeys = function(){ + 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', () => { + var win = BrowserWindow.getFocusedWindow(); + win.close(); + }); + } + this.on('focus', focusKeys); + this.on('blur', () => { + globalShortcut.unregisterAll(); + }); + } + } + 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(); + } + } + class Spotify extends BrowserWindow{ + constructor(){ + super({ + title: "Spotify Web Player", + icon: App.icon, + width: 1200, + height: 700, + show: true, + backgroundColor: "#121314", + minWidth: 800, + minHeight: 600, + webPreferences: { + nodeIntegration: false, + preload: `${__dirname}/spotify/preload.js`, + plugins: true, + webSecurity: false, + allowDisplayingInsecureContent: true, + allowRunningInsecureContent: true + } + }); + this.on('page-title-updated', function(event){ + event.preventDefault(); + }); + this.on('closed', () => { + electron.app.quit(); + process.exit(0); + }); + this.setMenu(null); + this.webContents.on('new-window', function(event, url, name, disposition){ + if(!~url.indexOf("facebook.com")) return; + (new FacebookPopup(name, url, this.webContents.session)).show(); + event.preventDefault(); + }); + this.webContents.once('dom-ready', () => { + this.show(); + if(app.settings.StartHidden) this.minimize(); + }); + this.webContents.session.setUserAgent('Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36'); + this.loadURL((app.settings.lastURL && app.settings.lastURL.indexOf('play.spotify.com') > -1 ? app.settings.lastURL : App.HOST)); + this.on('show', () => { + if(props.settings.ShowDevTools) this.openDevTools() + }); + var focusKeys = function(){ + globalShortcut.register('CommandOrControl+S', () => { + var win = BrowserWindow.getFocusedWindow(); + if (win == this) this.webContents.executeJavaScript('$(\'#suggest-area\').toggleClass(\'show\');'); + }); + globalShortcut.register('CommandOrControl+Shift+P', () => { + var win = BrowserWindow.getFocusedWindow(); + if (win == this) this.showPreferences(); + }); + globalShortcut.register('F1', () => { + var win = BrowserWindow.getFocusedWindow(); + if (win == this) this.showAbout(); + }); + globalShortcut.register('Shift+<', () => { + var win = BrowserWindow.getFocusedWindow(); + if (win == this) this.webContents.executeJavaScript('controller.previous();'); + }); + globalShortcut.register('Shift+>', () => { + var win = BrowserWindow.getFocusedWindow(); + if (win == this) this.webContents.executeJavaScript('controller.next();'); + }); + 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('F11', () => { + var win = BrowserWindow.getFocusedWindow(); + if (win == this) this.setFullScreen(!this.isFullScreen()); + }); + globalShortcut.register('CommandOrControl+Shift+L', () => { + var win = BrowserWindow.getFocusedWindow(); + if (win == this) this.webContents.executeJavaScript('user.logout()'); + }); + globalShortcut.register('CommandOrControl+W', () => { + var win = BrowserWindow.getFocusedWindow(); + win.close(); + }); + } + this.on('focus', focusKeys); + this.on('blur', () => { + globalShortcut.unregisterAll(); + }); + } + showAbout(){ + if(_aboutInstance) return this.AboutInstance.show(); + _aboutInstance = new About(); + _aboutInstance.on('closed', function(){ + _aboutInstance = null; + }); + } + get AboutInstance(){ + return _aboutInstance + } + get PreferenceInstance(){ + return _preferencesInstance; + } + showPreferences(){ + if(_preferencesInstance) return this.About.show(); + _preferencesInstance = new Preferences(); + _preferencesInstance.on('closed', function(){ + _preferencesInstance = null; + }) + } + } + return Spotify; }; \ No newline at end of file