mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-18 06:13:52 +02:00
Fix Discord RPC
This commit is contained in:
35
Discord.cs
35
Discord.cs
@@ -17,7 +17,6 @@ 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()
|
||||
@@ -75,35 +74,33 @@ namespace VRCX
|
||||
}
|
||||
m_Client.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_Active == true)
|
||||
{
|
||||
if (m_Client == null)
|
||||
{
|
||||
m_Client = new DiscordRpcClient(DiscordAppId);
|
||||
if (m_Client.Initialize() == false)
|
||||
{
|
||||
m_Client.Dispose();
|
||||
m_Client = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (m_Client != null)
|
||||
public void SetActive(bool active)
|
||||
{
|
||||
if (!active && m_Client != null)
|
||||
{
|
||||
m_Client.ClearPresence();
|
||||
m_Client.Dispose();
|
||||
m_Client = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetActive(bool active)
|
||||
{
|
||||
m_Active = active;
|
||||
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
|
||||
private static string LimitByteLength(string str, int maxBytesLength)
|
||||
{
|
||||
if (str == null)
|
||||
return string.Empty;
|
||||
var bytesArr = Encoding.UTF8.GetBytes(str);
|
||||
var bytesToRemove = 0;
|
||||
var lastIndexInString = str.Length - 1;
|
||||
@@ -216,4 +213,4 @@ namespace VRCX
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ speechSynthesis.getVoices();
|
||||
} else if (e.key === 'r') {
|
||||
location.reload();
|
||||
}
|
||||
} else if (e.key === 'R') {
|
||||
} else if (e.altKey && e.key === 'R') {
|
||||
$app.refreshCustomCss();
|
||||
}
|
||||
});
|
||||
@@ -4139,6 +4139,7 @@ speechSynthesis.getVoices();
|
||||
nextAppUpdateCheck: 0,
|
||||
ipcTimeout: 0,
|
||||
nextClearVRCXCacheCheck: 0,
|
||||
nextDiscordUpdate: 0,
|
||||
isGameRunning: false,
|
||||
isGameNoVR: configRepository.getBool('isGameNoVR'),
|
||||
isSteamVRRunning: false,
|
||||
@@ -4267,7 +4268,7 @@ speechSynthesis.getVoices();
|
||||
);
|
||||
API.currentUser.$online_for = '';
|
||||
API.currentUser.$offline_for = Date.now();
|
||||
Discord.SetActive(false);
|
||||
this.setDiscordActive(isGameRunning);
|
||||
this.autoVRChatCacheManagement();
|
||||
this.ipcTimeout = 0;
|
||||
}
|
||||
@@ -4278,7 +4279,10 @@ speechSynthesis.getVoices();
|
||||
if (isSteamVRRunning !== this.isSteamVRRunning) {
|
||||
this.isSteamVRRunning = isSteamVRRunning;
|
||||
}
|
||||
this.updateDiscord();
|
||||
if (--this.nextDiscordUpdate <= 0) {
|
||||
this.nextDiscordUpdate = 7;
|
||||
this.updateDiscord();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -7877,10 +7881,7 @@ speechSynthesis.getVoices();
|
||||
configRepository.setBool('discordJoinButton', this.discordJoinButton);
|
||||
configRepository.setBool('discordHideInvite', this.discordHideInvite);
|
||||
configRepository.setBool('discordHideImage', this.discordHideImage);
|
||||
if (!this.discordActive) {
|
||||
Discord.SetText('', '');
|
||||
Discord.SetActive(false);
|
||||
}
|
||||
this.setDiscordActive(this.isGameRunning);
|
||||
this.lastLocation$.tag = '';
|
||||
this.updateDiscord();
|
||||
};
|
||||
@@ -10006,9 +10007,6 @@ speechSynthesis.getVoices();
|
||||
}
|
||||
var L = this.lastLocation$;
|
||||
if (currentLocation !== this.lastLocation$.tag) {
|
||||
if (currentLocation) {
|
||||
Discord.SetActive(true);
|
||||
}
|
||||
Discord.SetTimestamps(timeStamp, 0);
|
||||
L = API.parseLocation(currentLocation);
|
||||
L.worldName = '';
|
||||
@@ -10174,6 +10172,15 @@ 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) {
|
||||
if (ref.userId) {
|
||||
this.showUserDialog(ref.userId);
|
||||
|
||||
Reference in New Issue
Block a user