Fix: Home-Screen Argument for RPC & Total Time

This commit is contained in:
Youwes09
2026-03-29 17:35:25 -05:00
parent 8aa2dc2547
commit 581eb2adb0
4 changed files with 69 additions and 14 deletions
+11 -3
View File
@@ -5,6 +5,8 @@ import type { Manga, Chapter } from "./types";
const APP_ID = "1487894643613106298";
const FALLBACK_IMAGE = "moku_logo";
let sessionStart: number | null = null; // ← captured once on init
function isPublicUrl(url: string | null | undefined): boolean {
return typeof url === "string" && url.startsWith("https://");
}
@@ -22,12 +24,17 @@ function formatChapter(chapter: Chapter): string {
return `Chapter ${Number.isInteger(n) ? n : n.toFixed(1)}`;
}
function getTimestamps(): Timestamps {
return new Timestamps(sessionStart ?? Date.now());
}
const BUTTONS = [
new Button("GitHub", "https://github.com/Youwes09/Moku"),
new Button("Discord", "https://discord.gg/Jq3pwuNqPp"),
];
export async function initRpc(): Promise<void> {
sessionStart = Date.now(); // ← set once here
await start(APP_ID)
.then(() => console.log("[discord] RPC started"))
.catch((e) => console.error("[discord] initRpc failed:", e));
@@ -44,7 +51,7 @@ export async function setReading(manga: Manga, chapter: Chapter): Promise<void>
.setDetails(trunc(manga.title))
.setState(`${formatChapter(chapter)} · Reading`)
.setAssets(assets)
.setTimestamps(new Timestamps(Date.now()));
.setTimestamps(getTimestamps()); // ← reuses session start
activity.setButton(BUTTONS);
await setActivity(activity)
@@ -60,7 +67,7 @@ export async function setIdle(): Promise<void> {
const activity = new Activity()
.setDetails("Browsing")
.setAssets(assets)
.setTimestamps(new Timestamps(Date.now()));
.setTimestamps(getTimestamps()); // ← reuses session start
activity.setButton(BUTTONS);
await setActivity(activity)
@@ -75,7 +82,8 @@ export async function clearReading(): Promise<void> {
}
export async function destroyRpc(): Promise<void> {
sessionStart = null; // ← clean up on stop
await stop()
.then(() => console.log("[discord] RPC stopped"))
.catch((e) => console.error("[discord] destroyRpc failed:", e));
}
}