Fix Discord RPC 2

This commit is contained in:
Natsumi
2022-08-26 19:32:55 +12:00
parent 66153e3be1
commit bfaefd3694
2 changed files with 26 additions and 32 deletions

View File

@@ -61,7 +61,17 @@ namespace VRCX
private void Update() private void Update()
{ {
if (m_Client != null) if (m_Client == null)
{
m_Client = new DiscordRpcClient(DiscordAppId);
if (m_Client.Initialize() == false)
{
m_Client.Dispose();
m_Client = null;
}
}
if (m_Client != null && !m_Lock.IsWriteLockHeld)
{ {
m_Lock.EnterReadLock(); m_Lock.EnterReadLock();
try try
@@ -76,24 +86,14 @@ namespace VRCX
} }
} }
public void SetActive(bool active) public void SetInactive()
{ {
if (!active && m_Client != null) if (m_Client != null)
{ {
m_Client.ClearPresence(); m_Client.ClearPresence();
m_Client.Dispose(); m_Client.Dispose();
m_Client = null; m_Client = null;
} }
if (active && m_Client == null)
{
m_Client = new DiscordRpcClient(DiscordAppId);
if (m_Client.Initialize() == false)
{
m_Client.Dispose();
m_Client = null;
}
}
} }
// https://stackoverflow.com/questions/1225052/best-way-to-shorten-utf8-string-based-on-byte-length // https://stackoverflow.com/questions/1225052/best-way-to-shorten-utf8-string-based-on-byte-length
@@ -113,6 +113,8 @@ namespace VRCX
} }
public void SetText(string details, string state) public void SetText(string details, string state)
{
if (m_Client != null && !m_Lock.IsReadLockHeld)
{ {
m_Lock.EnterWriteLock(); m_Lock.EnterWriteLock();
try try
@@ -125,6 +127,7 @@ namespace VRCX
m_Lock.ExitWriteLock(); m_Lock.ExitWriteLock();
} }
} }
}
public void SetAssets(string largeKey, string largeText, string smallKey, string smallText, string partyId, int partySize, int partyMax, string buttonText, string buttonUrl, string appId) public void SetAssets(string largeKey, string largeText, string smallKey, string smallText, string partyId, int partySize, int partyMax, string buttonText, string buttonUrl, string appId)
{ {

View File

@@ -4274,7 +4274,7 @@ speechSynthesis.getVoices();
this.lastLocationReset(); this.lastLocationReset();
this.clearNowPlaying(); this.clearNowPlaying();
this.updateVRLastLocation(); this.updateVRLastLocation();
this.setDiscordActive(isGameRunning); this.nextDiscordUpdate = 0;
} }
if (isSteamVRRunning !== this.isSteamVRRunning) { if (isSteamVRRunning !== this.isSteamVRRunning) {
this.isSteamVRRunning = isSteamVRRunning; this.isSteamVRRunning = isSteamVRRunning;
@@ -7881,7 +7881,6 @@ speechSynthesis.getVoices();
configRepository.setBool('discordJoinButton', this.discordJoinButton); configRepository.setBool('discordJoinButton', this.discordJoinButton);
configRepository.setBool('discordHideInvite', this.discordHideInvite); configRepository.setBool('discordHideInvite', this.discordHideInvite);
configRepository.setBool('discordHideImage', this.discordHideImage); configRepository.setBool('discordHideImage', this.discordHideImage);
this.setDiscordActive(this.isGameRunning);
this.lastLocation$.tag = ''; this.lastLocation$.tag = '';
this.updateDiscord(); this.updateDiscord();
}; };
@@ -10003,6 +10002,7 @@ speechSynthesis.getVoices();
!this.isGameRunning || !this.isGameRunning ||
(!currentLocation && !this.lastLocation$.tag) (!currentLocation && !this.lastLocation$.tag)
) { ) {
Discord.SetInactive();
return; return;
} }
var L = this.lastLocation$; var L = this.lastLocation$;
@@ -10172,15 +10172,6 @@ speechSynthesis.getVoices();
} }
}; };
$app.methods.setDiscordActive = function (isGameRunning) {
if (this.discordActive && isGameRunning) {
Discord.SetActive(true);
} else {
Discord.SetText('', '');
Discord.SetActive(false);
}
};
$app.methods.lookupUser = async function (ref) { $app.methods.lookupUser = async function (ref) {
if (ref.userId) { if (ref.userId) {
this.showUserDialog(ref.userId); this.showUserDialog(ref.userId);