mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
fix: discord RPC (fix #1664)
This commit is contained in:
@ -197,6 +197,7 @@
|
|||||||
"builtin-modules": "3.3.0",
|
"builtin-modules": "3.3.0",
|
||||||
"cross-env": "7.0.3",
|
"cross-env": "7.0.3",
|
||||||
"del-cli": "5.1.0",
|
"del-cli": "5.1.0",
|
||||||
|
"discord-api-types": "0.37.69",
|
||||||
"electron": "28.2.2",
|
"electron": "28.2.2",
|
||||||
"electron-builder": "24.9.1",
|
"electron-builder": "24.9.1",
|
||||||
"electron-devtools-installer": "3.2.0",
|
"electron-devtools-installer": "3.2.0",
|
||||||
|
|||||||
7
pnpm-lock.yaml
generated
7
pnpm-lock.yaml
generated
@ -200,6 +200,9 @@ devDependencies:
|
|||||||
del-cli:
|
del-cli:
|
||||||
specifier: 5.1.0
|
specifier: 5.1.0
|
||||||
version: 5.1.0
|
version: 5.1.0
|
||||||
|
discord-api-types:
|
||||||
|
specifier: 0.37.69
|
||||||
|
version: 0.37.69
|
||||||
electron:
|
electron:
|
||||||
specifier: 28.2.2
|
specifier: 28.2.2
|
||||||
version: 28.2.2
|
version: 28.2.2
|
||||||
@ -2987,6 +2990,10 @@ packages:
|
|||||||
path-type: 4.0.0
|
path-type: 4.0.0
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/discord-api-types@0.37.69:
|
||||||
|
resolution: {integrity: sha512-c0rHc5YGNIXQkI+V7QwP8y77wxo74ITNeZmMwxtKC/l01aIF/gKBG/U2MKhUt2iaeRH9XwAt9PT3AI9JQVvKVA==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/dmg-builder@24.9.1:
|
/dmg-builder@24.9.1:
|
||||||
resolution: {integrity: sha512-huC+O6hvHd24Ubj3cy2GMiGLe2xGFKN3klqVMLAdcbB6SWMd1yPSdZvV8W1O01ICzCCRlZDHiv4VrNUgnPUfbQ==}
|
resolution: {integrity: sha512-huC+O6hvHd24Ubj3cy2GMiGLe2xGFKN3klqVMLAdcbB6SWMd1yPSdZvV8W1O01ICzCCRlZDHiv4VrNUgnPUfbQ==}
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|||||||
@ -2,14 +2,12 @@ import { app, dialog, ipcMain } from 'electron';
|
|||||||
import { Client as DiscordClient } from '@xhayper/discord-rpc';
|
import { Client as DiscordClient } from '@xhayper/discord-rpc';
|
||||||
import { dev } from 'electron-is';
|
import { dev } from 'electron-is';
|
||||||
|
|
||||||
import { SetActivity } from '@xhayper/discord-rpc/dist/structures/ClientUser';
|
|
||||||
|
|
||||||
import registerCallback, { type SongInfo } from '@/providers/song-info';
|
import registerCallback, { type SongInfo } from '@/providers/song-info';
|
||||||
|
|
||||||
import { createBackend, LoggerPrefix } from '@/utils';
|
import { createBackend, LoggerPrefix } from '@/utils';
|
||||||
|
|
||||||
import { t } from '@/i18n';
|
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';
|
import type { DiscordPluginConfig } from './index';
|
||||||
|
|
||||||
// Application ID registered by @th-ch/youtube-music dev team
|
// 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 = {
|
const activityInfo: SetActivity = {
|
||||||
details: songInfo.title,
|
details: songInfo.title,
|
||||||
state: songInfo.artist,
|
state: songInfo.artist,
|
||||||
largeImageKey: songInfo.imageSrc ?? '',
|
largeImageKey: songInfo.imageSrc ?? '',
|
||||||
largeImageText: songInfo.album ?? '',
|
largeImageText: songInfo.album ?? '',
|
||||||
buttons: [
|
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',
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (songInfo.isPaused) {
|
if (songInfo.isPaused) {
|
||||||
|
|||||||
Reference in New Issue
Block a user