Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #34 from davicorreiajr/develop
Browse files Browse the repository at this point in the history
Bump version to 0.7.0
  • Loading branch information
davicorreiajr committed Aug 6, 2019
2 parents 3986d95 + daea184 commit 26e83ab
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ This is a popup that shows Spotify current playback information, made and tested

Download the `.dmg` file from the [latest release](https://github.com/davicorreiajr/spotify-now-playing/releases/latest), run it and move the app to the `Application` folder.

Using Homebrew:
```
brew cask install spotify-now-playing
```

### Compatibily with Linux

I tried to make the app compatible with Linux, but I've seen [this issue](https://github.com/electron/electron/issues/6773), which turns quite hard to make the app behaves as expected (let's say, as a menu bar app) on Linux. You can run the app locally, but for now, I prefered to not release a version for Linux because it'd be far from what I (or any other user) would expected. If you find a good solution, please don't hesitate to open an issue or a pull request.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spotify-now-playing",
"version": "0.6.1",
"version": "0.7.0",
"description": "Spotify now playing popup for macOS menu bar",
"main": "src/index.js",
"scripts": {
Expand Down
32 changes: 28 additions & 4 deletions src/domain/spotify-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const spotifyDataSource = require('../data-source/spotify-datasource');
const mappers = require('../helpers/mappers');
const errorReporter = require('../helpers/error-reporter');
const authorizer = require('./authorizer');
const { UPDATE_PERIOD } = require('../helpers/constants');
const { SONG_TITLE_MAX_LENGTH, UPDATE_PERIOD } = require('../helpers/constants');
const notifier = require('node-notifier');

ipcMain.on('shuffleButtonClicked', () => spotifyDataSource.shuffle(localStorage.get('accessToken'), true));
Expand All @@ -22,11 +22,13 @@ ipcMain.on('addToLibraryClicked', (event, uri) => {

let currentPlaybackURI;

exports.execute = function(parentWindow) {
exports.execute = function(parentWindow, tray) {
ipcMain.on('addToPlaylistButtonClicked', handleAddToPlaylistButtonClicked);
ipcMain.on('playlistSelected', (event, data) => handlePlaylistSelected(data));

setInterval(() => getCurrentPlayback(), UPDATE_PERIOD);

let index = 0;

function getCurrentPlayback() {
const accessToken = localStorage.get('accessToken');
Expand All @@ -36,9 +38,23 @@ exports.execute = function(parentWindow) {
if(json.item) {
const mappedData = mappers.currentPlaybackToView(json);
if(shouldShowTrackNotification(mappedData)) {
currentPlaybackURI = mappedData.uri;
notifier.notify(mappers.notificationData(json));
}
if(shouldShowSongMenubar()) {
const title = `${mappedData.artistName} - ${mappedData.musicName} - ${mappedData.albumName}`;

if(title.length <= SONG_TITLE_MAX_LENGTH) {
tray.setTitle(title);
} else {
if(didSongChange(mappedData)) {
index = 0;
}

tray.setTitle(title.substring(index, index + (SONG_TITLE_MAX_LENGTH - 1)));
index = (index + 1) % (title.length - SONG_TITLE_MAX_LENGTH + 2);
}
}
currentPlaybackURI = mappedData.uri;
sendToRendererProcess('currentPlaybackReceived', mappedData);
} else {
sendToRendererProcess('loading', {});
Expand All @@ -55,8 +71,16 @@ exports.execute = function(parentWindow) {
parentWindow.webContents.send(channel, data);
}

function didSongChange(data) {
return data.uri !== currentPlaybackURI;
}

function shouldShowTrackNotification(data) {
return data.currentlyPlayingType === 'track' && (data.uri !== currentPlaybackURI) && localStorage.get('activateNotifications');
return data.currentlyPlayingType === 'track' && didSongChange(data) && localStorage.get('activateNotifications');
}

function shouldShowSongMenubar() {
return localStorage.get('songMenubar');
}

function handleAddToPlaylistButtonClicked() {
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = {
MAIN_WINDOW_HEIGHT: 150,
UPDATER_WINDOW_WIDTH: 500,
UPDATER_WINDOW_HEIGHT: 250,
UPDATE_PERIOD: 1500,
UPDATE_PERIOD: 750,
SONG_TITLE_MAX_LENGTH: 25,
ERROR_MESSAGES: {
getCurrentPlayback: 'getCurrentPlayback',
getSpotifyTokenFromAuthCode: 'getSpotifyTokenFromAuthCode',
Expand Down
14 changes: 12 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function launchApp() {
setWindowListeners(window);

authorizer.execute(window);
spotify.execute(window);
spotify.execute(window, tray);
updater.execute(window);
setInterval(() => updater.execute(window), 86400000);
}
Expand All @@ -41,7 +41,7 @@ function setTrayListeners(tray) {
tray.on('click', (event, bounds) => {
const windowWidth = window.getSize()[0];
const trayWidth = bounds.width;
const x = bounds.x - windowWidth/2 + trayWidth/2;
const x = Math.round(bounds.x - windowWidth/2 + trayWidth/2);
const y = bounds.y;
window.setPosition(x, y);
window.isVisible() ? hideAllWindows() : showAllWindows();
Expand Down Expand Up @@ -86,6 +86,7 @@ function setWindowListeners(window) {
function manageTrayRightClick(tray) {
const openAtLogin = app.getLoginItemSettings().openAtLogin;
const activateNotifications = localStorage.get('activateNotifications');
const songMenubar = localStorage.get('songMenubar');
window.hide();

const trayMenuTemplate = [
Expand All @@ -112,6 +113,15 @@ function manageTrayRightClick(tray) {
checked: activateNotifications,
click: () => localStorage.save('activateNotifications', !localStorage.get('activateNotifications'))
},
{
label: 'Show song in menu bar',
type: 'checkbox',
checked: songMenubar,
click: function() {
localStorage.save('songMenubar', !songMenubar);
if(songMenubar) tray.setTitle('');
}
},
{
type: 'separator'
},
Expand Down

0 comments on commit 26e83ab

Please sign in to comment.