From b22d72a1b8bbc1829abccb78493485b48cebb3d8 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Sat, 5 Aug 2023 01:03:33 +0100 Subject: [PATCH] Allow for rich presence to be set on game join better title: Allow for rich presence to be set through BloxstrapRPC on immediate game join --- Bloxstrap/Integrations/DiscordRichPresence.cs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Bloxstrap/Integrations/DiscordRichPresence.cs b/Bloxstrap/Integrations/DiscordRichPresence.cs index 1444b36..5d74c73 100644 --- a/Bloxstrap/Integrations/DiscordRichPresence.cs +++ b/Bloxstrap/Integrations/DiscordRichPresence.cs @@ -9,6 +9,7 @@ namespace Bloxstrap.Integrations private DiscordRPC.RichPresence? _currentPresence; private DiscordRPC.RichPresence? _currentPresenceCopy; + private Message? _stashedRPCMessage; private bool _visible = true; private long _currentUniverseId; @@ -55,6 +56,13 @@ namespace Bloxstrap.Integrations if (_currentPresence is null || _currentPresenceCopy is null) { + if (_activityWatcher.ActivityInGame) + { + App.Logger.WriteLine(LOG_IDENT, "Presence is not yet set, but is currently in game, stashing presence set request"); + _stashedRPCMessage = message; + return; + } + App.Logger.WriteLine(LOG_IDENT, "Presence is not set, aborting"); return; } @@ -173,7 +181,10 @@ namespace Bloxstrap.Integrations if (!_activityWatcher.ActivityInGame) { App.Logger.WriteLine(LOG_IDENT, "Not in game, clearing presence"); - _currentPresence = _currentPresenceCopy = null; + + _currentPresence = _currentPresenceCopy = null; + _stashedRPCMessage = null; + UpdatePresence(); return true; } @@ -268,7 +279,16 @@ namespace Bloxstrap.Integrations // this is used for configuration from BloxstrapRPC _currentPresenceCopy = _currentPresence.Clone(); - UpdatePresence(); + if (_stashedRPCMessage is not null) + { + App.Logger.WriteLine(LOG_IDENT, "Found stashed RPC message, invoking presence set command now"); + ProcessRPCMessage(_stashedRPCMessage); + _stashedRPCMessage = null; + } + else + { + UpdatePresence(); + } return true; }