From a7753231081f58ed8b59b66638ac501626937f06 Mon Sep 17 00:00:00 2001
From: Jack251970 <1160210343@qq.com>
Date: Thu, 12 Jun 2025 16:07:09 +0800
Subject: [PATCH] Improve uac dialog api function
---
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs | 4 +--
Flow.Launcher/PublicAPIInstance.cs | 4 +--
Flow.Launcher/UACDialog.xaml.cs | 25 +++++++++++++++----
.../Programs/Win32.cs | 2 +-
4 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
index 8c02151be..6382ecd0f 100644
--- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
+++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
@@ -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.
///
- /// 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 file path to the icon that will be displayed in the dialog. Must be a valid path to an image file.
/// 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);
+ public MessageBoxResult ShowUACDialog(string appName, string iconPath = "", string fullPath = "");
}
}
diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs
index d02b718d0..4ff9659bb 100644
--- a/Flow.Launcher/PublicAPIInstance.cs
+++ b/Flow.Launcher/PublicAPIInstance.cs
@@ -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
diff --git a/Flow.Launcher/UACDialog.xaml.cs b/Flow.Launcher/UACDialog.xaml.cs
index 0d5e8a46d..e49eac685 100644
--- a/Flow.Launcher/UACDialog.xaml.cs
+++ b/Flow.Launcher/UACDialog.xaml.cs
@@ -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;
}
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
index 4e256d2cb..905fab913 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 (Main.Context.API.ShowUACDialog(IcoPath, Name, LnkResolvedPath) != MessageBoxResult.Yes)
+ if (Main.Context.API.ShowUACDialog(Name, IcoPath, LnkResolvedPath) != MessageBoxResult.Yes)
{
return;
}