Skip to content

Commit fbf4b3b

Browse files
committed
fix: missing icons taskbar-mediacontrol
1 parent 5812eb0 commit fbf4b3b

File tree

4 files changed

+35
-32
lines changed

4 files changed

+35
-32
lines changed

plugins/notifications/interactive.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import path from 'node:path';
22

33
import { app, BrowserWindow, ipcMain, Notification } from 'electron';
44

5-
import { icons, notificationImage, saveTempIcon, secondsToMinutes, ToastStyles } from './utils';
5+
import { notificationImage, secondsToMinutes, ToastStyles } from './utils';
66
import config from './config';
77

88
import getSongControls from '../../providers/song-controls';
99
import registerCallback, { SongInfo } from '../../providers/song-info';
1010
import { changeProtocolHandler } from '../../providers/protocol-handler';
1111
import { setTrayOnClick, setTrayOnDoubleClick } from '../../tray';
12-
import { getMediaIconLocation } from '../utils';
12+
import { getMediaIconLocation, mediaIcons, saveMediaIcon } from '../utils';
1313

1414
let songControls: ReturnType<typeof getSongControls>;
1515
let savedNotification: Notification | undefined;
@@ -23,7 +23,7 @@ export default (win: BrowserWindow) => {
2323
ipcMain.on('timeChanged', (_, t: number) => currentSeconds = t);
2424

2525
if (app.isPackaged) {
26-
saveTempIcon();
26+
saveMediaIcon();
2727
}
2828

2929
let savedSongInfo: SongInfo;
@@ -152,9 +152,9 @@ const getXml = (songInfo: SongInfo, iconSrc: string) => {
152152
}
153153
}
154154
};
155-
const display = (kind: keyof typeof icons) => {
155+
const display = (kind: keyof typeof mediaIcons) => {
156156
if (config.get('toastStyle') === ToastStyles.legacy) {
157-
return `content="${icons[kind]}"`;
157+
return `content="${mediaIcons[kind]}"`;
158158
}
159159

160160
return `\
@@ -163,7 +163,7 @@ const display = (kind: keyof typeof icons) => {
163163
`;
164164
};
165165

166-
const getButton = (kind: keyof typeof icons) =>
166+
const getButton = (kind: keyof typeof mediaIcons) =>
167167
`<action ${display(kind)} activationType="protocol" arguments="youtubemusic://${kind}"/>`;
168168

169169
const getButtons = (isPaused: boolean) => `\

plugins/notifications/utils.ts

+3-23
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { cache } from '../../providers/decorators';
99
import { SongInfo } from '../../providers/song-info';
1010
import { getAssetsDirectoryLocation } from '../utils';
1111

12-
const icon = 'assets/youtube-music.png';
12+
const defaultIcon = path.join(getAssetsDirectoryLocation(), 'youtube-music.png');
1313
const userData = app.getPath('userData');
1414
const temporaryIcon = path.join(userData, 'tempIcon.png');
1515
const temporaryBanner = path.join(userData, 'tempBanner.png');
@@ -25,13 +25,6 @@ export const ToastStyles = {
2525
legacy: 7,
2626
};
2727

28-
export const icons = {
29-
play: '\u{1405}', // ᐅ
30-
pause: '\u{2016}', // ‖
31-
next: '\u{1433}', // ᐳ
32-
previous: '\u{1438}', // ᐸ
33-
};
34-
3528
export const urgencyLevels = [
3629
{ name: 'Low', value: 'low' },
3730
{ name: 'Normal', value: 'normal' },
@@ -52,7 +45,7 @@ const nativeImageToLogo = cache((nativeImage: NativeImage) => {
5245

5346
export const notificationImage = (songInfo: SongInfo) => {
5447
if (!songInfo.image) {
55-
return icon;
48+
return defaultIcon;
5649
}
5750

5851
if (!config.get('interactive')) {
@@ -76,25 +69,12 @@ export const saveImage = cache((img: NativeImage, savePath: string) => {
7669
fs.writeFileSync(savePath, img.toPNG());
7770
} catch (error: unknown) {
7871
console.log(`Error writing song icon to disk:\n${String(error)}`);
79-
return icon;
72+
return defaultIcon;
8073
}
8174

8275
return savePath;
8376
});
8477

85-
export const saveTempIcon = () => {
86-
for (const kind of Object.keys(icons)) {
87-
const destinationPath = path.join(userData, 'icons', `${kind}.png`);
88-
if (fs.existsSync(destinationPath)) {
89-
continue;
90-
}
91-
92-
const iconPath = path.resolve(path.resolve(getAssetsDirectoryLocation(), 'media-icons-black'), `${kind}.png`);
93-
fs.mkdirSync(path.dirname(destinationPath), { recursive: true });
94-
fs.copyFile(iconPath, destinationPath, () => {});
95-
}
96-
};
97-
9878
export const snakeToCamel = (string_: string) => string_.replaceAll(/([-_][a-z]|^[a-z])/g, (group) =>
9979
group.toUpperCase()
10080
.replace('-', ' ')

plugins/taskbar-mediacontrol/back.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import path from 'node:path';
22

3-
import { BrowserWindow, nativeImage } from 'electron';
3+
import { app, BrowserWindow, nativeImage } from 'electron';
44

55
import getSongControls from '../../providers/song-controls';
66
import registerCallback, { SongInfo } from '../../providers/song-info';
7-
import { getMediaIconLocation } from '../utils';
7+
import { getMediaIconLocation, saveMediaIcon } from '../utils';
88

99
export default (win: BrowserWindow) => {
1010
let currentSongInfo: SongInfo;
1111

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

14+
if (app.isPackaged) {
15+
saveMediaIcon();
16+
}
17+
1418
const setThumbar = (win: BrowserWindow, songInfo: SongInfo) => {
1519
// Wait for song to start before setting thumbar
1620
if (!songInfo?.title) {

plugins/utils.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import fs from 'node:fs';
22
import path from 'node:path';
33

44
import { app, ipcMain, ipcRenderer } from 'electron';
5-
65
import is from 'electron-is';
76

87
import { ValueOf } from '../utils/type-utils';
@@ -15,6 +14,26 @@ export const getMediaIconLocation = () =>
1514
? path.resolve(app.getPath('userData'), 'icons')
1615
: path.resolve(getAssetsDirectoryLocation(), 'media-icons-black');
1716

17+
export const mediaIcons = {
18+
play: '\u{1405}', // ᐅ
19+
pause: '\u{2016}', // ‖
20+
next: '\u{1433}', // ᐳ
21+
previous: '\u{1438}', // ᐸ
22+
};
23+
24+
export const saveMediaIcon = () => {
25+
for (const kind of Object.keys(mediaIcons)) {
26+
const destinationPath = path.join(getMediaIconLocation(), `${kind}.png`);
27+
if (fs.existsSync(destinationPath)) {
28+
continue;
29+
}
30+
31+
const iconPath = path.resolve(path.resolve(getAssetsDirectoryLocation(), 'media-icons-black'), `${kind}.png`);
32+
fs.mkdirSync(path.dirname(destinationPath), { recursive: true });
33+
fs.copyFile(iconPath, destinationPath, () => {});
34+
}
35+
};
36+
1837
// Creates a DOM element from an HTML string
1938
export const ElementFromHtml = (html: string): HTMLElement => {
2039
const template = document.createElement('template');

0 commit comments

Comments
 (0)