Merge pull request #1283 from th-ch/fix/missing-taskbar-mediacontrol-icons

This commit is contained in:
JellyBrick
2023-10-08 19:57:50 +09:00
committed by GitHub
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('-', ' ')

View File

@ -1,16 +1,20 @@
import path from 'node:path';
import { BrowserWindow, nativeImage } from 'electron';
import { app, BrowserWindow, nativeImage } from 'electron';
import getSongControls from '../../providers/song-controls';
import registerCallback, { SongInfo } from '../../providers/song-info';
import { getMediaIconLocation } from '../utils';
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) {

View File

@ -2,7 +2,6 @@ import fs from 'node:fs';
import path from 'node:path';
import { app, ipcMain, ipcRenderer } from 'electron';
import is from 'electron-is';
import { ValueOf } from '../utils/type-utils';
@ -15,6 +14,26 @@ export const getMediaIconLocation = () =>
? path.resolve(app.getPath('userData'), 'icons')
: path.resolve(getAssetsDirectoryLocation(), 'media-icons-black');
export const mediaIcons = {
play: '\u{1405}', // ᐅ
pause: '\u{2016}', // ‖
next: '\u{1433}', //
previous: '\u{1438}', //
};
export const saveMediaIcon = () => {
for (const kind of Object.keys(mediaIcons)) {
const destinationPath = path.join(getMediaIconLocation(), `${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, () => {});
}
};
// Creates a DOM element from an HTML string
export const ElementFromHtml = (html: string): HTMLElement => {
const template = document.createElement('template');