From cb3d8d64fa73e6493d556ddcc0aba4c48cfc3f3d Mon Sep 17 00:00:00 2001 From: Youwes09 Date: Wed, 10 Jun 2026 13:06:46 -0500 Subject: [PATCH] Fix: DiscordRPC Toggle (Un-tested) --- src/lib/core/discord.ts | 9 +++++++-- src/routes/+layout.svelte | 13 ++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/lib/core/discord.ts b/src/lib/core/discord.ts index b7d2165..0b5f8e5 100644 --- a/src/lib/core/discord.ts +++ b/src/lib/core/discord.ts @@ -49,23 +49,27 @@ function buildPresence(manga: Manga, chapter: Chapter, coverUrl: string) { export async function initRpc(): Promise { if (!platformService.isSupported('discord-rpc')) return + if (!settingsState.settings.discordRpc) return sessionStart = Date.now() } export async function destroyRpc(): Promise { if (!platformService.isSupported('discord-rpc')) return - sessionStart = null + sessionStart = null + activeMangaId = null + await platformService.clearDiscordPresence() } export async function setReading(manga: Manga, chapter: Chapter): Promise { if (!platformService.isSupported('discord-rpc')) return - + if (!settingsState.settings.discordRpc) return activeMangaId = manga.id await platformService.setDiscordPresence(buildPresence(manga, chapter, resolveCoverUrl(manga))) } export async function setIdle(): Promise { if (!platformService.isSupported('discord-rpc')) return + if (!settingsState.settings.discordRpc) return await platformService.setDiscordPresence({ details: 'Browsing', timestamps: { start: sessionStart ?? Date.now() }, @@ -76,5 +80,6 @@ export async function setIdle(): Promise { export async function clearReading(): Promise { if (!platformService.isSupported('discord-rpc')) return + if (!settingsState.settings.discordRpc) return await platformService.clearDiscordPresence() } \ No newline at end of file diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index d16a939..c648036 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -105,11 +105,6 @@ isTauri && settingsState.settings.autoStartServer ? 2000 : 100, ) - if (settingsState.settings.discordRpc) { - await discord.initRpc() - await discord.setIdle() - } - polling = true pollLoop() @@ -142,6 +137,14 @@ if (appState.status === 'booting') splashDismissed = false }) + $effect(() => { + if (settingsState.settings.discordRpc) { + discord.initRpc().then(() => discord.setIdle()) + } else { + discord.destroyRpc() + } + }) + let idleTimer: ReturnType | null = null let idleDismissLock = false