Merge pull request #138 from gms10ur/main

Added thumbar buttons
This commit is contained in:
vapormusic 2022-01-16 17:38:31 +07:00 committed by GitHub
commit ffc55b6b64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 0 deletions

View file

@ -268,6 +268,7 @@ const CiderBase = {
win.webContents.setZoomFactor(screen.getPrimaryDisplay().scaleFactor)
mpris.connect(win)
mpris.SetButtons(win, false)
lastfm.authenticate()
// Discord
@ -275,6 +276,7 @@ const CiderBase = {
ipcMain.on('playbackStateDidChange', (_event, a) => {
app.media = a;
discord.updateActivity(a)
mpris.SetButtons(win, a)
mpris.updateState(a)
lastfm.scrobbleSong(a)
lastfm.updateNowPlayingSong(a)
@ -283,6 +285,7 @@ const CiderBase = {
ipcMain.on('nowPlayingItemDidChange', (_event, a) => {
app.media = a;
discord.updateActivity(a)
mpris.SetButtons(win, a)
mpris.updateAttributes(a)
lastfm.scrobbleSong(a)
lastfm.updateNowPlayingSong(a)

View file

@ -1,3 +1,6 @@
const { nativeImage } = require("electron");
const path = require('path')
let mediaPlayer = null;
module.exports = {
@ -102,6 +105,39 @@ module.exports = {
}
},
SetButtons: (win, attributes) => {
if (process.platform === 'win32') { // Set the Windows Thumbnail Toolbar Buttons
win.setThumbarButtons([
{
tooltip: 'Previous',
icon: nativeImage.createFromPath(path.join(__dirname, 'thumbaricons/backwardPng.png')),
click() {
console.log("Clicked the bc taskbar button!")
win.webContents.executeJavaScript('MusicKitInterop.previousTrack()').catch(err => console.error(err))
}
},
{
tooltip: attributes.status ? 'Pause' : 'Play',
//tooltip: 'Play',
icon: attributes.status ? nativeImage.createFromPath(path.join(__dirname, 'thumbaricons/pausePng.png')) : nativeImage.createFromPath(path.join(__dirname, 'thumbaricons/playPng.png')),
click() {
console.log("Clicked the pl taskbar button!")
win.webContents.executeJavaScript('MusicKitInterop.pausePlay()').catch(err => console.error(err))
}
},
{
tooltip: 'Next',
icon: nativeImage.createFromPath(path.join(__dirname, 'thumbaricons/forwardPng.png')),
click() {
console.log("Clicked the fw taskbar button!")
win.webContents.executeJavaScript('MusicKitInterop.nextTrack()').catch(err => console.error(err))
}
}
]);
}
},
/**
* Closes the MPRIS interface.
*/

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB