Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make thumbs up/down options in the tray menu work as checkboxes #3321

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/features/core/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,15 @@ const setContextMenu = (track) => {
{ type: 'separator' },
{
label: TranslationProvider.query('playback-label-thumbs-up'),
type: 'checkbox',
click: () => Emitter.sendToGooglePlayMusic('playback:thumbsUp'),
checked: (PlaybackAPI.getRating().liked),
},
{
label: TranslationProvider.query('playback-label-thumbs-down'),
type: 'checkbox',
click: () => Emitter.sendToGooglePlayMusic('playback:thumbsDown'),
checked: (PlaybackAPI.getRating().disliked),
},
{ type: 'separator' },
{
Expand Down Expand Up @@ -267,3 +271,7 @@ Emitter.on('audiooutput:set', () => Emitter.sendToGooglePlayMusic('audiooutput:f
PlaybackAPI.on('change:track', (track) => {
setContextMenu(track);
});

PlaybackAPI.on('change:rating', () => {
setContextMenu(PlaybackAPI.currentSong());
});
28 changes: 18 additions & 10 deletions src/renderer/windows/GPMWebView/playback/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,28 @@ Emitter.on('playback:stop', () => {

Emitter.on('playback:thumbsUp', () => {
if (!remote.getGlobal('PlaybackAPI').data.song.title) return;
new Notification('You just liked', { // eslint-disable-line
body: remote.getGlobal('PlaybackAPI').data.song.title,
icon: remote.getGlobal('PlaybackAPI').data.song.albumArt,
});
window.GPM.rating.setRating(5);
if (window.GPM.rating.getRating() !== '5') {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure how this change is relevent or what it does? Can you either clarify or remove ❓

Copy link
Contributor Author

@calvin-sykes calvin-sykes Oct 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, the "you just liked..." toast got fired every time the menu option was clicked - which was fine because once a song was already liked clicking the button again didn't do anything.
The menu option is now a toggle, so depending on whether the song is currently liked or not the rating either needs to be reset ("un-liked", as distinct from disliked) or set to 5.
Only in the latter case should the toast be shown. I didn't add an "un-liking" toast because I wasn't sure if that was the correct term to use.

(same argument in reverse applies to the dislike option)

new Notification('You just liked', { // eslint-disable-line
body: remote.getGlobal('PlaybackAPI').data.song.title,
icon: remote.getGlobal('PlaybackAPI').data.song.albumArt,
});
window.GPM.rating.setRating(5);
} else {
window.GPM.rating.resetRating();
}
});

Emitter.on('playback:thumbsDown', () => {
if (!remote.getGlobal('PlaybackAPI').data.song.title) return;
new Notification('You just disliked', { // eslint-disable-line
body: remote.getGlobal('PlaybackAPI').data.song.title,
icon: remote.getGlobal('PlaybackAPI').data.song.albumArt,
});
window.GPM.rating.setRating(1);
if (window.GPM.rating.getRating() !== '0') {
new Notification('You just disliked', { // eslint-disable-line
body: remote.getGlobal('PlaybackAPI').data.song.title,
icon: remote.getGlobal('PlaybackAPI').data.song.albumArt,
});
window.GPM.rating.setRating(1);
} else {
window.GPM.rating.resetRating();
}
});

Emitter.on('playback:increaseVolume', () => {
Expand Down