mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-13 11:21:46 +00:00
QOL: Move source code under the src directory. (#1318)
This commit is contained in:
65
src/plugins/taskbar-mediacontrol/back.ts
Normal file
65
src/plugins/taskbar-mediacontrol/back.ts
Normal file
@ -0,0 +1,65 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import { app, BrowserWindow, nativeImage } from 'electron';
|
||||
|
||||
import getSongControls from '../../providers/song-controls';
|
||||
import registerCallback, { SongInfo } from '../../providers/song-info';
|
||||
import { getMediaIconLocation, saveMediaIcon } from '../utils';
|
||||
|
||||
export default (win: BrowserWindow) => {
|
||||
let currentSongInfo: SongInfo;
|
||||
|
||||
const { playPause, next, previous } = getSongControls(win);
|
||||
|
||||
if (app.isPackaged) {
|
||||
saveMediaIcon();
|
||||
}
|
||||
|
||||
const setThumbar = (win: BrowserWindow, songInfo: SongInfo) => {
|
||||
// Wait for song to start before setting thumbar
|
||||
if (!songInfo?.title) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Win32 require full rewrite of components
|
||||
win.setThumbarButtons([
|
||||
{
|
||||
tooltip: 'Previous',
|
||||
icon: nativeImage.createFromPath(get('previous')),
|
||||
click() {
|
||||
previous();
|
||||
},
|
||||
}, {
|
||||
tooltip: 'Play/Pause',
|
||||
// Update icon based on play state
|
||||
icon: nativeImage.createFromPath(songInfo.isPaused ? get('play') : get('pause')),
|
||||
click() {
|
||||
playPause();
|
||||
},
|
||||
}, {
|
||||
tooltip: 'Next',
|
||||
icon: nativeImage.createFromPath(get('next')),
|
||||
click() {
|
||||
next();
|
||||
},
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
// Util
|
||||
const get = (kind: string) => {
|
||||
return path.join(getMediaIconLocation(), `${kind}.png`);
|
||||
};
|
||||
|
||||
registerCallback((songInfo) => {
|
||||
// Update currentsonginfo for win.on('show')
|
||||
currentSongInfo = songInfo;
|
||||
// Update thumbar
|
||||
setThumbar(win, songInfo);
|
||||
});
|
||||
|
||||
// Need to set thumbar again after win.show
|
||||
win.on('show', () => {
|
||||
setThumbar(win, currentSongInfo);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user