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

[Plugin] taskbar-mediacontrol (for Windows) #200

Merged
merged 11 commits into from
Mar 25, 2021
Binary file added plugins/taskbar-mediacontrol/assets/backward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugins/taskbar-mediacontrol/assets/forward.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugins/taskbar-mediacontrol/assets/pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugins/taskbar-mediacontrol/assets/play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions plugins/taskbar-mediacontrol/back.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const getSongControls = require('../../providers/song-controls');
const getSongInfo = require('../../providers/song-info');
const path = require('path');

module.exports = win => {
win.hide = function () {
win.minimize();
win.setSkipTaskbar(true);
};

const show = win.show;
win.show = function () {
win.restore();
win.focus();
win.setSkipTaskbar(false);
show.apply(win);
};

win.isVisible = function () {
return !win.isMinimized();
};

const registerCallback = getSongInfo(win);
const {playPause, next, previous} = getSongControls(win);

// If the page is ready, register the callback
win.on('ready-to-show', () => {
registerCallback(songInfo => {
// Wait for song to start before setting thumbar
if (songInfo.title === '') {
return;
}

// Win32 require full rewrite of components
win.setThumbarButtons([
{
tooltip: 'Previous',
icon: get('backward.png'),
click() {previous(win.webContents);}
}, {
tooltip: 'Play/Pause',
// Update icon based on play state
icon: songInfo.isPaused ? get('play.png') : get('pause.png'),
click() {playPause(win.webContents);}
}, {
tooltip: 'Next',
icon: get('forward.png'),
click() {next(win.webContents);}
}
]);
});
});
};

// Util
function get(file) {
return path.join(__dirname,"assets", file);
}