Autorun open single instance of app

This commit is contained in:
Natsumi
2025-08-23 12:27:51 +12:00
parent 6a3b0cd24a
commit ae30ad978b
6 changed files with 58 additions and 7 deletions

View File

@@ -149,10 +149,11 @@ namespace VRCX
return output;
}
public void SetAppLauncherSettings(bool enabled, bool killOnExit)
public void SetAppLauncherSettings(bool enabled, bool killOnExit, bool runProcessOnce)
{
AutoAppLaunchManager.Instance.Enabled = enabled;
AutoAppLaunchManager.Instance.KillChildrenOnExit = killOnExit;
AutoAppLaunchManager.Instance.RunProcessOnce = runProcessOnce;
}
public string GetFileBase64(string path)

View File

@@ -21,6 +21,7 @@ namespace VRCX
public bool Enabled = false;
/// <summary> Whether or not to kill child processes when VRChat closes. </summary>
public bool KillChildrenOnExit = true;
public bool RunProcessOnce = true;
public readonly string AppShortcutDirectory;
private DateTime startTime = DateTime.Now;
@@ -110,11 +111,15 @@ namespace VRCX
UpdateChildProcesses();
var shortcutFiles = FindShortcutFiles(AppShortcutDirectory);
foreach (var file in shortcutFiles)
{
if (!IsChildProcessRunning(file))
StartChildProcess(file);
if (RunProcessOnce && IsProcessRunning(file))
continue;
if (IsChildProcessRunning(file))
continue;
StartChildProcess(file);
}
if (shortcutFiles.Length == 0)
@@ -273,6 +278,20 @@ namespace VRCX
{
return startedProcesses.ContainsKey(path);
}
private bool IsProcessRunning(string filePath)
{
try
{
var processName = Path.GetFileNameWithoutExtension(filePath);
return Process.GetProcessesByName(processName).Length != 0;
}
catch (Exception ex)
{
logger.Error(ex, "Error checking if process is running: {0}", filePath);
return false;
}
}
public void Init()
{