From 25502c659056ac1784788f577e505d0f9968116a Mon Sep 17 00:00:00 2001 From: aliceenight <146655861+aliceenight@users.noreply.github.com> Date: Wed, 29 Apr 2026 00:19:58 +0200 Subject: [PATCH] CustomRPC custom timestamp looping (#1023) * Refactor timestamp handling and loop management * Added gemini changes * Update index.tsx * Update index.tsx --------- Co-authored-by: thororen <78185467+thororen1234@users.noreply.github.com> --- src/plugins/customRPC/index.tsx | 53 ++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/src/plugins/customRPC/index.tsx b/src/plugins/customRPC/index.tsx index bafff2c2e..774cba0e1 100644 --- a/src/plugins/customRPC/index.tsx +++ b/src/plugins/customRPC/index.tsx @@ -138,8 +138,14 @@ async function createActivity(): Promise { case TimestampMode.CUSTOM: if (startTime || endTime) { activity.timestamps = {}; - if (startTime) activity.timestamps.start = startTime; - if (endTime) activity.timestamps.end = endTime; + if (startTime && endTime && endTime > startTime) { + const anchor = getLoopAnchor(); + activity.timestamps.start = anchor; + activity.timestamps.end = anchor + (endTime - startTime); + } else { + if (startTime) activity.timestamps.start = startTime; + if (endTime) activity.timestamps.end = endTime; + } } break; case TimestampMode.NONE: @@ -212,6 +218,39 @@ export async function setRpc(disable?: boolean) { }); } +let loopInterval: ReturnType | undefined; +let loopAnchor = 0; + +function getLoopAnchor() { + return loopAnchor; +} + +function startTimestampLoop() { + const { timestampMode, startTime, endTime } = settings.store; + if (timestampMode !== TimestampMode.CUSTOM || !startTime || !endTime) return; + const duration = endTime - startTime; + if (duration <= 0) return; + + stopTimestampLoop(); + loopAnchor = Date.now(); + + loopInterval = setInterval(() => { + + if (Date.now() >= loopAnchor + duration) { + loopAnchor = Date.now(); + setRpc(); + } + }, 1000); +} + +function stopTimestampLoop() { + if (loopInterval !== undefined) { + clearInterval(loopInterval); + loopInterval = undefined; + } + loopAnchor = 0; +} + export default definePlugin({ name: "CustomRPC", description: "Add a fully customisable Rich Presence (Game status) to your Discord profile", @@ -222,8 +261,14 @@ export default definePlugin({ requiresRestart: false, settings, - start: setRpc, - stop: () => setRpc(true), + start() { + startTimestampLoop(); + setRpc(); + }, + stop() { + setRpc(true); + stopTimestampLoop(); + }, // Discord hides buttons on your own Rich Presence for some reason. This patch disables that behaviour patches: [