mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-16 04:41:47 +00:00
fix: missing icons taskbar-mediacontrol
This commit is contained in:
@ -2,14 +2,14 @@ import path from 'node:path';
|
|||||||
|
|
||||||
import { app, BrowserWindow, ipcMain, Notification } from 'electron';
|
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 config from './config';
|
||||||
|
|
||||||
import getSongControls from '../../providers/song-controls';
|
import getSongControls from '../../providers/song-controls';
|
||||||
import registerCallback, { SongInfo } from '../../providers/song-info';
|
import registerCallback, { SongInfo } from '../../providers/song-info';
|
||||||
import { changeProtocolHandler } from '../../providers/protocol-handler';
|
import { changeProtocolHandler } from '../../providers/protocol-handler';
|
||||||
import { setTrayOnClick, setTrayOnDoubleClick } from '../../tray';
|
import { setTrayOnClick, setTrayOnDoubleClick } from '../../tray';
|
||||||
import { getMediaIconLocation } from '../utils';
|
import { getMediaIconLocation, mediaIcons, saveMediaIcon } from '../utils';
|
||||||
|
|
||||||
let songControls: ReturnType<typeof getSongControls>;
|
let songControls: ReturnType<typeof getSongControls>;
|
||||||
let savedNotification: Notification | undefined;
|
let savedNotification: Notification | undefined;
|
||||||
@ -23,7 +23,7 @@ export default (win: BrowserWindow) => {
|
|||||||
ipcMain.on('timeChanged', (_, t: number) => currentSeconds = t);
|
ipcMain.on('timeChanged', (_, t: number) => currentSeconds = t);
|
||||||
|
|
||||||
if (app.isPackaged) {
|
if (app.isPackaged) {
|
||||||
saveTempIcon();
|
saveMediaIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
let savedSongInfo: SongInfo;
|
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) {
|
if (config.get('toastStyle') === ToastStyles.legacy) {
|
||||||
return `content="${icons[kind]}"`;
|
return `content="${mediaIcons[kind]}"`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `\
|
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}"/>`;
|
`<action ${display(kind)} activationType="protocol" arguments="youtubemusic://${kind}"/>`;
|
||||||
|
|
||||||
const getButtons = (isPaused: boolean) => `\
|
const getButtons = (isPaused: boolean) => `\
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import { cache } from '../../providers/decorators';
|
|||||||
import { SongInfo } from '../../providers/song-info';
|
import { SongInfo } from '../../providers/song-info';
|
||||||
import { getAssetsDirectoryLocation } from '../utils';
|
import { getAssetsDirectoryLocation } from '../utils';
|
||||||
|
|
||||||
const icon = 'assets/youtube-music.png';
|
const defaultIcon = path.join(getAssetsDirectoryLocation(), 'youtube-music.png');
|
||||||
const userData = app.getPath('userData');
|
const userData = app.getPath('userData');
|
||||||
const temporaryIcon = path.join(userData, 'tempIcon.png');
|
const temporaryIcon = path.join(userData, 'tempIcon.png');
|
||||||
const temporaryBanner = path.join(userData, 'tempBanner.png');
|
const temporaryBanner = path.join(userData, 'tempBanner.png');
|
||||||
@ -25,13 +25,6 @@ export const ToastStyles = {
|
|||||||
legacy: 7,
|
legacy: 7,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const icons = {
|
|
||||||
play: '\u{1405}', // ᐅ
|
|
||||||
pause: '\u{2016}', // ‖
|
|
||||||
next: '\u{1433}', // ᐳ
|
|
||||||
previous: '\u{1438}', // ᐸ
|
|
||||||
};
|
|
||||||
|
|
||||||
export const urgencyLevels = [
|
export const urgencyLevels = [
|
||||||
{ name: 'Low', value: 'low' },
|
{ name: 'Low', value: 'low' },
|
||||||
{ name: 'Normal', value: 'normal' },
|
{ name: 'Normal', value: 'normal' },
|
||||||
@ -52,7 +45,7 @@ const nativeImageToLogo = cache((nativeImage: NativeImage) => {
|
|||||||
|
|
||||||
export const notificationImage = (songInfo: SongInfo) => {
|
export const notificationImage = (songInfo: SongInfo) => {
|
||||||
if (!songInfo.image) {
|
if (!songInfo.image) {
|
||||||
return icon;
|
return defaultIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config.get('interactive')) {
|
if (!config.get('interactive')) {
|
||||||
@ -76,25 +69,12 @@ export const saveImage = cache((img: NativeImage, savePath: string) => {
|
|||||||
fs.writeFileSync(savePath, img.toPNG());
|
fs.writeFileSync(savePath, img.toPNG());
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.log(`Error writing song icon to disk:\n${String(error)}`);
|
console.log(`Error writing song icon to disk:\n${String(error)}`);
|
||||||
return icon;
|
return defaultIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
return savePath;
|
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) =>
|
export const snakeToCamel = (string_: string) => string_.replaceAll(/([-_][a-z]|^[a-z])/g, (group) =>
|
||||||
group.toUpperCase()
|
group.toUpperCase()
|
||||||
.replace('-', ' ')
|
.replace('-', ' ')
|
||||||
|
|||||||
@ -1,16 +1,20 @@
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
|
||||||
import { BrowserWindow, nativeImage } from 'electron';
|
import { app, BrowserWindow, nativeImage } from 'electron';
|
||||||
|
|
||||||
import getSongControls from '../../providers/song-controls';
|
import getSongControls from '../../providers/song-controls';
|
||||||
import registerCallback, { SongInfo } from '../../providers/song-info';
|
import registerCallback, { SongInfo } from '../../providers/song-info';
|
||||||
import { getMediaIconLocation } from '../utils';
|
import { getMediaIconLocation, saveMediaIcon } from '../utils';
|
||||||
|
|
||||||
export default (win: BrowserWindow) => {
|
export default (win: BrowserWindow) => {
|
||||||
let currentSongInfo: SongInfo;
|
let currentSongInfo: SongInfo;
|
||||||
|
|
||||||
const { playPause, next, previous } = getSongControls(win);
|
const { playPause, next, previous } = getSongControls(win);
|
||||||
|
|
||||||
|
if (app.isPackaged) {
|
||||||
|
saveMediaIcon();
|
||||||
|
}
|
||||||
|
|
||||||
const setThumbar = (win: BrowserWindow, songInfo: SongInfo) => {
|
const setThumbar = (win: BrowserWindow, songInfo: SongInfo) => {
|
||||||
// Wait for song to start before setting thumbar
|
// Wait for song to start before setting thumbar
|
||||||
if (!songInfo?.title) {
|
if (!songInfo?.title) {
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import fs from 'node:fs';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
|
||||||
import { app, ipcMain, ipcRenderer } from 'electron';
|
import { app, ipcMain, ipcRenderer } from 'electron';
|
||||||
|
|
||||||
import is from 'electron-is';
|
import is from 'electron-is';
|
||||||
|
|
||||||
import { ValueOf } from '../utils/type-utils';
|
import { ValueOf } from '../utils/type-utils';
|
||||||
@ -15,6 +14,26 @@ export const getMediaIconLocation = () =>
|
|||||||
? path.resolve(app.getPath('userData'), 'icons')
|
? path.resolve(app.getPath('userData'), 'icons')
|
||||||
: path.resolve(getAssetsDirectoryLocation(), 'media-icons-black');
|
: 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
|
// Creates a DOM element from an HTML string
|
||||||
export const ElementFromHtml = (html: string): HTMLElement => {
|
export const ElementFromHtml = (html: string): HTMLElement => {
|
||||||
const template = document.createElement('template');
|
const template = document.createElement('template');
|
||||||
|
|||||||
Reference in New Issue
Block a user