From 1ef8c073b712101bab9e2f1cd2f499acdcf4c57b Mon Sep 17 00:00:00 2001 From: Brian Lima Date: Sat, 9 Jan 2021 18:06:44 -0300 Subject: [PATCH] Pass secondary args to launched app --- UWPHook/AppManager.cs | 13 +++++++++++-- UWPHook/GamesWindow.xaml.cs | 9 +++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/UWPHook/AppManager.cs b/UWPHook/AppManager.cs index 3b04b1b..7b22e5d 100644 --- a/UWPHook/AppManager.cs +++ b/UWPHook/AppManager.cs @@ -20,14 +20,23 @@ namespace UWPHook /// Launch a UWP App using a ApplicationActivationManager and sets a internal id to launched proccess id /// /// The AUMID of the app to launch - public static void LaunchUWPApp(string aumid) + public static void LaunchUWPApp(string[] args) { + string aumid = args[1]; // We receive the args from Steam, + // 0 is application location, + // 1 is the aumid, the rest are extras + var mgr = new ApplicationActivationManager(); uint processId; + string extra_args = String.Join(" ", args.Skip(2) + .Take(args.Length - 2) + .Select(eachElement => eachElement.Clone() + ).ToArray()); + try { - mgr.ActivateApplication(aumid, null, ActivateOptions.None, out processId); + mgr.ActivateApplication(aumid, extra_args, ActivateOptions.None, out processId); //Bring the launched app to the foreground, this fixes in-home streaming id = (int)processId; diff --git a/UWPHook/GamesWindow.xaml.cs b/UWPHook/GamesWindow.xaml.cs index 4e265b7..8ea2751 100644 --- a/UWPHook/GamesWindow.xaml.cs +++ b/UWPHook/GamesWindow.xaml.cs @@ -32,14 +32,15 @@ namespace UWPHook { InitializeComponent(); Apps = new AppEntryModel(); + var args = Environment.GetCommandLineArgs(); //If null or 1, the app was launched normally - if (Environment.GetCommandLineArgs() != null) + if (args != null) { //When length is 1, the only argument is the path where the app is installed if (Environment.GetCommandLineArgs().Length > 1) { - _ = LauncherAsync(); + _ = LauncherAsync(args); } } } @@ -53,7 +54,7 @@ namespace UWPHook await Task.Delay(10000); } - private async Task LauncherAsync() + private async Task LauncherAsync(string[] args) { FullScreenLauncher launcher = null; //So, for some reason, Steam is now stopping in-home streaming if the launched app is minimized, so not hiding UWPHook's window is doing the trick for now @@ -86,7 +87,7 @@ namespace UWPHook } //The only other parameter Steam will send is the app AUMID - AppManager.LaunchUWPApp(Environment.GetCommandLineArgs()[1]); + AppManager.LaunchUWPApp(args); //While the current launched app is running, sleep for n seconds and then check again while (AppManager.IsRunning())