diff --git a/js/backend/Error/error.html b/js/backend/Error/error.html deleted file mode 100644 index f03b217..0000000 --- a/js/backend/Error/error.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - -
-
- -

-

This application requires the internet to function

-
-
- - - \ No newline at end of file diff --git a/js/backend/Error/preload.js b/js/backend/Error/preload.js deleted file mode 100644 index 0b6f4f6..0000000 --- a/js/backend/Error/preload.js +++ /dev/null @@ -1,29 +0,0 @@ -/* - * @author Matthew James - * Error loading script - */ -var errorpath = __dirname + '/error.html'; -props.fs.readFile(errorpath, (err, data) => { - var newDoc = document.open("text/html", "replace"); - newDoc.write(data); - document.onreadystatechange = function(){ - window.$ = window.jQuery = require('../../preloaded/jquery'); - let interface = require('../../preloaded/interface'); - interface.load(); - props.fs.readFile(__dirname + '/../About/Spotify_Logo_RGB_White.png', {encoding: 'base64'}, (err, data) => { - if(err) console.log(err); - $('#logo').attr('src', 'data:image/png;base64,' + data); - }); - $('#app_title_and_version').html(props.NAME + ' for Linux (v' + props.electron.app.getVersion() + ')'); - var testInternet = setInterval(() => { - if (navigator.onLine){ - window.location = ( - props.appSettings.lastURL && props.appSettings.lastURL.indexOf('play.spotify.com') > -1 ? - props.appSettings.lastURL : - global.props.HOST - ); - } - }, 1500); - } - newDoc.close(); -}); \ No newline at end of file diff --git a/js/backend/dbus_service.js b/js/backend/MPRISAndNotifications_service.js similarity index 65% rename from js/backend/dbus_service.js rename to js/backend/MPRISAndNotifications_service.js index 3e87be5..c68aa90 100755 --- a/js/backend/dbus_service.js +++ b/js/backend/MPRISAndNotifications_service.js @@ -7,29 +7,35 @@ var fs = require('fs'); const interpreter = require('./dbus_interpreter'); const notifications = require('freedesktop-notifications'); notifications.setUnflood(true); -let notification = notifications.createNotification({timeout: 1e4}); +let notification = notifications.createNotification({timeout: 15e4}); function setupNotification(info){ notification.summary = (info.status == 'Playing' ? 'Now Playing' : info.status); - notification.body = info.activeSong.name.replace(/(\'| - .*| \(.*)/i, '') + '\n' + - info.activeSong.album.replace(/(\'| - .*| \(.*)/i, '') + '\n' + + notification.body = info.activeSong.name.replace(/( - .*| \(.*)/i, '') + '\n' + + info.activeSong.album.replace(/( - .*| \(.*)/i, '') + '\n' + info.activeSong.artists; - notification.icon = info.activeSong.art;; + notification.icon = info.activeSong.art; } + //Always make sure we're running as a proper name! process.title = 'spotifywebplayer'; interpreter.handle(process.stdin, { updateMpris: (info) => { - player.metadata = { - 'mpris:trackid': player.objectPath('track/' + info.activeSong.id), - 'mpris:length': info.activeSong.length, // In microseconds - 'mpris:artUrl': info.activeSong.art, - 'xesam:title': info.activeSong.name.replace(/(\'| - .*| \(.*)/i, ''), //Remove long track titles - 'xesam:album': info.activeSong.album.replace(/(\'| - .*| \(.*)/i, ''), //Remove long album names - 'xesam:artist': info.activeSong.artists - }; - player.playbackStatus = info.status; - player.shuffle = info.shuffle; - player.repeat = info.repeat; + if (info.status == 'Stopped'){ + player.playbackStatus = info.status; + } else { + player.metadata = { + 'mpris:trackid': player.objectPath('track/' + info.activeSong.id), + 'mpris:length': info.activeSong.length, // In microseconds + 'mpris:artUrl': info.activeSong.art, + 'xesam:title': info.activeSong.name.replace(/(\'| - .*| \(.*)/i, ''), //Remove long track titles + 'xesam:album': info.activeSong.album.replace(/(\'| - .*| \(.*)/i, ''), //Remove long album names + 'xesam:artist': info.activeSong.artists, + 'xesam:url': 'https://play.spotify.com/track/' + info.activeSong.uri + }; + player.playbackStatus = info.status; + player.shuffle = info.shuffle; + player.repeat = info.repeat; + } }, notify: (info) => { var filepath = info.albumCache; @@ -40,13 +46,13 @@ interpreter.handle(process.stdin, { }); } }); - var file = filepath + '/' + info.activeSong.album + '.jpeg'; + var file = (info.activeSong.art ? filepath + '/' + info.activeSong.album + '.jpeg' : process.cwd() + '/icons/spotify-web-player.png'); fs.access(file, fs.F_OK, function(err){ if (err){ request(info.activeSong.art, {encoding: 'binary'}, function(error, response, body) { + if(error) console.log(error); fs.writeFile(file, body, 'binary', function (err) { - if (err) console.log(err); - lastAlbumArt = file; + if (err) return console.log(err); info.activeSong.art = file; setupNotification(info); notification.push(); @@ -62,7 +68,6 @@ interpreter.handle(process.stdin, { }); const Player = require('mpris-service'); - const player = Player({ name: 'spotifywebplayer', identity: 'spotifywebplayer', diff --git a/js/backend/MediaKeys_service.js b/js/backend/MediaKeys_service.js new file mode 100644 index 0000000..47dc91f --- /dev/null +++ b/js/backend/MediaKeys_service.js @@ -0,0 +1,28 @@ +const interpreter = require('./dbus_interpreter'); +function send(command, args){ + console.log('Sending ' + command + ' event'); + interpreter.send(process.stdout, command, args); +} +var DBus = require('dbus'); +var dbus = new DBus(); +var bus = dbus.getBus('session'); +bus.getInterface('org.gnome.SettingsDaemon', '/org/gnome/SettingsDaemon/MediaKeys', 'org.gnome.SettingsDaemon.MediaKeys', function(err, iface) { + if(err) console.log(err); + iface.on('MediaPlayerKeyPressed', function (n, value) { + switch (value) { + case 'Play': + send('PlayPause'); + break; + case 'Next': + send('Next'); + break; + case 'Previous': + send('Previous'); + break; + case 'Stop': + send('Stop'); + break; + } + }); + iface.GrabMediaPlayerKeys(0, 'org.gnome.SettingsDaemon.MediaKeys'); +}); \ No newline at end of file diff --git a/js/backend/Preferences/preferences.html b/js/backend/Preferences/preferences.html index 46d516c..e69b4d0 100755 --- a/js/backend/Preferences/preferences.html +++ b/js/backend/Preferences/preferences.html @@ -71,9 +71,7 @@

App Preferences

Notifications

- - - + @@ -124,7 +122,7 @@

On Stop

Only When Focused

- Show any notification but only when you're not using the player window + Show any enabled notification but only when you're not using the player window