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