mirror of
https://github.com/vrcx-team/VRCX.git
synced 2026-04-06 00:32:02 +02:00
Fix Discord RPC 3
This commit is contained in:
19
Discord.cs
19
Discord.cs
@@ -17,6 +17,7 @@ namespace VRCX
|
||||
private readonly RichPresence m_Presence;
|
||||
private DiscordRpcClient m_Client;
|
||||
private Timer m_Timer;
|
||||
private bool m_Active;
|
||||
public static string DiscordAppId;
|
||||
|
||||
static Discord()
|
||||
@@ -61,7 +62,7 @@ namespace VRCX
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (m_Client == null)
|
||||
if (m_Client == null && m_Active)
|
||||
{
|
||||
m_Client = new DiscordRpcClient(DiscordAppId);
|
||||
if (m_Client.Initialize() == false)
|
||||
@@ -71,6 +72,12 @@ namespace VRCX
|
||||
}
|
||||
}
|
||||
|
||||
if (m_Client != null && !m_Active)
|
||||
{
|
||||
m_Client.Dispose();
|
||||
m_Client = null;
|
||||
}
|
||||
|
||||
if (m_Client != null && !m_Lock.IsWriteLockHeld)
|
||||
{
|
||||
m_Lock.EnterReadLock();
|
||||
@@ -86,14 +93,10 @@ namespace VRCX
|
||||
}
|
||||
}
|
||||
|
||||
public void SetInactive()
|
||||
public bool SetActive(bool active)
|
||||
{
|
||||
if (m_Client != null)
|
||||
{
|
||||
m_Client.ClearPresence();
|
||||
m_Client.Dispose();
|
||||
m_Client = null;
|
||||
}
|
||||
m_Active = active;
|
||||
return m_Active;
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/1225052/best-way-to-shorten-utf8-string-based-on-byte-length
|
||||
|
||||
@@ -4140,6 +4140,7 @@ speechSynthesis.getVoices();
|
||||
ipcTimeout: 0,
|
||||
nextClearVRCXCacheCheck: 0,
|
||||
nextDiscordUpdate: 0,
|
||||
isDiscordActive: false,
|
||||
isGameRunning: false,
|
||||
isGameNoVR: configRepository.getBool('isGameNoVR'),
|
||||
isSteamVRRunning: false,
|
||||
@@ -4281,7 +4282,9 @@ speechSynthesis.getVoices();
|
||||
}
|
||||
if (--this.nextDiscordUpdate <= 0) {
|
||||
this.nextDiscordUpdate = 7;
|
||||
this.updateDiscord();
|
||||
if (this.discordActive) {
|
||||
this.updateDiscord();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -7882,6 +7885,7 @@ speechSynthesis.getVoices();
|
||||
configRepository.setBool('discordHideInvite', this.discordHideInvite);
|
||||
configRepository.setBool('discordHideImage', this.discordHideImage);
|
||||
this.lastLocation$.tag = '';
|
||||
this.nextDiscordUpdate = 7;
|
||||
this.updateDiscord();
|
||||
};
|
||||
|
||||
@@ -10002,9 +10006,10 @@ speechSynthesis.getVoices();
|
||||
!this.isGameRunning ||
|
||||
(!currentLocation && !this.lastLocation$.tag)
|
||||
) {
|
||||
Discord.SetInactive();
|
||||
this.setDiscordActive(false);
|
||||
return;
|
||||
}
|
||||
this.setDiscordActive(true);
|
||||
var L = this.lastLocation$;
|
||||
if (currentLocation !== this.lastLocation$.tag) {
|
||||
Discord.SetTimestamps(timeStamp, 0);
|
||||
@@ -10172,6 +10177,12 @@ speechSynthesis.getVoices();
|
||||
}
|
||||
};
|
||||
|
||||
$app.methods.setDiscordActive = async function (active) {
|
||||
if (active !== this.isDiscordActive) {
|
||||
this.isDiscordActive = await Discord.SetActive(active);
|
||||
}
|
||||
};
|
||||
|
||||
$app.methods.lookupUser = async function (ref) {
|
||||
if (ref.userId) {
|
||||
this.showUserDialog(ref.userId);
|
||||
|
||||
Reference in New Issue
Block a user