mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 10:11:46 +00:00
fix: image path
This commit is contained in:
@ -26,6 +26,7 @@
|
||||
"!node_modules/**/*.map",
|
||||
"!node_modules/**/*.ts"
|
||||
],
|
||||
"asarUnpack": ["assets"],
|
||||
"mac": {
|
||||
"identity": null,
|
||||
"target": [
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import { app, BrowserWindow, ipcMain, Notification } from 'electron';
|
||||
|
||||
import { notificationImage, secondsToMinutes, ToastStyles } from './utils';
|
||||
@ -9,7 +7,12 @@ 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, mediaIcons, saveMediaIcon } from '../utils';
|
||||
import { mediaIcons } from '../utils';
|
||||
|
||||
import playIcon from '../../../assets/media-icons-black/play.png?asset&asarUnpack';
|
||||
import pauseIcon from '../../../assets/media-icons-black/pause.png?asset&asarUnpack';
|
||||
import nextIcon from '../../../assets/media-icons-black/next.png?asset&asarUnpack';
|
||||
import previousIcon from '../../../assets/media-icons-black/previous.png?asset&asarUnpack';
|
||||
|
||||
let songControls: ReturnType<typeof getSongControls>;
|
||||
let savedNotification: Notification | undefined;
|
||||
@ -22,10 +25,6 @@ export default (win: BrowserWindow) => {
|
||||
|
||||
ipcMain.on('timeChanged', (_, t: number) => currentSeconds = t);
|
||||
|
||||
if (app.isPackaged) {
|
||||
saveMediaIcon();
|
||||
}
|
||||
|
||||
let savedSongInfo: SongInfo;
|
||||
let lastUrl: string | undefined;
|
||||
|
||||
@ -152,6 +151,22 @@ const getXml = (songInfo: SongInfo, iconSrc: string) => {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const selectIcon = (kind: keyof typeof mediaIcons): string => {
|
||||
switch (kind) {
|
||||
case 'play':
|
||||
return playIcon;
|
||||
case 'pause':
|
||||
return pauseIcon;
|
||||
case 'next':
|
||||
return nextIcon;
|
||||
case 'previous':
|
||||
return previousIcon;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
const display = (kind: keyof typeof mediaIcons) => {
|
||||
if (config.get('toastStyle') === ToastStyles.legacy) {
|
||||
return `content="${mediaIcons[kind]}"`;
|
||||
@ -159,7 +174,7 @@ const display = (kind: keyof typeof mediaIcons) => {
|
||||
|
||||
return `\
|
||||
content="${config.get('hideButtonText') ? '' : kind.charAt(0).toUpperCase() + kind.slice(1)}"\
|
||||
imageUri="file:///${path.resolve(getMediaIconLocation(), `${kind}.png`)}"
|
||||
imageUri="file:///${selectIcon(kind)}"
|
||||
`;
|
||||
};
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ import config from './config';
|
||||
import { cache } from '../../providers/decorators';
|
||||
import { SongInfo } from '../../providers/song-info';
|
||||
|
||||
import youtubeMusicIcon from '../../../assets/youtube-music.png?asset';
|
||||
import youtubeMusicIcon from '../../../assets/youtube-music.png?asset&asarUnpack';
|
||||
|
||||
|
||||
const userData = app.getPath('userData');
|
||||
|
||||
@ -1,20 +1,19 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import { app, BrowserWindow, nativeImage } from 'electron';
|
||||
import { BrowserWindow, nativeImage } from 'electron';
|
||||
|
||||
import getSongControls from '../../providers/song-controls';
|
||||
import registerCallback, { SongInfo } from '../../providers/song-info';
|
||||
import { getMediaIconLocation, saveMediaIcon } from '../utils';
|
||||
import { mediaIcons } from '../utils';
|
||||
|
||||
import playIcon from '../../../assets/media-icons-black/play.png?asset&asarUnpack';
|
||||
import pauseIcon from '../../../assets/media-icons-black/pause.png?asset&asarUnpack';
|
||||
import nextIcon from '../../../assets/media-icons-black/next.png?asset&asarUnpack';
|
||||
import previousIcon from '../../../assets/media-icons-black/previous.png?asset&asarUnpack';
|
||||
|
||||
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) {
|
||||
@ -47,8 +46,19 @@ export default (win: BrowserWindow) => {
|
||||
};
|
||||
|
||||
// Util
|
||||
const get = (kind: string) => {
|
||||
return path.join(getMediaIconLocation(), `${kind}.png`);
|
||||
const get = (kind: keyof typeof mediaIcons): string => {
|
||||
switch (kind) {
|
||||
case 'play':
|
||||
return playIcon;
|
||||
case 'pause':
|
||||
return pauseIcon;
|
||||
case 'next':
|
||||
return nextIcon;
|
||||
case 'previous':
|
||||
return previousIcon;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
registerCallback((songInfo) => {
|
||||
|
||||
@ -1,18 +1,9 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
import { app } from 'electron';
|
||||
import is from 'electron-is';
|
||||
|
||||
import defaultConfig from '../config/defaults';
|
||||
|
||||
export const getAssetsDirectoryLocation = () => path.resolve(__dirname, '..', 'assets');
|
||||
|
||||
export const getMediaIconLocation = () =>
|
||||
app.isPackaged
|
||||
? path.resolve(app.getPath('userData'), 'icons')
|
||||
: path.resolve(getAssetsDirectoryLocation(), 'media-icons-black');
|
||||
|
||||
export const mediaIcons = {
|
||||
play: '\u{1405}', // ᐅ
|
||||
pause: '\u{2016}', // ‖
|
||||
@ -20,19 +11,6 @@ export const mediaIcons = {
|
||||
previous: '\u{1438}', // ᐸ
|
||||
} as const;
|
||||
|
||||
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, () => {});
|
||||
}
|
||||
};
|
||||
|
||||
export const fileExists = (
|
||||
path: fs.PathLike,
|
||||
callbackIfExists: { (): void; (): void; (): void; },
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import youtubeMusicTrayIcon from '../../assets/youtube-music-tray.png?asset';
|
||||
import youtubeMusicTrayIcon from '../../assets/youtube-music-tray.png?asset&asarUnpack';
|
||||
|
||||
const promptOptions = {
|
||||
customStylesheet: 'dark',
|
||||
|
||||
@ -4,7 +4,7 @@ import { restart } from './providers/app-controls';
|
||||
import config from './config';
|
||||
import getSongControls from './providers/song-controls';
|
||||
|
||||
import youtubeMusicTrayIcon from '../assets/youtube-music-tray.png?asset';
|
||||
import youtubeMusicTrayIcon from '../assets/youtube-music-tray.png?asset&asarUnpack';
|
||||
|
||||
import type { MenuTemplate } from './menu';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user