From 1a193f017a39e22fe9c1a204cd614ae327e188d8 Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Sun, 28 Sep 2025 20:43:22 -0700 Subject: [PATCH] Make rpc show that the user is idle when they are idle --- Assets/Scripts/DiscordRPCHandler.cs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/DiscordRPCHandler.cs b/Assets/Scripts/DiscordRPCHandler.cs index e0462ad..5a372ee 100644 --- a/Assets/Scripts/DiscordRPCHandler.cs +++ b/Assets/Scripts/DiscordRPCHandler.cs @@ -7,6 +7,10 @@ public class DiscordRPCHandler : MonoBehaviour public DiscordRpcClient client; private readonly Timestamps timestamp = Timestamps.Now; + private bool isIdle = false; + private string savedDetails; + private string savedState; + void Awake() { if (Application.isMobilePlatform || Instance != null) @@ -27,8 +31,28 @@ public class DiscordRPCHandler : MonoBehaviour client.Dispose(); } - public void UpdateRPC(string details, string state) + void OnApplicationPause(bool pause) { + isIdle = pause; + if (pause) + { + UpdateRPC("Idle", null, true); + } + else + { + UpdateRPC(savedDetails, savedState, true); + } + } + + public void UpdateRPC(string details, string state, bool force = false) + { + if (!force && isIdle) + { + savedDetails = details; + savedState = state; + return; + } + client.SetPresence(new RichPresence { Details = details, @@ -47,5 +71,8 @@ public class DiscordRPCHandler : MonoBehaviour }, Timestamps = timestamp }); + + savedDetails = details; + savedState = state; } }