diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs index a413fe98e..9e3d279ab 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs @@ -592,5 +592,20 @@ namespace Flow.Launcher.Plugin /// Optional arguments to pass to the process. If not specified, no arguments will be passed /// Whether to run the process as administrator public void StartProcess(string filePath, string workingDirectory = "", string arguments = "", bool runAsAdmin = false); + + /// + /// Displays a User Account Control (UAC) dialog to request elevated permissions for the specified application. + /// + /// + /// If Flow is running under administrator mode, executing elevated actions will not trigger UAC dialog. + /// So this method is used to manually show the UAC dialog when needed. + /// + /// The file path to the icon that will be displayed in the dialog. Must be a valid path to an image file. + /// The name of the application requesting elevation. This will be displayed in the dialog. + /// The full file path of the executable requesting elevation. This is shown to the user for verification. + /// A indicating the user's response to the dialog. Possible values include + /// if the user grants permission, + /// or if the user denies permission. + public MessageBoxResult ShowUACDialog(string iconPath, string appName, string fullPath); } } diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index 97f294b14..aea9d4a60 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -379,6 +379,11 @@ Flow Launcher has been updated to {0} Click here to view the release notes + + User Account Control + Do you want to allow this app to make changes to your device? + Program location: {0} + Select File Manager Learn more diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index e76ea1a5a..6a4a4493d 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -610,6 +610,9 @@ namespace Flow.Launcher } } + public MessageBoxResult ShowUACDialog(string iconPath, string appName, string fullPath) => + UACDialog.Show(iconPath, appName, fullPath); + #endregion #region Private Methods diff --git a/Plugins/Flow.Launcher.Plugin.Program/UACDialog.xaml b/Flow.Launcher/UACDialog.xaml similarity index 95% rename from Plugins/Flow.Launcher.Plugin.Program/UACDialog.xaml rename to Flow.Launcher/UACDialog.xaml index d619f4765..9d13a2c7b 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/UACDialog.xaml +++ b/Flow.Launcher/UACDialog.xaml @@ -1,10 +1,11 @@  @@ -86,7 +87,7 @@ Margin="0 0 26 0" HorizontalAlignment="Stretch" FontSize="14" - Text="{DynamicResource flowlauncher_plugin_program_user_account_control_subtitle}" + Text="{DynamicResource userAccountControlSubtitle}" TextAlignment="Left" TextWrapping="Wrap" /> diff --git a/Plugins/Flow.Launcher.Plugin.Program/UACDialog.xaml.cs b/Flow.Launcher/UACDialog.xaml.cs similarity index 80% rename from Plugins/Flow.Launcher.Plugin.Program/UACDialog.xaml.cs rename to Flow.Launcher/UACDialog.xaml.cs index 3ab087b48..0d5e8a46d 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/UACDialog.xaml.cs +++ b/Flow.Launcher/UACDialog.xaml.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Input; -namespace Flow.Launcher.Plugin.Program +namespace Flow.Launcher { public partial class UACDialog : Window { @@ -26,16 +26,13 @@ namespace Flow.Launcher.Plugin.Program try { - msgBox = new UACDialog - { - Title = Main.Context.API.GetTranslation("flowlauncher_plugin_program_user_account_control_title") - }; + msgBox = new UACDialog(); // Set icon & app name & program location _ = msgBox.SetImageAsync(iconPath); msgBox.AppName.Text = appName; msgBox.ProgramLocation.Text = string.Format( - Main.Context.API.GetTranslation("flowlauncher_plugin_program_user_account_control_program_location"), + App.API.GetTranslation("userAccountControlProgramLocation"), fullPath); // Focus No by default @@ -47,7 +44,7 @@ namespace Flow.Launcher.Plugin.Program } catch (Exception e) { - Main.Context.API.LogError(ClassName, $"An error occurred: {e.Message}"); + App.API.LogError(ClassName, $"An error occurred: {e.Message}"); msgBox = null; return MessageBoxResult.None; } @@ -55,7 +52,7 @@ namespace Flow.Launcher.Plugin.Program private async Task SetImageAsync(string imagePath) { - var imageSource = await Main.Context.API.LoadImageAsync(imagePath); + var imageSource = await App.API.LoadImageAsync(imagePath); Img.Source = imageSource; } diff --git a/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml index e3eeb4e91..e551a7dcb 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml @@ -97,8 +97,5 @@ Successfully disabled this program from displaying in your query This app is not intended to be run as administrator Unable to run {0} - User Account Control - Do you want to allow this app to make changes to your device? - Program location: {0} diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs index 7e78a7fb6..4e256d2cb 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs @@ -211,7 +211,7 @@ namespace Flow.Launcher.Plugin.Program.Programs if (Main.IsAdmin && elevated) { // Since we are already elevated, we need to create UAC dialog manually - if (UACDialog.Show(IcoPath, Name, LnkResolvedPath) != MessageBoxResult.Yes) + if (Main.Context.API.ShowUACDialog(IcoPath, Name, LnkResolvedPath) != MessageBoxResult.Yes) { return; }