Linux: Make Discord Rich Presence work (#998)

* Linux: Make Discord Rich Presence work

* Fix file already exists

* Fix chmod file name
This commit is contained in:
rs189
2024-12-01 11:00:30 +00:00
committed by GitHub
parent cd42a9a207
commit 5e6c611264
6 changed files with 69 additions and 21 deletions
+17 -2
View File
@@ -27,9 +27,24 @@ namespace VRCX
var isGameRunning = false; var isGameRunning = false;
var isSteamVRRunning = false; var isSteamVRRunning = false;
if (ProcessMonitor.Instance.IsProcessRunning("VRChat")) if (Wine.GetIfWine())
{ {
isGameRunning = true; var wineTmpPath = Path.Combine(Program.AppDataDirectory, "wine.tmp");
if (File.Exists(wineTmpPath))
{
var wineTmp = File.ReadAllText(wineTmpPath);
if (wineTmp.Contains("isGameRunning=true"))
{
isGameRunning = true;
}
}
}
else
{
if (ProcessMonitor.Instance.IsProcessRunning("VRChat"))
{
isGameRunning = true;
}
} }
if (ProcessMonitor.Instance.IsProcessRunning("vrserver")) if (ProcessMonitor.Instance.IsProcessRunning("vrserver"))
+17 -17
View File
@@ -1,23 +1,23 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace VRCX; namespace VRCX
public static class Wine
{ {
[DllImport("ntdll.dll")] public static class Wine
private static extern IntPtr wine_get_version();
public static bool GetIfWine()
{ {
// wine_get_version should be guaranteed to exist exclusively in Wine envs, [DllImport("ntdll.dll")]
// unlike some other suggestions like checking Wine registry keys private static extern IntPtr wine_get_version();
try
{
wine_get_version();
return true;
}
catch { return false; }
}
}
public static bool GetIfWine()
{
// wine_get_version should be guaranteed to exist exclusively in Wine envs,
// unlike some other suggestions like checking Wine registry keys
try
{
wine_get_version();
return true;
}
catch { return false; }
}
}
}
+6 -1
View File
@@ -83,6 +83,11 @@ cp seguiemj.ttf "$WINEPREFIX/drive_c/windows/Fonts"
WINEPREFIX=$WINEPREFIX wine reg add 'HKLM\Software\Microsoft\Windows NT\CurrentVersion\Fonts' /v 'seguiemj' /t REG_SZ /d 'seguiemj.ttf' /f WINEPREFIX=$WINEPREFIX wine reg add 'HKLM\Software\Microsoft\Windows NT\CurrentVersion\Fonts' /v 'seguiemj' /t REG_SZ /d 'seguiemj.ttf' /f
rm seguiemj.ttf rm seguiemj.ttf
curl -L https://raw.githubusercontent.com/vrcx-team/VRCX/master/Linux/vrcx.sh -o $WINEPREFIX/drive_c/vrcx.sh
chmod +x $WINEPREFIX/drive_c/vrcx.sh
curl -L https://raw.githubusercontent.com/vrcx-team/VRCX/master/Linux/winediscordipcbridge.exe -o $WINEPREFIX/drive_c/winediscordipcbridge.exe
echo "Install VRCX.png to $XDG_DATA_HOME/icons" echo "Install VRCX.png to $XDG_DATA_HOME/icons"
curl -L https://raw.githubusercontent.com/vrcx-team/VRCX/master/VRCX.png -o "$XDG_DATA_HOME/icons/VRCX.png" curl -L https://raw.githubusercontent.com/vrcx-team/VRCX/master/VRCX.png -o "$XDG_DATA_HOME/icons/VRCX.png"
@@ -91,7 +96,7 @@ echo "[Desktop Entry]
Type=Application Type=Application
Name=VRCX Name=VRCX
Categories=Utility; Categories=Utility;
Exec=WINEPREFIX=$WINEPREFIX wine '$INSTALL_LOCATION/VRCX.exe' Exec=$WINEPREFIX/drive_c/vrcx.sh
Icon=VRCX Icon=VRCX
" > $XDG_DATA_HOME/applications/vrcx.exe.desktop " > $XDG_DATA_HOME/applications/vrcx.exe.desktop
Executable
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
export WINEPREFIX=~/.local/share/vrcx
wine ~/.local/share/vrcx/drive_c/winediscordipcbridge.exe &
IPCBRIDGE_PID=$!
wine ~/.local/share/vrcx/drive_c/vrcx/VRCX.exe &
VRCX_PID=$!
while kill -0 $VRCX_PID 2>/dev/null; do
if ps -A | grep -i "VRChat.exe" > /dev/null; then
isGameRunning=true
else
isGameRunning=false
fi
echo "isGameRunning=$isGameRunning" > "$WINEPREFIX/drive_c/users/$USER/AppData/Roaming/VRCX/wine.tmp"
sleep 1
done
echo "isGameRunning=false" > "$WINEPREFIX/drive_c/users/$USER/AppData/Roaming/VRCX/wine.tmp"
kill $IPCBRIDGE_PID 2>/dev/null
Binary file not shown.
+6 -1
View File
@@ -22,7 +22,8 @@ export default class extends baseClass {
ipcTimeout: 0, ipcTimeout: 0,
nextClearVRCXCacheCheck: 0, nextClearVRCXCacheCheck: 0,
nextDiscordUpdate: 0, nextDiscordUpdate: 0,
nextAutoStateChange: 0 nextAutoStateChange: 0,
nextGameRunningCheck: 0,
}; };
_methods = { _methods = {
@@ -75,6 +76,10 @@ export default class extends baseClass {
this.nextAutoStateChange = 3; this.nextAutoStateChange = 3;
this.updateAutoStateChange(); this.updateAutoStateChange();
} }
if (--this.nextGameRunningCheck <= 0) {
this.nextGameRunningCheck = 3;
AppApi.CheckGameRunning();
}
} }
} catch (err) { } catch (err) {
API.isRefreshFriendsLoading = false; API.isRefreshFriendsLoading = false;