fix: missing icons taskbar-mediacontrol

This commit is contained in:
JellyBrick
2023-10-08 19:41:39 +09:00
parent 5812eb0147
commit fbf4b3b8b5
4 changed files with 35 additions and 32 deletions

View File

@ -2,14 +2,14 @@ import path from 'node:path';
import { app, BrowserWindow, ipcMain, Notification } from 'electron';
import { icons, notificationImage, saveTempIcon, secondsToMinutes, ToastStyles } from './utils';
import { notificationImage, secondsToMinutes, ToastStyles } from './utils';
import config from './config';
import getSongControls from '../../providers/song-controls';
import registerCallback, { SongInfo } from '../../providers/song-info';
import { changeProtocolHandler } from '../../providers/protocol-handler';
import { setTrayOnClick, setTrayOnDoubleClick } from '../../tray';
import { getMediaIconLocation } from '../utils';
import { getMediaIconLocation, mediaIcons, saveMediaIcon } from '../utils';
let songControls: ReturnType<typeof getSongControls>;
let savedNotification: Notification | undefined;
@ -23,7 +23,7 @@ export default (win: BrowserWindow) => {
ipcMain.on('timeChanged', (_, t: number) => currentSeconds = t);
if (app.isPackaged) {
saveTempIcon();
saveMediaIcon();
}
let savedSongInfo: SongInfo;
@ -152,9 +152,9 @@ const getXml = (songInfo: SongInfo, iconSrc: string) => {
}
}
};
const display = (kind: keyof typeof icons) => {
const display = (kind: keyof typeof mediaIcons) => {
if (config.get('toastStyle') === ToastStyles.legacy) {
return `content="${icons[kind]}"`;
return `content="${mediaIcons[kind]}"`;
}
return `\
@ -163,7 +163,7 @@ const display = (kind: keyof typeof icons) => {
`;
};
const getButton = (kind: keyof typeof icons) =>
const getButton = (kind: keyof typeof mediaIcons) =>
`<action ${display(kind)} activationType="protocol" arguments="youtubemusic://${kind}"/>`;
const getButtons = (isPaused: boolean) => `\

View File

@ -9,7 +9,7 @@ import { cache } from '../../providers/decorators';
import { SongInfo } from '../../providers/song-info';
import { getAssetsDirectoryLocation } from '../utils';
const icon = 'assets/youtube-music.png';
const defaultIcon = path.join(getAssetsDirectoryLocation(), 'youtube-music.png');
const userData = app.getPath('userData');
const temporaryIcon = path.join(userData, 'tempIcon.png');
const temporaryBanner = path.join(userData, 'tempBanner.png');
@ -25,13 +25,6 @@ export const ToastStyles = {
legacy: 7,
};
export const icons = {
play: '\u{1405}', // ᐅ
pause: '\u{2016}', // ‖
next: '\u{1433}', //
previous: '\u{1438}', //
};
export const urgencyLevels = [
{ name: 'Low', value: 'low' },
{ name: 'Normal', value: 'normal' },
@ -52,7 +45,7 @@ const nativeImageToLogo = cache((nativeImage: NativeImage) => {
export const notificationImage = (songInfo: SongInfo) => {
if (!songInfo.image) {
return icon;
return defaultIcon;
}
if (!config.get('interactive')) {
@ -76,25 +69,12 @@ export const saveImage = cache((img: NativeImage, savePath: string) => {
fs.writeFileSync(savePath, img.toPNG());
} catch (error: unknown) {
console.log(`Error writing song icon to disk:\n${String(error)}`);
return icon;
return defaultIcon;
}
return savePath;
});
export const saveTempIcon = () => {
for (const kind of Object.keys(icons)) {
const destinationPath = path.join(userData, 'icons', `${kind}.png`);
if (fs.existsSync(destinationPath)) {
continue;
}
const iconPath = path.resolve(path.resolve(getAssetsDirectoryLocation(), 'media-icons-black'), `${kind}.png`);
fs.mkdirSync(path.dirname(destinationPath), { recursive: true });
fs.copyFile(iconPath, destinationPath, () => {});
}
};
export const snakeToCamel = (string_: string) => string_.replaceAll(/([-_][a-z]|^[a-z])/g, (group) =>
group.toUpperCase()
.replace('-', ' ')