separate isGameRunning and isGmaeNoVR

This commit is contained in:
pypy
2020-10-25 18:59:57 +09:00
parent e9f65f4868
commit b15cf90a01
2 changed files with 31 additions and 21 deletions
+17 -10
View File
@@ -46,18 +46,18 @@ namespace VRCX
: string.Empty; : string.Empty;
} }
public bool IsGameRunning() public bool[] CheckGameRunning()
{ {
IntPtr hwnd = WinApi.FindWindow("UnityWndClass", "VRChat"); var isGameRunning = false;
if (hwnd == IntPtr.Zero) var isGameNoVR = false;
{
return false;
}
String cmdline; var hwnd = WinApi.FindWindow("UnityWndClass", "VRChat");
if (hwnd != IntPtr.Zero)
{
var cmdline = string.Empty;
try try
{ {
Int32 pid; Int32 pid = 0;
WinApi.GetWindowThreadProcessId(hwnd, out pid); WinApi.GetWindowThreadProcessId(hwnd, out pid);
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + pid)) using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + pid))
using (ManagementObjectCollection objects = searcher.Get()) using (ManagementObjectCollection objects = searcher.Get())
@@ -67,10 +67,17 @@ namespace VRCX
} }
catch catch
{ {
return false;
} }
return !cmdline.Contains("--no-vr"); isGameRunning = true;
isGameNoVR = cmdline.Contains("--no-vr");
}
return new bool[]
{
isGameRunning,
isGameNoVR
};
} }
public void StartGame(string arguments) public void StartGame(string arguments)
+6 -3
View File
@@ -3272,6 +3272,7 @@ CefSharp.BindObjectAsync(
VRCX, VRCX,
nextRefresh: 0, nextRefresh: 0,
isGameRunning: false, isGameRunning: false,
isGameNoVR: false,
appVersion: 'VRCX 2020.07.13', appVersion: 'VRCX 2020.07.13',
latestAppVersion: '', latestAppVersion: '',
ossDialog: false, ossDialog: false,
@@ -3378,11 +3379,12 @@ CefSharp.BindObjectAsync(
} }
this.checkActiveFriends(); this.checkActiveFriends();
this.refreshGameLog(); this.refreshGameLog();
VRCX.IsGameRunning().then((running) => { VRCX.CheckGameRunning().then(([isGameRunning, isGameNoVR]) => {
if (running !== this.isGameRunning) { if (isGameRunning !== this.isGameRunning) {
this.isGameRunning = running; this.isGameRunning = isGameRunning;
Discord.SetTimestamps(Date.now(), 0); Discord.SetTimestamps(Date.now(), 0);
} }
this.isGameNoVR = isGameNoVR;
this.updateDiscord(); this.updateDiscord();
this.updateOpenVR(); this.updateOpenVR();
}); });
@@ -5567,6 +5569,7 @@ CefSharp.BindObjectAsync(
$app.methods.updateOpenVR = function () { $app.methods.updateOpenVR = function () {
if (this.openVR && if (this.openVR &&
this.isGameNoVR === false &&
(this.isGameRunning || this.openVRAlways)) { (this.isGameRunning || this.openVRAlways)) {
VRCX.StartVR(); VRCX.StartVR();
} else { } else {