mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 18:41:47 +00:00
feat: rename IPC
This commit is contained in:
@ -9,7 +9,25 @@ import { t } from '@/i18n';
|
||||
const COLOR_KEY = '--ytmusic-album-color';
|
||||
const DARK_COLOR_KEY = '--ytmusic-album-color-dark';
|
||||
|
||||
export default createPlugin({
|
||||
export default createPlugin<
|
||||
unknown,
|
||||
unknown,
|
||||
{
|
||||
color?: Color;
|
||||
darkColor?: Color;
|
||||
|
||||
playerPage: HTMLElement | null;
|
||||
navBarBackground: HTMLElement | null;
|
||||
ytmusicPlayerBar: HTMLElement | null;
|
||||
playerBarBackground: HTMLElement | null;
|
||||
sidebarBig: HTMLElement | null;
|
||||
sidebarSmall: HTMLElement | null;
|
||||
ytmusicAppLayout: HTMLElement | null;
|
||||
|
||||
getColor(key: string, alpha?: number): string;
|
||||
updateColor(): void;
|
||||
}
|
||||
>({
|
||||
name: () => t('plugins.album-color-theme.name'),
|
||||
description: () => t('plugins.album-color-theme.description'),
|
||||
restartNeeded: true,
|
||||
@ -18,16 +36,13 @@ export default createPlugin({
|
||||
},
|
||||
stylesheets: [style],
|
||||
renderer: {
|
||||
color: null as Color | null,
|
||||
darkColor: null as Color | null,
|
||||
|
||||
playerPage: null as HTMLElement | null,
|
||||
navBarBackground: null as HTMLElement | null,
|
||||
ytmusicPlayerBar: null as HTMLElement | null,
|
||||
playerBarBackground: null as HTMLElement | null,
|
||||
sidebarBig: null as HTMLElement | null,
|
||||
sidebarSmall: null as HTMLElement | null,
|
||||
ytmusicAppLayout: null as HTMLElement | null,
|
||||
playerPage: null,
|
||||
navBarBackground: null,
|
||||
ytmusicPlayerBar: null,
|
||||
playerBarBackground: null,
|
||||
sidebarBig: null,
|
||||
sidebarSmall: null,
|
||||
ytmusicAppLayout: null,
|
||||
|
||||
start() {
|
||||
this.playerPage = document.querySelector<HTMLElement>('#player-page');
|
||||
|
||||
@ -7,7 +7,7 @@ export default createPlugin({
|
||||
|
||||
renderer() {
|
||||
document.addEventListener(
|
||||
'audioCanPlay',
|
||||
'ytmd:audio-can-play',
|
||||
({ detail: { audioSource, audioContext } }) => {
|
||||
const compressor = audioContext.createDynamicsCompressor();
|
||||
|
||||
|
||||
@ -121,7 +121,7 @@ export default createRenderer<
|
||||
?.unloadModule('captions');
|
||||
document
|
||||
.querySelector('video')
|
||||
?.removeEventListener('srcChanged', this.videoChangeListener);
|
||||
?.removeEventListener('ytmd:src-changed', this.videoChangeListener);
|
||||
this.captionsSettingsButton.removeEventListener(
|
||||
'click',
|
||||
this.captionsButtonClickListener,
|
||||
@ -139,7 +139,7 @@ export default createRenderer<
|
||||
|
||||
document
|
||||
.querySelector('video')
|
||||
?.addEventListener('srcChanged', this.videoChangeListener);
|
||||
?.addEventListener('ytmd:src-changed', this.videoChangeListener);
|
||||
this.captionsSettingsButton.addEventListener(
|
||||
'click',
|
||||
this.captionsButtonClickListener,
|
||||
|
||||
@ -244,7 +244,7 @@ export const backend = createBackend<
|
||||
});
|
||||
connect();
|
||||
let lastSent = Date.now();
|
||||
ipcMain.on('timeChanged', (_, t: number) => {
|
||||
ipcMain.on('ytmd:time-changed', (_, t: number) => {
|
||||
const currentTime = Date.now();
|
||||
// if lastSent is more than 5 seconds ago, send the new time
|
||||
if (currentTime - lastSent > 5000) {
|
||||
|
||||
@ -110,7 +110,7 @@ export const onMainLoad = async ({
|
||||
fetch: getNetFetchAsFetch(),
|
||||
});
|
||||
ipc.handle('download-song', (url: string) => downloadSong(url));
|
||||
ipc.on('video-src-changed', (data: GetPlayerResponse) => {
|
||||
ipc.on('ytmd:video-src-changed', (data: GetPlayerResponse) => {
|
||||
playingUrl = data.microformat.microformatDataRenderer.urlCanonical;
|
||||
});
|
||||
ipc.handle('download-playlist-request', async (url: string) =>
|
||||
|
||||
@ -47,7 +47,7 @@ export const onMainLoad = ({
|
||||
return target;
|
||||
};
|
||||
|
||||
ipcMain.handle('menu-event', (event, commandId: number) => {
|
||||
ipcMain.handle('ytmd:menu-event', (event, commandId: number) => {
|
||||
const target = getMenuItemById(commandId);
|
||||
if (target)
|
||||
target.click(
|
||||
|
||||
@ -76,7 +76,7 @@ export const createPanel = (
|
||||
}
|
||||
|
||||
menu.addEventListener('click', async () => {
|
||||
await window.ipcRenderer.invoke('menu-event', item.commandId);
|
||||
await window.ipcRenderer.invoke('ytmd:menu-event', item.commandId);
|
||||
const menuItem = (await window.ipcRenderer.invoke(
|
||||
'get-menu-by-id',
|
||||
item.commandId,
|
||||
|
||||
@ -253,9 +253,9 @@ export default (
|
||||
songControls = getSongControls(win);
|
||||
|
||||
let currentSeconds = 0;
|
||||
on('ytmd:player-api-loaded', () => send('setupTimeChangedListener'));
|
||||
on('ytmd:player-api-loaded', () => send('ytmd:setup-time-changed-listener'));
|
||||
|
||||
on('timeChanged', (t: number) => {
|
||||
on('ytmd:time-changed', (t: number) => {
|
||||
currentSeconds = t;
|
||||
});
|
||||
|
||||
|
||||
@ -101,7 +101,7 @@ export const onMainLoad = async ({
|
||||
|
||||
config ??= await getConfig();
|
||||
setConfig({ isInPiP });
|
||||
on('picture-in-picture', () => {
|
||||
on('plugin:toggle-picture-in-picture', () => {
|
||||
togglePiP();
|
||||
});
|
||||
|
||||
|
||||
@ -90,7 +90,7 @@ const togglePictureInPicture = async () => {
|
||||
} catch {}
|
||||
}
|
||||
|
||||
window.ipcRenderer.send('picture-in-picture');
|
||||
window.ipcRenderer.send('plugin:toggle-picture-in-picture');
|
||||
return false;
|
||||
};
|
||||
// For UI (HTML)
|
||||
|
||||
@ -78,7 +78,7 @@ const observeVideo = () => {
|
||||
const video = document.querySelector<HTMLVideoElement>('video');
|
||||
if (video) {
|
||||
video.addEventListener('ratechange', forcePlaybackRate);
|
||||
video.addEventListener('srcChanged', forcePlaybackRate);
|
||||
video.addEventListener('ytmd:src-changed', forcePlaybackRate);
|
||||
}
|
||||
};
|
||||
|
||||
@ -128,7 +128,7 @@ export const onUnload = () => {
|
||||
const video = document.querySelector<HTMLVideoElement>('video');
|
||||
if (video) {
|
||||
video.removeEventListener('ratechange', forcePlaybackRate);
|
||||
video.removeEventListener('srcChanged', forcePlaybackRate);
|
||||
video.removeEventListener('ytmd:src-changed', forcePlaybackRate);
|
||||
}
|
||||
slider.removeEventListener('wheel', wheelEventListener);
|
||||
getSongMenu()?.removeChild(slider);
|
||||
|
||||
@ -71,7 +71,7 @@ export const onPlayerApiReady = async (
|
||||
const videoMode = () =>
|
||||
api.getPlayerResponse().videoDetails?.musicVideoType !==
|
||||
'MUSIC_VIDEO_TYPE_ATV';
|
||||
$('video')?.addEventListener('srcChanged', () =>
|
||||
$('video')?.addEventListener('ytmd:src-changed', () =>
|
||||
moveVolumeHud(videoMode()),
|
||||
);
|
||||
}
|
||||
|
||||
@ -29,25 +29,25 @@ function registerMPRIS(win: BrowserWindow) {
|
||||
const microToSec = (n: unknown) => Math.round(Number(n) / 1e6);
|
||||
|
||||
const seekTo = (e: { position: unknown }) =>
|
||||
win.webContents.send('seekTo', microToSec(e.position));
|
||||
win.webContents.send('ytmd:seek-to', microToSec(e.position));
|
||||
const seekBy = (o: unknown) =>
|
||||
win.webContents.send('seekBy', microToSec(o));
|
||||
win.webContents.send('ytmd:seek-by', microToSec(o));
|
||||
|
||||
const player = setupMPRIS();
|
||||
|
||||
ipcMain.on('ytmd:player-api-loaded', () => {
|
||||
win.webContents.send('setupSeekedListener', 'mpris');
|
||||
win.webContents.send('setupTimeChangedListener', 'mpris');
|
||||
win.webContents.send('setupRepeatChangedListener', 'mpris');
|
||||
win.webContents.send('setupVolumeChangedListener', 'mpris');
|
||||
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');
|
||||
});
|
||||
|
||||
ipcMain.on('seeked', (_, t: number) => player.seeked(secToMicro(t)));
|
||||
ipcMain.on('ytmd:seeked', (_, t: number) => player.seeked(secToMicro(t)));
|
||||
|
||||
let currentSeconds = 0;
|
||||
ipcMain.on('timeChanged', (_, t: number) => (currentSeconds = t));
|
||||
ipcMain.on('ytmd:time-changed', (_, t: number) => (currentSeconds = t));
|
||||
|
||||
ipcMain.on('repeatChanged', (_, mode: string) => {
|
||||
ipcMain.on('ytmd:repeat-changed', (_, mode: string) => {
|
||||
switch (mode) {
|
||||
case 'NONE': {
|
||||
player.loopStatus = mpris.LOOP_STATUS_NONE;
|
||||
@ -122,7 +122,7 @@ function registerMPRIS(win: BrowserWindow) {
|
||||
|
||||
let mprisVolNewer = false;
|
||||
let autoUpdate = false;
|
||||
ipcMain.on('volumeChanged', (_, newVol) => {
|
||||
ipcMain.on('ytmd:volume-changed', (_, newVol) => {
|
||||
if (~~(player.volume * 100) !== newVol) {
|
||||
if (mprisVolNewer) {
|
||||
mprisVolNewer = false;
|
||||
|
||||
@ -115,13 +115,13 @@ export const onRendererLoad = async ({
|
||||
}: RendererContext<SkipSilencesPluginConfig>) => {
|
||||
config = await getConfig();
|
||||
|
||||
document.addEventListener('audioCanPlay', audioCanPlayListener, {
|
||||
document.addEventListener('ytmd:audio-can-play', audioCanPlayListener, {
|
||||
passive: true,
|
||||
});
|
||||
};
|
||||
|
||||
export const onRendererUnload = () => {
|
||||
document.removeEventListener('audioCanPlay', audioCanPlayListener);
|
||||
document.removeEventListener('ytmd:audio-can-play', audioCanPlayListener);
|
||||
|
||||
if (playOrSeekHandler) {
|
||||
const video = document.querySelector('video');
|
||||
|
||||
@ -76,7 +76,7 @@ export default createPlugin({
|
||||
|
||||
const { apiURL, categories } = config;
|
||||
|
||||
ipc.on('video-src-changed', async (data: GetPlayerResponse) => {
|
||||
ipc.on('ytmd:video-src-changed', async (data: GetPlayerResponse) => {
|
||||
const segments = await fetchSegments(
|
||||
apiURL,
|
||||
categories,
|
||||
|
||||
@ -68,9 +68,9 @@ export default createPlugin({
|
||||
};
|
||||
|
||||
ipc.on('ytmd:player-api-loaded', () =>
|
||||
ipc.send('setupTimeChangedListener'),
|
||||
ipc.send('ytmd:setup-time-changed-listener'),
|
||||
);
|
||||
ipc.on('timeChanged', (t: number) => {
|
||||
ipc.on('ytmd:time-changed', (t: number) => {
|
||||
if (!this.data.title) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -305,7 +305,7 @@ export default createPlugin({
|
||||
setVideoState(target.checked);
|
||||
});
|
||||
|
||||
video?.addEventListener('srcChanged', videoStarted);
|
||||
video?.addEventListener('ytmd:src-changed', videoStarted);
|
||||
|
||||
observeThumbnail();
|
||||
|
||||
|
||||
@ -161,7 +161,7 @@ export default createPlugin({
|
||||
}
|
||||
|
||||
document.addEventListener(
|
||||
'audioCanPlay',
|
||||
'ytmd:audio-can-play',
|
||||
(e) => {
|
||||
const video = document.querySelector<
|
||||
HTMLVideoElement & { captureStream(): MediaStream }
|
||||
|
||||
Reference in New Issue
Block a user