mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
chore(song-info): change from array to Set
change from `array` to `Set` to prevent the duplicate callback from being stored
This commit is contained in:
@ -93,11 +93,11 @@ const handleData = async (
|
|||||||
|
|
||||||
// This variable will be filled with the callbacks once they register
|
// This variable will be filled with the callbacks once they register
|
||||||
export type SongInfoCallback = (songInfo: SongInfo, event?: string) => void;
|
export type SongInfoCallback = (songInfo: SongInfo, event?: string) => void;
|
||||||
const callbacks: SongInfoCallback[] = [];
|
const callbacks: Set<SongInfoCallback> = new Set();
|
||||||
|
|
||||||
// This function will allow plugins to register callback that will be triggered when data changes
|
// This function will allow plugins to register callback that will be triggered when data changes
|
||||||
const registerCallback = (callback: SongInfoCallback) => {
|
const registerCallback = (callback: SongInfoCallback) => {
|
||||||
callbacks.push(callback);
|
callbacks.add(callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
let handlingData = false;
|
let handlingData = false;
|
||||||
|
|||||||
26
src/tray.ts
26
src/tray.ts
@ -117,17 +117,19 @@ export const setUpTray = (app: Electron.App, win: Electron.BrowserWindow) => {
|
|||||||
const trayMenu = Menu.buildFromTemplate(template);
|
const trayMenu = Menu.buildFromTemplate(template);
|
||||||
tray.setContextMenu(trayMenu);
|
tray.setContextMenu(trayMenu);
|
||||||
|
|
||||||
registerCallback(songInfo => {
|
registerCallback((songInfo) => {
|
||||||
if (typeof songInfo.isPaused === 'undefined') {
|
if (tray) {
|
||||||
tray.setImage(defaultTrayIcon);
|
if (typeof songInfo.isPaused === 'undefined') {
|
||||||
return;
|
tray.setImage(defaultTrayIcon);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tray.setToolTip(t('main.tray.tooltip.with-song-info', {
|
||||||
|
artist: songInfo.artist,
|
||||||
|
title: songInfo.title,
|
||||||
|
}));
|
||||||
|
|
||||||
|
tray.setImage(songInfo.isPaused ? pausedTrayIcon : defaultTrayIcon);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
tray.setToolTip(t('main.tray.tooltip.with-song-info', {
|
|
||||||
artist: songInfo.artist,
|
|
||||||
title: songInfo.title,
|
|
||||||
}));
|
|
||||||
|
|
||||||
tray.setImage(songInfo.isPaused ? pausedTrayIcon : defaultTrayIcon);
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user