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
This commit is contained in:
pizzaboxer 2023-08-05 01:03:33 +01:00
parent 871bf2f9b1
commit b22d72a1b8
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8

View File

@ -9,6 +9,7 @@ namespace Bloxstrap.Integrations
private DiscordRPC.RichPresence? _currentPresence; private DiscordRPC.RichPresence? _currentPresence;
private DiscordRPC.RichPresence? _currentPresenceCopy; private DiscordRPC.RichPresence? _currentPresenceCopy;
private Message? _stashedRPCMessage;
private bool _visible = true; private bool _visible = true;
private long _currentUniverseId; private long _currentUniverseId;
@ -55,6 +56,13 @@ namespace Bloxstrap.Integrations
if (_currentPresence is null || _currentPresenceCopy is null) 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"); App.Logger.WriteLine(LOG_IDENT, "Presence is not set, aborting");
return; return;
} }
@ -173,7 +181,10 @@ namespace Bloxstrap.Integrations
if (!_activityWatcher.ActivityInGame) if (!_activityWatcher.ActivityInGame)
{ {
App.Logger.WriteLine(LOG_IDENT, "Not in game, clearing presence"); App.Logger.WriteLine(LOG_IDENT, "Not in game, clearing presence");
_currentPresence = _currentPresenceCopy = null; _currentPresence = _currentPresenceCopy = null;
_stashedRPCMessage = null;
UpdatePresence(); UpdatePresence();
return true; return true;
} }
@ -268,7 +279,16 @@ namespace Bloxstrap.Integrations
// this is used for configuration from BloxstrapRPC // this is used for configuration from BloxstrapRPC
_currentPresenceCopy = _currentPresence.Clone(); _currentPresenceCopy = _currentPresence.Clone();
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(); UpdatePresence();
}
return true; return true;
} }