From eabb3392b4f7209f88aa46121550e5d00253e712 Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Tue, 13 Feb 2024 07:41:32 +0900 Subject: [PATCH] fix: discord RPC (fix #1664) --- package.json | 1 + pnpm-lock.yaml | 7 +++++++ src/plugins/discord/main.ts | 38 ++++++++++++++++++++----------------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 99b7dee0..fa828506 100644 --- a/package.json +++ b/package.json @@ -197,6 +197,7 @@ "builtin-modules": "3.3.0", "cross-env": "7.0.3", "del-cli": "5.1.0", + "discord-api-types": "0.37.69", "electron": "28.2.2", "electron-builder": "24.9.1", "electron-devtools-installer": "3.2.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 03a0722b..ddc4f1e7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -200,6 +200,9 @@ devDependencies: del-cli: specifier: 5.1.0 version: 5.1.0 + discord-api-types: + specifier: 0.37.69 + version: 0.37.69 electron: specifier: 28.2.2 version: 28.2.2 @@ -2987,6 +2990,10 @@ packages: path-type: 4.0.0 dev: true + /discord-api-types@0.37.69: + resolution: {integrity: sha512-c0rHc5YGNIXQkI+V7QwP8y77wxo74ITNeZmMwxtKC/l01aIF/gKBG/U2MKhUt2iaeRH9XwAt9PT3AI9JQVvKVA==} + dev: true + /dmg-builder@24.9.1: resolution: {integrity: sha512-huC+O6hvHd24Ubj3cy2GMiGLe2xGFKN3klqVMLAdcbB6SWMd1yPSdZvV8W1O01ICzCCRlZDHiv4VrNUgnPUfbQ==} dependencies: diff --git a/src/plugins/discord/main.ts b/src/plugins/discord/main.ts index f5b38344..582245de 100644 --- a/src/plugins/discord/main.ts +++ b/src/plugins/discord/main.ts @@ -2,14 +2,12 @@ import { app, dialog, ipcMain } from 'electron'; import { Client as DiscordClient } from '@xhayper/discord-rpc'; import { dev } from 'electron-is'; -import { SetActivity } from '@xhayper/discord-rpc/dist/structures/ClientUser'; - import registerCallback, { type SongInfo } from '@/providers/song-info'; - import { createBackend, LoggerPrefix } from '@/utils'; - import { t } from '@/i18n'; +import type { GatewayActivityButton } from 'discord-api-types/v10'; +import type { SetActivity } from '@xhayper/discord-rpc/dist/structures/ClientUser'; import type { DiscordPluginConfig } from './index'; // Application ID registered by @th-ch/youtube-music dev team @@ -163,24 +161,30 @@ export const backend = createBackend< ); } + // see https://github.com/th-ch/youtube-music/issues/1664 + let buttons: GatewayActivityButton[] | undefined = []; + if (config.playOnYouTubeMusic) { + buttons.push({ + label: 'Play on YouTube Music', + url: songInfo.url ?? 'https://music.youtube.com', + }); + } + if (!config.hideGitHubButton) { + buttons.push({ + label: 'View App On GitHub', + url: 'https://github.com/th-ch/youtube-music', + }); + } + if (buttons.length === 0) { + buttons = undefined; + } + const activityInfo: SetActivity = { details: songInfo.title, state: songInfo.artist, largeImageKey: songInfo.imageSrc ?? '', largeImageText: songInfo.album ?? '', - buttons: [ - ...(config.playOnYouTubeMusic - ? [{ label: 'Play on YouTube Music', url: songInfo.url ?? '' }] - : []), - ...(config.hideGitHubButton - ? [] - : [ - { - label: 'View App On GitHub', - url: 'https://github.com/th-ch/youtube-music', - }, - ]), - ], + buttons, }; if (songInfo.isPaused) {