Skip to content

Commit

Permalink
feat(tray): Add song info and paused icon
Browse files Browse the repository at this point in the history
  • Loading branch information
Destroy666x committed Jan 5, 2024
1 parent ddb5619 commit 81e3e43
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
Binary file added assets/youtube-music-tray-paused.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/i18n/resources/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@
}
},
"tray": {
"tooltip": {
"default": "YouTube Music",
"with-song-info": "YouTube Music: {{artist}} - {{title}}"
},
"next": "Next",
"play-pause": "Play/Pause",
"previous": "Previous",
Expand Down
31 changes: 27 additions & 4 deletions src/tray.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Menu, nativeImage, Tray } from 'electron';

import youtubeMusicTrayIcon from '@assets/youtube-music-tray.png?asset&asarUnpack';
import defaultTrayIconAsset from '@assets/youtube-music-tray.png?asset&asarUnpack';
import pausedTrayIconAsset from '@assets/youtube-music-tray-paused.png?asset&asarUnpack';

import config from './config';

import { restart } from './providers/app-controls';
import registerCallback from './providers/song-info';
import getSongControls from './providers/song-controls';

import { t } from '@/i18n';
Expand Down Expand Up @@ -46,14 +48,18 @@ export const setUpTray = (app: Electron.App, win: Electron.BrowserWindow) => {

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

const trayIcon = nativeImage.createFromPath(youtubeMusicTrayIcon).resize({
const defaultTrayIcon = nativeImage.createFromPath(defaultTrayIconAsset).resize({
width: 16,
height: 16,
});
const pausedTrayIcon = nativeImage.createFromPath(pausedTrayIconAsset).resize({
width: 16,
height: 16,
});

tray = new Tray(trayIcon);
tray = new Tray(defaultTrayIcon);

tray.setToolTip('YouTube Music');
tray.setToolTip(t('main.tray.tooltip.default'));

// MacOS only
tray.setIgnoreDoubleClickEvents(true);
Expand Down Expand Up @@ -110,4 +116,21 @@ export const setUpTray = (app: Electron.App, win: Electron.BrowserWindow) => {

const trayMenu = Menu.buildFromTemplate(template);
tray.setContextMenu(trayMenu);

registerCallback(songInfo => {
if (typeof songInfo.isPaused === 'undefined') {
return;
}

tray.setToolTip(t('main.tray.tooltip.with-song-info', {
artist: songInfo.artist,
title: songInfo.title,
}));

if (songInfo.isPaused) {
tray.setImage(pausedTrayIcon);
} else {
tray.setImage(defaultTrayIcon);
}
})
};

0 comments on commit 81e3e43

Please sign in to comment.