Make rpc show that the user is idle when they are idle

This commit is contained in:
2025-09-28 20:43:22 -07:00
parent 2a9e16aeaf
commit 1a193f017a

View File

@@ -7,6 +7,10 @@ public class DiscordRPCHandler : MonoBehaviour
public DiscordRpcClient client; public DiscordRpcClient client;
private readonly Timestamps timestamp = Timestamps.Now; private readonly Timestamps timestamp = Timestamps.Now;
private bool isIdle = false;
private string savedDetails;
private string savedState;
void Awake() void Awake()
{ {
if (Application.isMobilePlatform || Instance != null) if (Application.isMobilePlatform || Instance != null)
@@ -27,8 +31,28 @@ public class DiscordRPCHandler : MonoBehaviour
client.Dispose(); 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 client.SetPresence(new RichPresence
{ {
Details = details, Details = details,
@@ -47,5 +71,8 @@ public class DiscordRPCHandler : MonoBehaviour
}, },
Timestamps = timestamp Timestamps = timestamp
}); });
savedDetails = details;
savedState = state;
} }
} }