mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-12 11:01:45 +00:00
fix: apply fix from eslint
This commit is contained in:
@ -9,10 +9,8 @@ export const restart = () => restartInternal();
|
||||
export const setupAppControls = () => {
|
||||
ipcMain.on('ytmd:restart', restart);
|
||||
ipcMain.handle('ytmd:get-downloads-folder', () => app.getPath('downloads'));
|
||||
ipcMain.on(
|
||||
'ytmd:reload',
|
||||
() =>
|
||||
BrowserWindow.getFocusedWindow()?.webContents.loadURL(config.get('url')),
|
||||
ipcMain.on('ytmd:reload', () =>
|
||||
BrowserWindow.getFocusedWindow()?.webContents.loadURL(config.get('url')),
|
||||
);
|
||||
ipcMain.handle('ytmd:get-path', (_, ...args: string[]) => path.join(...args));
|
||||
};
|
||||
|
||||
@ -80,7 +80,7 @@ function memoize<T extends (...params: unknown[]) => unknown>(fn: T): T {
|
||||
cache.set(key, fn(...args));
|
||||
}
|
||||
|
||||
return cache.get(key) as unknown;
|
||||
return cache.get(key);
|
||||
}) as T;
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,9 @@ import getSongControls from './song-controls';
|
||||
|
||||
export const APP_PROTOCOL = 'youtubemusic';
|
||||
|
||||
let protocolHandler: ((cmd: string, args: string[] | undefined) => void) | undefined;
|
||||
let protocolHandler:
|
||||
| ((cmd: string, args: string[] | undefined) => void)
|
||||
| undefined;
|
||||
|
||||
export function setupProtocolHandler(win: BrowserWindow) {
|
||||
if (process.defaultApp && process.argv.length >= 2) {
|
||||
@ -19,7 +21,10 @@ export function setupProtocolHandler(win: BrowserWindow) {
|
||||
|
||||
const songControls = getSongControls(win);
|
||||
|
||||
protocolHandler = ((cmd: keyof typeof songControls, args: string[] | undefined = undefined) => {
|
||||
protocolHandler = ((
|
||||
cmd: keyof typeof songControls,
|
||||
args: string[] | undefined = undefined,
|
||||
) => {
|
||||
if (Object.keys(songControls).includes(cmd)) {
|
||||
songControls[cmd](args as never);
|
||||
}
|
||||
@ -30,7 +35,9 @@ export function handleProtocol(cmd: string, args: string[] | undefined) {
|
||||
protocolHandler?.(cmd, args);
|
||||
}
|
||||
|
||||
export function changeProtocolHandler(f: (cmd: string, args: string[] | undefined) => void) {
|
||||
export function changeProtocolHandler(
|
||||
f: (cmd: string, args: string[] | undefined) => void,
|
||||
) {
|
||||
protocolHandler = f;
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,11 @@ import { singleton } from './decorators';
|
||||
|
||||
import type { YoutubePlayer } from '@/types/youtube-player';
|
||||
import type { GetState } from '@/types/datahost-get-state';
|
||||
import type { AlbumDetails, PlayerOverlays, VideoDataChangeValue } from '@/types/player-api-events';
|
||||
import type {
|
||||
AlbumDetails,
|
||||
PlayerOverlays,
|
||||
VideoDataChangeValue,
|
||||
} from '@/types/player-api-events';
|
||||
|
||||
import type { SongInfo } from './song-info';
|
||||
import type { VideoDataChanged } from '@/types/video-data-changed';
|
||||
@ -10,9 +14,12 @@ import type { VideoDataChanged } from '@/types/video-data-changed';
|
||||
let songInfo: SongInfo = {} as SongInfo;
|
||||
export const getSongInfo = () => songInfo;
|
||||
|
||||
window.ipcRenderer.on('ytmd:update-song-info', (_, extractedSongInfo: SongInfo) => {
|
||||
songInfo = extractedSongInfo;
|
||||
});
|
||||
window.ipcRenderer.on(
|
||||
'ytmd:update-song-info',
|
||||
(_, extractedSongInfo: SongInfo) => {
|
||||
songInfo = extractedSongInfo;
|
||||
},
|
||||
);
|
||||
|
||||
// Used because 'loadeddata' or 'loadedmetadata' weren't firing on song start for some users (https://github.com/th-ch/youtube-music/issues/473)
|
||||
const srcChangedEvent = new CustomEvent('ytmd:src-changed');
|
||||
@ -91,9 +98,8 @@ export const setupFullScreenChangedListener = singleton(() => {
|
||||
const observer = new MutationObserver(() => {
|
||||
window.ipcRenderer.send(
|
||||
'ytmd:fullscreen-changed',
|
||||
(
|
||||
playerBar?.attributes.getNamedItem('player-fullscreened') ?? null
|
||||
) !== null,
|
||||
(playerBar?.attributes.getNamedItem('player-fullscreened') ?? null) !==
|
||||
null,
|
||||
);
|
||||
});
|
||||
|
||||
@ -203,15 +209,19 @@ export default (api: YoutubePlayer) => {
|
||||
|
||||
if (!isNaN(video.duration)) {
|
||||
const {
|
||||
title, author,
|
||||
title,
|
||||
author,
|
||||
video_id: videoId,
|
||||
list: playlistId
|
||||
list: playlistId,
|
||||
} = api.getVideoData();
|
||||
|
||||
const watchNextResponse = api.getWatchNextResponse();
|
||||
|
||||
sendSongInfo({
|
||||
title, author, videoId, playlistId,
|
||||
title,
|
||||
author,
|
||||
videoId,
|
||||
playlistId,
|
||||
|
||||
isUpcoming: false,
|
||||
lengthSeconds: video.duration,
|
||||
@ -236,9 +246,10 @@ export default (api: YoutubePlayer) => {
|
||||
} else {
|
||||
playerOverlay = videoData.ytmdWatchNextResponse?.playerOverlays;
|
||||
}
|
||||
data.videoDetails.album = playerOverlay?.playerOverlayRenderer?.browserMediaSession?.browserMediaSessionRenderer?.album?.runs?.at(
|
||||
0,
|
||||
)?.text;
|
||||
data.videoDetails.album =
|
||||
playerOverlay?.playerOverlayRenderer?.browserMediaSession?.browserMediaSessionRenderer?.album?.runs?.at(
|
||||
0,
|
||||
)?.text;
|
||||
data.videoDetails.elapsedSeconds = 0;
|
||||
data.videoDetails.isPaused = false;
|
||||
|
||||
|
||||
@ -47,9 +47,7 @@ export interface SongInfo {
|
||||
export const getImage = async (src: string): Promise<Electron.NativeImage> => {
|
||||
const result = await net.fetch(src);
|
||||
const output = nativeImage.createFromBuffer(
|
||||
Buffer.from(
|
||||
await result.arrayBuffer(),
|
||||
),
|
||||
Buffer.from(await result.arrayBuffer()),
|
||||
);
|
||||
if (output.isEmpty() && !src.endsWith('.jpg') && src.includes('.jpg')) {
|
||||
// Fix hidden webp files (https://github.com/th-ch/youtube-music/issues/315)
|
||||
|
||||
Reference in New Issue
Block a user