chore: improve readability

This commit is contained in:
Su-Yong
2025-10-12 14:28:29 +09:00
parent 4f716d8e0b
commit ffa61687bf
137 changed files with 2625 additions and 2626 deletions

View File

@ -24,7 +24,7 @@ import * as config from '@/config';
import { LoggerPrefix } from '@/utils';
import type { RepeatMode, VolumeState } from '@/types/datahost-get-state';
import type { QueueResponse } from '@/types/youtube-music-desktop-internal';
import type { QueueResponse } from '@/types/music-player-desktop-internal';
class YTPlayer extends MprisPlayer {
/**
@ -70,8 +70,8 @@ class YTPlayer extends MprisPlayer {
function setupMPRIS() {
const instance = new YTPlayer({
name: 'YoutubeMusic',
identity: 'YouTube Music',
name: 'PearDesktop',
identity: 'Pear Desktop',
supportedMimeTypes: ['audio/mpeg'],
supportedInterfaces: ['player'],
});
@ -80,7 +80,7 @@ function setupMPRIS() {
instance.canQuit = false;
instance.canUsePlayerControls = true;
instance.supportedUriSchemes = ['http', 'https'];
instance.desktopEntry = 'youtube-music';
instance.desktopEntry = 'pear-desktop';
return instance;
}
@ -114,34 +114,34 @@ export function registerMPRIS(win: BrowserWindow) {
currentSongInfo?.videoId &&
event.trackId.endsWith(correctId(currentSongInfo.videoId))
) {
win.webContents.send('ytmd:seek-to', microToSec(event.position ?? 0));
win.webContents.send('peard:seek-to', microToSec(event.position ?? 0));
player.setPosition(event.position ?? 0);
}
};
const seekBy = (offset: number) => {
win.webContents.send('ytmd:seek-by', microToSec(offset));
win.webContents.send('peard:seek-by', microToSec(offset));
player.setPosition(player.getPosition() + offset);
};
ipcMain.on('ytmd:player-api-loaded', () => {
win.webContents.send('ytmd:setup-seeked-listener', 'mpris');
win.webContents.send('ytmd:setup-time-changed-listener', 'mpris');
win.webContents.send('ytmd:setup-repeat-changed-listener', 'mpris');
win.webContents.send('ytmd:setup-volume-changed-listener', 'mpris');
win.webContents.send('ytmd:setup-shuffle-changed-listener', 'mpris');
win.webContents.send('ytmd:setup-fullscreen-changed-listener', 'mpris');
win.webContents.send('ytmd:setup-autoplay-changed-listener', 'mpris');
ipcMain.on('peard:player-api-loaded', () => {
win.webContents.send('peard:setup-seeked-listener', 'mpris');
win.webContents.send('peard:setup-time-changed-listener', 'mpris');
win.webContents.send('peard:setup-repeat-changed-listener', 'mpris');
win.webContents.send('peard:setup-volume-changed-listener', 'mpris');
win.webContents.send('peard:setup-shuffle-changed-listener', 'mpris');
win.webContents.send('peard:setup-fullscreen-changed-listener', 'mpris');
win.webContents.send('peard:setup-autoplay-changed-listener', 'mpris');
requestShuffleInformation();
requestFullscreenInformation();
requestQueueInformation();
});
ipcMain.on('ytmd:seeked', (_, t: number) => {
ipcMain.on('peard:seeked', (_, t: number) => {
player.setPosition(secToMicro(t));
player.seeked(secToMicro(t));
});
ipcMain.on('ytmd:repeat-changed', (_, mode: RepeatMode) => {
ipcMain.on('peard:repeat-changed', (_, mode: RepeatMode) => {
switch (mode) {
case 'NONE': {
player.setLoopStatus(LOOP_STATUS_NONE);
@ -160,7 +160,7 @@ export function registerMPRIS(win: BrowserWindow) {
requestQueueInformation();
});
ipcMain.on('ytmd:shuffle-changed', (_, shuffleEnabled: boolean) => {
ipcMain.on('peard:shuffle-changed', (_, shuffleEnabled: boolean) => {
if (player.shuffle === undefined || !player.canUsePlayerControls) {
return;
}
@ -168,7 +168,7 @@ export function registerMPRIS(win: BrowserWindow) {
player.shuffle = shuffleEnabled ?? !player.shuffle;
});
ipcMain.on('ytmd:fullscreen-changed', (_, changedTo: boolean) => {
ipcMain.on('peard:fullscreen-changed', (_, changedTo: boolean) => {
if (player.fullscreen === undefined || !player.canUsePlayerControls) {
return;
}
@ -178,7 +178,7 @@ export function registerMPRIS(win: BrowserWindow) {
});
ipcMain.on(
'ytmd:set-fullscreen',
'peard:set-fullscreen',
(_, isFullscreen: boolean | undefined) => {
if (!player.canUsePlayerControls || isFullscreen === undefined) {
return;
@ -189,16 +189,16 @@ export function registerMPRIS(win: BrowserWindow) {
);
ipcMain.on(
'ytmd:fullscreen-changed-supported',
'peard:fullscreen-changed-supported',
(_, isFullscreenSupported: boolean) => {
player.canUsePlayerControls = isFullscreenSupported;
},
);
ipcMain.on('ytmd:autoplay-changed', (_) => {
ipcMain.on('peard:autoplay-changed', (_) => {
requestQueueInformation();
});
ipcMain.on('ytmd:get-queue-response', (_, queue: QueueResponse) => {
ipcMain.on('peard:get-queue-response', (_, queue: QueueResponse) => {
if (!queue) {
return;
}
@ -306,7 +306,7 @@ export function registerMPRIS(win: BrowserWindow) {
console.trace(error);
});
ipcMain.on('ytmd:volume-changed', (_, newVolumeState: VolumeState) => {
ipcMain.on('peard:volume-changed', (_, newVolumeState: VolumeState) => {
player.volume = newVolumeState.isMuted
? 0
: Number.parseFloat((newVolumeState.state / 100).toFixed(2));