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.
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
1 parent
17e85d0
commit f76c88f
Showing
26 changed files
with
590 additions
and
611 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,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({ | ||
|
@@ -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(){ | ||
|
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 |
---|---|---|
@@ -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'); | ||
|
@@ -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; | ||
} | ||
}); | ||
|
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
Oops, something went wrong.