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
+2 -1
View File
@@ -149,10 +149,11 @@ namespace VRCX
return output; return output;
} }
public void SetAppLauncherSettings(bool enabled, bool killOnExit) public void SetAppLauncherSettings(bool enabled, bool killOnExit, bool runProcessOnce)
{ {
AutoAppLaunchManager.Instance.Enabled = enabled; AutoAppLaunchManager.Instance.Enabled = enabled;
AutoAppLaunchManager.Instance.KillChildrenOnExit = killOnExit; AutoAppLaunchManager.Instance.KillChildrenOnExit = killOnExit;
AutoAppLaunchManager.Instance.RunProcessOnce = runProcessOnce;
} }
public string GetFileBase64(string path) public string GetFileBase64(string path)
+22 -3
View File
@@ -21,6 +21,7 @@ namespace VRCX
public bool Enabled = false; public bool Enabled = false;
/// <summary> Whether or not to kill child processes when VRChat closes. </summary> /// <summary> Whether or not to kill child processes when VRChat closes. </summary>
public bool KillChildrenOnExit = true; public bool KillChildrenOnExit = true;
public bool RunProcessOnce = true;
public readonly string AppShortcutDirectory; public readonly string AppShortcutDirectory;
private DateTime startTime = DateTime.Now; private DateTime startTime = DateTime.Now;
@@ -110,11 +111,15 @@ namespace VRCX
UpdateChildProcesses(); UpdateChildProcesses();
var shortcutFiles = FindShortcutFiles(AppShortcutDirectory); var shortcutFiles = FindShortcutFiles(AppShortcutDirectory);
foreach (var file in shortcutFiles) foreach (var file in shortcutFiles)
{ {
if (!IsChildProcessRunning(file)) if (RunProcessOnce && IsProcessRunning(file))
StartChildProcess(file); continue;
if (IsChildProcessRunning(file))
continue;
StartChildProcess(file);
} }
if (shortcutFiles.Length == 0) if (shortcutFiles.Length == 0)
@@ -274,6 +279,20 @@ namespace VRCX
return startedProcesses.ContainsKey(path); 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() public void Init()
{ {
// What are you lookin at? :eyes: // What are you lookin at? :eyes:
+2 -1
View File
@@ -631,7 +631,8 @@
"folder": "Auto-Launch Folder", "folder": "Auto-Launch Folder",
"folder_tooltip": "To auto-launch apps with VRChat, place shortcuts in this folder.", "folder_tooltip": "To auto-launch apps with VRChat, place shortcuts in this folder.",
"enable": "Enable", "enable": "Enable",
"auto_close": "Auto close apps" "auto_close": "Auto close apps",
"run_process_once": "Open single instance of app"
}, },
"cache_debug": { "cache_debug": {
"header": "VRCX Instance Cache/Debug", "header": "VRCX Instance Cache/Debug",
+23 -1
View File
@@ -25,6 +25,7 @@ export const useAdvancedSettingsStore = defineStore('AdvancedSettings', () => {
avatarRemoteDatabase: true, avatarRemoteDatabase: true,
enableAppLauncher: true, enableAppLauncher: true,
enableAppLauncherAutoClose: true, enableAppLauncherAutoClose: true,
enableAppLauncherRunProcessOnce: true,
screenshotHelper: true, screenshotHelper: true,
screenshotHelperModifyFilename: false, screenshotHelperModifyFilename: false,
screenshotHelperCopyToClipboard: false, screenshotHelperCopyToClipboard: false,
@@ -58,6 +59,7 @@ export const useAdvancedSettingsStore = defineStore('AdvancedSettings', () => {
avatarRemoteDatabase, avatarRemoteDatabase,
enableAppLauncher, enableAppLauncher,
enableAppLauncherAutoClose, enableAppLauncherAutoClose,
enableAppLauncherRunProcessOnce,
screenshotHelper, screenshotHelper,
screenshotHelperModifyFilename, screenshotHelperModifyFilename,
screenshotHelperCopyToClipboard, screenshotHelperCopyToClipboard,
@@ -84,6 +86,10 @@ export const useAdvancedSettingsStore = defineStore('AdvancedSettings', () => {
configRepository.getBool('VRCX_avatarRemoteDatabase', true), configRepository.getBool('VRCX_avatarRemoteDatabase', true),
configRepository.getBool('VRCX_enableAppLauncher', true), configRepository.getBool('VRCX_enableAppLauncher', true),
configRepository.getBool('VRCX_enableAppLauncherAutoClose', true), configRepository.getBool('VRCX_enableAppLauncherAutoClose', true),
configRepository.getBool(
'VRCX_enableAppLauncherRunProcessOnce',
true
),
configRepository.getBool('VRCX_screenshotHelper', true), configRepository.getBool('VRCX_screenshotHelper', true),
configRepository.getBool( configRepository.getBool(
'VRCX_screenshotHelperModifyFilename', 'VRCX_screenshotHelperModifyFilename',
@@ -120,6 +126,7 @@ export const useAdvancedSettingsStore = defineStore('AdvancedSettings', () => {
state.avatarRemoteDatabase = avatarRemoteDatabase; state.avatarRemoteDatabase = avatarRemoteDatabase;
state.enableAppLauncher = enableAppLauncher; state.enableAppLauncher = enableAppLauncher;
state.enableAppLauncherAutoClose = enableAppLauncherAutoClose; state.enableAppLauncherAutoClose = enableAppLauncherAutoClose;
state.enableAppLauncherRunProcessOnce = enableAppLauncherRunProcessOnce;
state.screenshotHelper = screenshotHelper; state.screenshotHelper = screenshotHelper;
state.screenshotHelperModifyFilename = screenshotHelperModifyFilename; state.screenshotHelperModifyFilename = screenshotHelperModifyFilename;
state.screenshotHelperCopyToClipboard = screenshotHelperCopyToClipboard; state.screenshotHelperCopyToClipboard = screenshotHelperCopyToClipboard;
@@ -167,6 +174,9 @@ export const useAdvancedSettingsStore = defineStore('AdvancedSettings', () => {
const enableAppLauncherAutoClose = computed( const enableAppLauncherAutoClose = computed(
() => state.enableAppLauncherAutoClose () => state.enableAppLauncherAutoClose
); );
const enableAppLauncherRunProcessOnce = computed(
() => state.enableAppLauncherRunProcessOnce
);
const screenshotHelper = computed(() => state.screenshotHelper); const screenshotHelper = computed(() => state.screenshotHelper);
``; ``;
const screenshotHelperModifyFilename = computed( const screenshotHelperModifyFilename = computed(
@@ -280,6 +290,15 @@ export const useAdvancedSettingsStore = defineStore('AdvancedSettings', () => {
); );
handleSetAppLauncherSettings(); handleSetAppLauncherSettings();
} }
async function setEnableAppLauncherRunProcessOnce() {
state.enableAppLauncherRunProcessOnce =
!state.enableAppLauncherRunProcessOnce;
await configRepository.setBool(
'VRCX_enableAppLauncherRunProcessOnce',
state.enableAppLauncherRunProcessOnce
);
handleSetAppLauncherSettings();
}
async function setScreenshotHelper() { async function setScreenshotHelper() {
state.screenshotHelper = !state.screenshotHelper; state.screenshotHelper = !state.screenshotHelper;
await configRepository.setBool( await configRepository.setBool(
@@ -440,7 +459,8 @@ export const useAdvancedSettingsStore = defineStore('AdvancedSettings', () => {
function handleSetAppLauncherSettings() { function handleSetAppLauncherSettings() {
AppApi.SetAppLauncherSettings( AppApi.SetAppLauncherSettings(
state.enableAppLauncher, state.enableAppLauncher,
state.enableAppLauncherAutoClose state.enableAppLauncherAutoClose,
state.enableAppLauncherRunProcessOnce
); );
} }
@@ -678,6 +698,7 @@ export const useAdvancedSettingsStore = defineStore('AdvancedSettings', () => {
avatarRemoteDatabase, avatarRemoteDatabase,
enableAppLauncher, enableAppLauncher,
enableAppLauncherAutoClose, enableAppLauncherAutoClose,
enableAppLauncherRunProcessOnce,
screenshotHelper, screenshotHelper,
screenshotHelperModifyFilename, screenshotHelperModifyFilename,
screenshotHelperCopyToClipboard, screenshotHelperCopyToClipboard,
@@ -707,6 +728,7 @@ export const useAdvancedSettingsStore = defineStore('AdvancedSettings', () => {
setAvatarRemoteDatabase, setAvatarRemoteDatabase,
setEnableAppLauncher, setEnableAppLauncher,
setEnableAppLauncherAutoClose, setEnableAppLauncherAutoClose,
setEnableAppLauncherRunProcessOnce,
setScreenshotHelper, setScreenshotHelper,
setScreenshotHelperModifyFilename, setScreenshotHelperModifyFilename,
setScreenshotHelperCopyToClipboard, setScreenshotHelperCopyToClipboard,
+2 -1
View File
@@ -197,7 +197,8 @@ declare global {
GetColourBulk(userIds: string[]): Promise<Record<string, number>>; GetColourBulk(userIds: string[]): Promise<Record<string, number>>;
SetAppLauncherSettings( SetAppLauncherSettings(
enabled: boolean, enabled: boolean,
killOnExit: boolean killOnExit: boolean,
runProcessOnce: boolean
): Promise<void>; ): Promise<void>;
GetFileBase64(path: string): Promise<string | null>; GetFileBase64(path: string): Promise<string | null>;
+7
View File
@@ -1521,6 +1521,11 @@
:value="enableAppLauncherAutoClose" :value="enableAppLauncherAutoClose"
:long-label="true" :long-label="true"
@change="setEnableAppLauncherAutoClose" /> @change="setEnableAppLauncherAutoClose" />
<simple-switch
:label="t('view.settings.advanced.advanced.app_launcher.run_process_once')"
:value="enableAppLauncherRunProcessOnce"
:long-label="true"
@change="setEnableAppLauncherRunProcessOnce" />
</div> </div>
</template> </template>
@@ -2118,6 +2123,7 @@
avatarRemoteDatabase, avatarRemoteDatabase,
enableAppLauncher, enableAppLauncher,
enableAppLauncherAutoClose, enableAppLauncherAutoClose,
enableAppLauncherRunProcessOnce,
screenshotHelper, screenshotHelper,
screenshotHelperModifyFilename, screenshotHelperModifyFilename,
screenshotHelperCopyToClipboard, screenshotHelperCopyToClipboard,
@@ -2143,6 +2149,7 @@
setAvatarRemoteDatabase, setAvatarRemoteDatabase,
setEnableAppLauncher, setEnableAppLauncher,
setEnableAppLauncherAutoClose, setEnableAppLauncherAutoClose,
setEnableAppLauncherRunProcessOnce,
setScreenshotHelper, setScreenshotHelper,
setScreenshotHelperModifyFilename, setScreenshotHelperModifyFilename,
setScreenshotHelperCopyToClipboard, setScreenshotHelperCopyToClipboard,