mirror of
https://github.com/moku-project/Moku.git
synced 2026-06-13 09:19:56 -05:00
Fix: DiscordRPC Toggle (Un-tested)
This commit is contained in:
@@ -49,23 +49,27 @@ function buildPresence(manga: Manga, chapter: Chapter, coverUrl: string) {
|
|||||||
|
|
||||||
export async function initRpc(): Promise<void> {
|
export async function initRpc(): Promise<void> {
|
||||||
if (!platformService.isSupported('discord-rpc')) return
|
if (!platformService.isSupported('discord-rpc')) return
|
||||||
|
if (!settingsState.settings.discordRpc) return
|
||||||
sessionStart = Date.now()
|
sessionStart = Date.now()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function destroyRpc(): Promise<void> {
|
export async function destroyRpc(): Promise<void> {
|
||||||
if (!platformService.isSupported('discord-rpc')) return
|
if (!platformService.isSupported('discord-rpc')) return
|
||||||
sessionStart = null
|
sessionStart = null
|
||||||
|
activeMangaId = null
|
||||||
|
await platformService.clearDiscordPresence()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setReading(manga: Manga, chapter: Chapter): Promise<void> {
|
export async function setReading(manga: Manga, chapter: Chapter): Promise<void> {
|
||||||
if (!platformService.isSupported('discord-rpc')) return
|
if (!platformService.isSupported('discord-rpc')) return
|
||||||
|
if (!settingsState.settings.discordRpc) return
|
||||||
activeMangaId = manga.id
|
activeMangaId = manga.id
|
||||||
await platformService.setDiscordPresence(buildPresence(manga, chapter, resolveCoverUrl(manga)))
|
await platformService.setDiscordPresence(buildPresence(manga, chapter, resolveCoverUrl(manga)))
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setIdle(): Promise<void> {
|
export async function setIdle(): Promise<void> {
|
||||||
if (!platformService.isSupported('discord-rpc')) return
|
if (!platformService.isSupported('discord-rpc')) return
|
||||||
|
if (!settingsState.settings.discordRpc) return
|
||||||
await platformService.setDiscordPresence({
|
await platformService.setDiscordPresence({
|
||||||
details: 'Browsing',
|
details: 'Browsing',
|
||||||
timestamps: { start: sessionStart ?? Date.now() },
|
timestamps: { start: sessionStart ?? Date.now() },
|
||||||
@@ -76,5 +80,6 @@ export async function setIdle(): Promise<void> {
|
|||||||
|
|
||||||
export async function clearReading(): Promise<void> {
|
export async function clearReading(): Promise<void> {
|
||||||
if (!platformService.isSupported('discord-rpc')) return
|
if (!platformService.isSupported('discord-rpc')) return
|
||||||
|
if (!settingsState.settings.discordRpc) return
|
||||||
await platformService.clearDiscordPresence()
|
await platformService.clearDiscordPresence()
|
||||||
}
|
}
|
||||||
@@ -105,11 +105,6 @@
|
|||||||
isTauri && settingsState.settings.autoStartServer ? 2000 : 100,
|
isTauri && settingsState.settings.autoStartServer ? 2000 : 100,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (settingsState.settings.discordRpc) {
|
|
||||||
await discord.initRpc()
|
|
||||||
await discord.setIdle()
|
|
||||||
}
|
|
||||||
|
|
||||||
polling = true
|
polling = true
|
||||||
pollLoop()
|
pollLoop()
|
||||||
|
|
||||||
@@ -142,6 +137,14 @@
|
|||||||
if (appState.status === 'booting') splashDismissed = false
|
if (appState.status === 'booting') splashDismissed = false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (settingsState.settings.discordRpc) {
|
||||||
|
discord.initRpc().then(() => discord.setIdle())
|
||||||
|
} else {
|
||||||
|
discord.destroyRpc()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
let idleTimer: ReturnType<typeof setTimeout> | null = null
|
let idleTimer: ReturnType<typeof setTimeout> | null = null
|
||||||
let idleDismissLock = false
|
let idleDismissLock = false
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user