Add show uac dialog api function

This commit is contained in:
Jack251970 2025-06-12 15:30:25 +08:00
parent 433e0fd0e1
commit 21e8d92aa2
7 changed files with 33 additions and 15 deletions

View file

@ -592,5 +592,20 @@ namespace Flow.Launcher.Plugin
/// <param name="arguments">Optional arguments to pass to the process. If not specified, no arguments will be passed</param>
/// <param name="runAsAdmin">Whether to run the process as administrator</param>
public void StartProcess(string filePath, string workingDirectory = "", string arguments = "", bool runAsAdmin = false);
/// <summary>
/// Displays a User Account Control (UAC) dialog to request elevated permissions for the specified application.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
/// <param name="iconPath">The file path to the icon that will be displayed in the dialog. Must be a valid path to an image file.</param>
/// <param name="appName">The name of the application requesting elevation. This will be displayed in the dialog.</param>
/// <param name="fullPath">The full file path of the executable requesting elevation. This is shown to the user for verification.</param>
/// <returns>A <see cref="MessageBoxResult"/> indicating the user's response to the dialog. Possible values include
/// <see cref="MessageBoxResult.Yes"/> if the user grants permission,
/// or <see cref="MessageBoxResult.No"/> if the user denies permission.</returns>
public MessageBoxResult ShowUACDialog(string iconPath, string appName, string fullPath);
}
}

View file

@ -379,6 +379,11 @@
<system:String x:Key="appUpdateTitle">Flow Launcher has been updated to {0}</system:String>
<system:String x:Key="appUpdateButtonContent">Click here to view the release notes</system:String>
<!-- User Account Control Dialog -->
<system:String x:Key="userAccountControlTitle">User Account Control</system:String>
<system:String x:Key="userAccountControlSubtitle">Do you want to allow this app to make changes to your device?</system:String>
<system:String x:Key="userAccountControlProgramLocation">Program location: {0}</system:String>
<!-- FileManager Setting Dialog -->
<system:String x:Key="fileManagerWindow">Select File Manager</system:String>
<system:String x:Key="fileManager_learnMore">Learn more</system:String>

View file

@ -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

View file

@ -1,10 +1,11 @@
<Window
x:Class="Flow.Launcher.Plugin.Program.UACDialog"
x:Class="Flow.Launcher.UACDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="MessageBoxWindow"
Title="{DynamicResource userAccountControlTitle}"
Width="420"
Height="Auto"
Background="{DynamicResource PopuBGColor}"
@ -76,7 +77,7 @@
FontFamily="Segoe UI"
FontSize="20"
FontWeight="SemiBold"
Text="{DynamicResource flowlauncher_plugin_program_user_account_control_title}"
Text="{DynamicResource userAccountControlTitle}"
TextAlignment="Left"
TextWrapping="Wrap" />
</Grid>
@ -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" />
</Grid>

View file

@ -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;
}

View file

@ -97,8 +97,5 @@
<system:String x:Key="flowlauncher_plugin_program_disable_dlgtitle_success_message">Successfully disabled this program from displaying in your query</system:String>
<system:String x:Key="flowlauncher_plugin_program_run_as_administrator_not_supported_message">This app is not intended to be run as administrator</system:String>
<system:String x:Key="flowlauncher_plugin_program_run_failed">Unable to run {0}</system:String>
<system:String x:Key="flowlauncher_plugin_program_user_account_control_title">User Account Control</system:String>
<system:String x:Key="flowlauncher_plugin_program_user_account_control_subtitle">Do you want to allow this app to make changes to your device?</system:String>
<system:String x:Key="flowlauncher_plugin_program_user_account_control_program_location">Program location: {0}</system:String>
</ResourceDictionary>

View file

@ -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;
}