mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-19 14:53:50 +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 readonly RichPresence m_Presence;
|
||||||
private DiscordRpcClient m_Client;
|
private DiscordRpcClient m_Client;
|
||||||
private Timer m_Timer;
|
private Timer m_Timer;
|
||||||
|
private bool m_Active;
|
||||||
public static string DiscordAppId;
|
public static string DiscordAppId;
|
||||||
|
|
||||||
static Discord()
|
static Discord()
|
||||||
@@ -61,7 +62,7 @@ namespace VRCX
|
|||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (m_Client == null)
|
if (m_Client == null && m_Active)
|
||||||
{
|
{
|
||||||
m_Client = new DiscordRpcClient(DiscordAppId);
|
m_Client = new DiscordRpcClient(DiscordAppId);
|
||||||
if (m_Client.Initialize() == false)
|
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)
|
if (m_Client != null && !m_Lock.IsWriteLockHeld)
|
||||||
{
|
{
|
||||||
m_Lock.EnterReadLock();
|
m_Lock.EnterReadLock();
|
||||||
@@ -86,14 +93,10 @@ namespace VRCX
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetInactive()
|
public bool SetActive(bool active)
|
||||||
{
|
{
|
||||||
if (m_Client != null)
|
m_Active = active;
|
||||||
{
|
return m_Active;
|
||||||
m_Client.ClearPresence();
|
|
||||||
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
|
||||||
|
|||||||
@@ -4140,6 +4140,7 @@ speechSynthesis.getVoices();
|
|||||||
ipcTimeout: 0,
|
ipcTimeout: 0,
|
||||||
nextClearVRCXCacheCheck: 0,
|
nextClearVRCXCacheCheck: 0,
|
||||||
nextDiscordUpdate: 0,
|
nextDiscordUpdate: 0,
|
||||||
|
isDiscordActive: false,
|
||||||
isGameRunning: false,
|
isGameRunning: false,
|
||||||
isGameNoVR: configRepository.getBool('isGameNoVR'),
|
isGameNoVR: configRepository.getBool('isGameNoVR'),
|
||||||
isSteamVRRunning: false,
|
isSteamVRRunning: false,
|
||||||
@@ -4281,7 +4282,9 @@ speechSynthesis.getVoices();
|
|||||||
}
|
}
|
||||||
if (--this.nextDiscordUpdate <= 0) {
|
if (--this.nextDiscordUpdate <= 0) {
|
||||||
this.nextDiscordUpdate = 7;
|
this.nextDiscordUpdate = 7;
|
||||||
this.updateDiscord();
|
if (this.discordActive) {
|
||||||
|
this.updateDiscord();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -7882,6 +7885,7 @@ speechSynthesis.getVoices();
|
|||||||
configRepository.setBool('discordHideInvite', this.discordHideInvite);
|
configRepository.setBool('discordHideInvite', this.discordHideInvite);
|
||||||
configRepository.setBool('discordHideImage', this.discordHideImage);
|
configRepository.setBool('discordHideImage', this.discordHideImage);
|
||||||
this.lastLocation$.tag = '';
|
this.lastLocation$.tag = '';
|
||||||
|
this.nextDiscordUpdate = 7;
|
||||||
this.updateDiscord();
|
this.updateDiscord();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -10002,9 +10006,10 @@ speechSynthesis.getVoices();
|
|||||||
!this.isGameRunning ||
|
!this.isGameRunning ||
|
||||||
(!currentLocation && !this.lastLocation$.tag)
|
(!currentLocation && !this.lastLocation$.tag)
|
||||||
) {
|
) {
|
||||||
Discord.SetInactive();
|
this.setDiscordActive(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.setDiscordActive(true);
|
||||||
var L = this.lastLocation$;
|
var L = this.lastLocation$;
|
||||||
if (currentLocation !== this.lastLocation$.tag) {
|
if (currentLocation !== this.lastLocation$.tag) {
|
||||||
Discord.SetTimestamps(timeStamp, 0);
|
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) {
|
$app.methods.lookupUser = async function (ref) {
|
||||||
if (ref.userId) {
|
if (ref.userId) {
|
||||||
this.showUserDialog(ref.userId);
|
this.showUserDialog(ref.userId);
|
||||||
|
|||||||
Reference in New Issue
Block a user