Improve uac dialog api function

This commit is contained in:
Jack251970 2025-06-12 16:07:09 +08:00
parent 0d1358fdc3
commit a775323108
4 changed files with 25 additions and 10 deletions

View file

@ -601,12 +601,12 @@ namespace Flow.Launcher.Plugin
/// 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="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="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);
public MessageBoxResult ShowUACDialog(string appName, string iconPath = "", string fullPath = "");
}
}

View file

@ -614,8 +614,8 @@ namespace Flow.Launcher
}
}
public MessageBoxResult ShowUACDialog(string iconPath, string appName, string fullPath) =>
UACDialog.Show(iconPath, appName, fullPath);
public MessageBoxResult ShowUACDialog(string appName, string iconPath = "", string fullPath = "") =>
UACDialog.Show(appName, iconPath, fullPath);
#endregion

View file

@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
@ -17,11 +18,11 @@ namespace Flow.Launcher
InitializeComponent();
}
public static MessageBoxResult Show(string iconPath, string appName, string fullPath)
public static MessageBoxResult Show(string appName, string iconPath, string fullPath)
{
if (!Application.Current.Dispatcher.CheckAccess())
{
return Application.Current.Dispatcher.Invoke(() => Show(iconPath, appName, fullPath));
return Application.Current.Dispatcher.Invoke(() => Show(appName, iconPath, fullPath));
}
try
@ -31,9 +32,18 @@ namespace Flow.Launcher
// Set icon & app name & program location
_ = msgBox.SetImageAsync(iconPath);
msgBox.AppName.Text = appName;
msgBox.ProgramLocation.Text = string.Format(
App.API.GetTranslation("userAccountControlProgramLocation"),
fullPath);
if (string.IsNullOrEmpty(fullPath))
{
msgBox.ProgramLocation.Text = string.Format(
App.API.GetTranslation("userAccountControlProgramLocation"),
appName);
}
else
{
msgBox.ProgramLocation.Text = string.Format(
App.API.GetTranslation("userAccountControlProgramLocation"),
fullPath);
}
// Focus No by default
msgBox.btnNo.Focus();
@ -52,6 +62,11 @@ namespace Flow.Launcher
private async Task SetImageAsync(string imagePath)
{
if (string.IsNullOrEmpty(imagePath) || !File.Exists(imagePath))
{
Img.Visibility = Visibility.Collapsed;
return;
}
var imageSource = await App.API.LoadImageAsync(imagePath);
Img.Source = imageSource;
}

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 (Main.Context.API.ShowUACDialog(IcoPath, Name, LnkResolvedPath) != MessageBoxResult.Yes)
if (Main.Context.API.ShowUACDialog(Name, IcoPath, LnkResolvedPath) != MessageBoxResult.Yes)
{
return;
}