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

New Feature: Keyboard shortcut for 'like' toggle #200

Closed
gamemasta0 opened this issue Nov 13, 2019 · 4 comments
Closed

New Feature: Keyboard shortcut for 'like' toggle #200

gamemasta0 opened this issue Nov 13, 2019 · 4 comments

Comments

@gamemasta0
Copy link

I'm trying to write a new keyboard shortcut into soundcleod and have got the functionality down - a keyboard shortcut now toggles 'like' of the current track - but I don't know how to get the track data to describe in a notification what track has been liked and if a like was added or removed by pressing the shortcut.

The only code I've had to write to make this happen so far with a generalized notification "Track Like Toggled" is the following in main.js:

 globalShortcut.register('Option+Shift+L', () => {
	soundcloud.likeUnlike()
 	let title = "Track Like Toggled"
 	mainWindow.webContents.send('notification', {title})
 })

I used similar notification code to the function soundcloud.on('play-new-track'), but I don't know how to implement a similar soundcloud.on('track-liked') and soundcloud.on('track-disliked'). Is this possible with the SoundCloud API included in soundcleod? Is there documentation on the API? I was unable to locate it myself.

@salomvary
Copy link
Owner

@gamemasta0 the good news is, this shortcut already exists both in SoundCleod or on soundcloud.com. Just press the key 'L' to like/unlike the currently playing track.

You can learn more about SoundCloud's built-in shortcuts by pressing '?'.

I hope this helps.

@gamemasta0
Copy link
Author

@salomvary I understand that, but that’s not what I’m talking about. I made a shortcut that can be accessed when the app is not focused! The ‘L’ shortcut only works when in-app. I want to be able to like a song when I’m in another app, like how the media keys can be used anywhere. Also, my question wasn’t how to do that, I’ve already built that. I’m trying to make a notification to give feedback to the user that the shortcut worked and also that they ‘liked’ or ‘disliked’ the song. Right now, it just says that the keyboard shortcut toggled ‘like’, but doesn’t say whether or not the song was ‘liked’ or ‘disliked’. Does the API have access to the ‘like’ status of the current track?

@salomvary
Copy link
Owner

@gamemasta0 Sorry, I missed the bit about a global shortcut.

The "API" to programmatically trigger like/unlike is here:

likeUnlike() {
this.trigger('L')
}

This is for example how the main menu uses it:

soundcleod/app/main.js

Lines 160 to 164 in 13bd4e9

menu.events.on('likeUnlike', () => {
if (isNotFocused()) {
soundcloud.likeUnlike()
}
})

Does the API have access to the ‘like’ status of the current track?

There is nothing implemented for reading like status right now, you can do something similar to how getTrackMetadata works:

ipcRenderer.on('getTrackMetadata', ({ sender }) => sendTrackMetadata(sender))
ipcRenderer.on('navigate', (_, url) => navigate(url))
ipcRenderer.on('notification', (_, metadata) => showNotification(metadata))
function sendTrackMetadata(sender) {
const artworkURL = getArtworkURL()
sender.send('trackMetadata', { artworkURL })
}

I imagine you will actually have to implement this in multiple steps:

  • Sent the keyboard shortcut to like/remove like
  • Listen to a "track was liked" event
  • If that event was received, get track metadata
  • Show a notification (with the like status and/or track metadata)

I hope this now actually helps. Catching that "track was liked" event from SoundCloud will be a tricky one, it might involve digging into some internals on soundcloud.com.

@salomvary
Copy link
Owner

You might find some useful bits about getting the like status on this now abandoned pull request: #148.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants