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

Commit

Permalink
v1.0.0 pre-release
Browse files Browse the repository at this point in the history
Fixed buggy notifications
Controller functions that have been deprecated (getTrackUri, getAlbumArt, getArtist, getTrackName, getAlbum, isPlaying, isShuffled, isRepeat)
dbus_interpreter put into a class, now uses event emitter
Controller put into a class, now uses event emitter
Removed theming unnecessary interval - less CPU hogging
Update theme change function in preferences to accommodate for missing interval
Added Clean lyricCache and albumCache buttons
Added albumCacheDisabled property (album art saved to /tmp until restart)
Support System Icons
Mix-&-Match Tray Icon to DE/Icon theme (22px icons to fix bug #)
Update button (shows if update on start up)
Fixed 0.8.19 version in make_deb.sh
Updated version - ready for version 1.0.0 - small updates for Sing! can wait (would take too much time to perfect)
Changed console.log redirect back to original console.log for devtools - was buggy and not needed
Added dbus dependency to package.json
  • Loading branch information
Quacky2200 committed Sep 28, 2016
1 parent 17e85d0 commit f76c88f
Show file tree
Hide file tree
Showing 26 changed files with 590 additions and 611 deletions.
Binary file added icons/spotify-ico-small-black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/spotify-ico-small-green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/spotify-ico-small-lime.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/spotify-ico-small-old.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/spotify-ico-small-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
156 changes: 83 additions & 73 deletions js/backend/MPRISAndNotifications_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,19 @@
* @author Matthew James <[email protected]>
* MPRIS D-Bus Service
*/

//Always make sure we're running as a proper name!
process.title = 'spotifywebplayer';

var request = require('request');
var fs = require('fs');
const interpreter = require('./dbus_interpreter');

const DBusInterpeter = require('./dbus_interpreter');
var interpreter = new DBusInterpeter(process.stdin, process.stdout);

const notifications = require('freedesktop-notifications');
notifications.setUnflood(true);
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' +
info.activeSong.artists;
notification.icon = info.activeSong.art;
}

//Always make sure we're running as a proper name!
process.title = 'spotifywebplayer';
interpreter.handle(process.stdin, {
updateMpris: (info) => {
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;
fs.access(filepath, fs.F_OK, (err) => {
if (err){
fs.mkdir(filepath, (err) => {
if (err) console.log(err);
});
}
});
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) return console.log(err);
info.activeSong.art = file;
setupNotification(info);
notification.push();
});
});
} else {
info.activeSong.art = file;
setupNotification(info);
notification.push();
}
});
}
});
let notification = notifications.createNotification({timeout: 2e3});

const Player = require('mpris-service');
const player = Player({
Expand All @@ -75,22 +24,83 @@ const player = Player({
supportedMimeTypes: ['application/www-url'],
desktopEntry: 'spotifywebplayer'
});
function send(command, args){
console.log('Sending ' + command + ' event');
interpreter.send(process.stdout, command, args);


function setupNotification(info){
notification.summary = (info.status == 'Playing' ? 'Now Playing' : info.status);
notification.body = info.track.name.replace(/( - .*| \(.*)/i, '') + '\n' +
info.track.album.replace(/( - .*| \(.*)/i, '') + '\n' +
info.track.artists;
notification.icon = info.track.art;
}
let lastURI = '';
interpreter.on('updateMpris', function(info){
if (info.status == 'Stopped'){
player.playbackStatus = info.status;
} else {
if (info.track.uri && lastURI != info.track.uri){
player.metadata = {
'mpris:trackid': player.objectPath('track/' + info.track.id),
'mpris:length': info.track.length,
'mpris:artUrl': info.track.art,
'xesam:title': info.track.name.replace(/(\'| - .*| \(.*)/i, ''), //Remove long track titles
'xesam:album': info.track.album.replace(/(\'| - .*| \(.*)/i, ''), //Remove long album names
'xesam:artist': info.track.artists,
'xesam:url': 'https://play.spotify.com/track/' + info.track.uri
};
lastURI = info.track.uri;
}
if (player.metadata['mpris:length'] != info.track.length) {
player.metadata['mpris:length'] = info.track.length;
}
if (info.track.uri) player.position = info.track.position;
if(player.playbackStatus != info.status) player.playbackStatus = info.status;
if(player.shuffle != info.shuffle) player.shuffle = info.shuffle;
if(player.repeat != info.repeat) player.repeat = info.repeat;
}
});

interpreter.on('notify', function(info){
if (!info.track.uri) return;
var filepath = (info.albumCacheDisabled ? '/tmp' : info.albumCache);
if (!info.albumCacheDisabled) fs.access(filepath, fs.F_OK, (err) => {
if (err){
fs.mkdir(filepath, (err) => {
if (err) console.log(err);
});
}
});
var file = (info.track.art ? filepath + '/' + info.track.album + '.jpeg' : process.cwd() + '/icons/spotify-web-player.png');
fs.access(file, fs.F_OK, function(err){
if (err){
request(info.track.art, {encoding: 'binary'}, function(error, response, body) {
if(error) console.log(error);
fs.writeFile(file, body, 'binary', function (err) {
if (err) return console.log(err);
info.track.art = file;
setupNotification(info);
notification.push();
});
});
} else {
info.track.art = file;
setupNotification(info);
notification.push();
}
});
});

player.on('quit', () => {send('Quit')});
player.on('raise', () => {send('Raise')});
player.on('quit', () => {interpreter.send('Quit')});
player.on('raise', () => {interpreter.send('Raise')});

player.on('playpause', () => {send('PlayPause')});
player.on('play', () => {send('Play')});
player.on('next', () => {send('Next')});
player.on('previous', () => {send('Previous')});
player.on('stop', () => {send('Stop')});
player.on('seek', (Offset) => {send('Seek', {Offset:Offset})});
player.on('position', (TrackID, Position) => {send('SetPosition', {TrackID:TrackID, Position:Position})});
player.on('open', (Uri) => {send('OpenUri', {Uri:Uri})});
player.on('playpause', () => {interpreter.send('PlayPause')});
player.on('play', () => {interpreter.send('Play')});
player.on('next', () => {interpreter.send('Next')});
player.on('previous', () => {interpreter.send('Previous')});
player.on('stop', () => {interpreter.send('Stop')});
player.on('seek', (Offset) => {interpreter.send('Seek', {Offset:Offset})});
player.on('position', (TrackID, Position) => {interpreter.send('SetPosition', {TrackID:TrackID, Position:Position})});
player.on('open', (Uri) => {interpreter.send('OpenUri', {Uri:Uri})});

//Make sure we stop when we get disconnected from the main process
process.on('disconnect', function(){
Expand Down
23 changes: 14 additions & 9 deletions js/backend/MediaKeys_service.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
const interpreter = require('./dbus_interpreter');
function send(command, args){
console.log('Sending ' + command + ' event');
interpreter.send(process.stdout, command, args);
}
/*
* @author Matthew James <[email protected]>
* Media Keys D-Bus Service
*/
//Always make sure we're running as a proper name!
process.title = 'spotifywebplayer';

const DBusInterpeter = require('./dbus_interpreter');
var interpreter = new DBusInterpeter(null, process.stdout);

var DBus = require('dbus');
var dbus = new DBus();
var bus = dbus.getBus('session');
Expand All @@ -11,16 +16,16 @@ bus.getInterface('org.gnome.SettingsDaemon', '/org/gnome/SettingsDaemon/MediaKey
iface.on('MediaPlayerKeyPressed', function (n, value) {
switch (value) {
case 'Play':
send('PlayPause');
interpreter.send('PlayPause');
break;
case 'Next':
send('Next');
interpreter.send('Next');
break;
case 'Previous':
send('Previous');
interpreter.send('Previous');
break;
case 'Stop':
send('Stop');
interpreter.send('Stop');
break;
}
});
Expand Down
56 changes: 54 additions & 2 deletions js/backend/Preferences/preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,15 @@ <h2>Theme</h2>
</tr>
<tr>
<td>
<h2>Show Tray Icon</h2>
<h2>Tray</h2>
<span></span>
</td>
<td>
</td>
</tr>
<tr class='indent'>
<td>
<h2>Enabled</h2>
<span>Should Spotify Web Player show a tray icon?</span>
</td>
<td>
Expand All @@ -155,6 +163,21 @@ <h2>Show Tray Icon</h2>
</label>
</td>
</tr>
<tr class='indent'>
<td>
<h2>Icon</h2>
<span>Mix-&amp;-Match the tray icon to your DE/Icon style</span>
</td>
<td>
<select name='TrayIcon'>
<option value='old'>Old Spotify</option>
<option value='green'>Green Spotify</option>
<option value='lime'>Lime Spotify</option>
<option value='white'>White Spotify</option>
<option value='black'>Black Spotify</option>
</select>
</td>
</tr>
<tr>
<td>
<h2>Close To Tray</h2>
Expand All @@ -169,7 +192,7 @@ <h2>Close To Tray</h2>
<tr>
<td>
<h2>Close To Controller</h2>
<span>Allows you to keep the window hidden without an indicator or application icon taking up space<br/><i>Hint: MPRIS controllers have to raise Spotify Web Player for it to become unhidden</i></span>
<span>Allows you to keep the window hidden without an indicator or application icon taking up space<br/><i>Warning: MPRIS controllers have to raise Spotify Web Player for it to become unhidden</i></span>
</td>
<td>
<label class='toggle'>
Expand Down Expand Up @@ -294,6 +317,35 @@ <h2>Show Sing! Icon</h2>
</label>
</td>
</tr>
<tr>
<td>
<h2>Store Album Art?</h2>
<span>Sometimes you want album art, other times it's just art...<br/><i>Note: Album Art will still be downloaded temporarily to /tmp for notifications (but deleted on reboot)</i></span>
</td>
<td>
<label class='toggle'>
<input type='checkbox' name='AlbumCacheDisabled'>
</label>
</td>
</tr>
<tr>
<td>
<h2>Clean AlbumCache</h2>
<span>This will remove all album art covers</span>
</td>
<td>
<a class='btn btn-primary clean-album-cache'>Clean Me</a>
</td>
</tr>
<tr>
<td>
<h2>Clean LyricCache</h2>
<span>This will remove all the lyrics you have saved</span>
</td>
<td>
<a class='btn btn-primary clean-lyric-cache'>Clean Me</a>
</td>
</tr>
<tr>
<td>
<h2>Show DevTools</h2>
Expand Down
50 changes: 44 additions & 6 deletions js/backend/Preferences/preload.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
global.remote = require('electron').remote;
let fs = require('fs');
let props = remote.getGlobal('props');
var AutoLaunch = require('auto-launch');
let autolaunch = new AutoLaunch({
Expand All @@ -13,6 +14,19 @@ global.refresh = () => {
windowHook = false;
window.location.reload();
}
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);
}
};
document.onreadystatechange = function(){
window.$ = window.jQuery = require('../../preloaded/jquery');
var interface = require('../../preloaded/interface');
Expand Down Expand Up @@ -61,17 +75,41 @@ document.onreadystatechange = function(){
props.appSettings.save();
props.mainWindow.webContents.executeJavaScript('appMenu.toggleMenu(' + props.appSettings.ShowApplicationMenu + ')');
});

$('input[name*="AlbumCacheDisabled"]').change(function(){
props.appSettings.AlbumCacheDisabled = $(this).prop('checked');
props.appSettings.save();
props.mainWindow.webContents.executeJavaScript('controller.albumCacheDisabled = ' + props.appSettings.AlbumCacheDisabled + ';');
});
$('input[name*=\'NavBar\'], select').change(() => {
props.mainWindow.webContents.executeJavaScript('interface.load();interface.clean()');
interface.load();
interface.clean();
var i = 0;
var setTheme = setInterval(() => {
if(i > 5) clearInterval(setTheme);
i += 1;
props.mainWindow.webContents.executeJavaScript('interface.load();interface.clean()');
interface.load();
interface.clean();
}, 1500);
});

$('select').change(function(){
$('select[name=\'Theme\']').change(function(){
props.appSettings.Theme = $(this).val();
props.appSettings.save();
});
$('select').val(props.appSettings.Theme);
$('select[name=\'TrayIcon\']').change(function(){
props.appSettings.TrayIcon = $(this).val();
props.mainWindow.webContents.executeJavaScript('tray.toggleTray(false);tray.toggleTray(true);');
props.appSettings.save();
});

$('select[name=\'Theme\']').val(props.appSettings.Theme);
$('select[name=\'TrayIcon\']').val(props.appSettings.TrayIcon);

$('a.clean-album-cache').click(() => {
deleteFolderRecursive(props.albumCache);
});

$('a.clean-lyric-cache').click(() => {
deleteFolderRecursive(props.lyricCache);
});
};

Loading

0 comments on commit f76c88f

Please sign in to comment.