Skip to content

Commit 0544681

Browse files
authored
Prevent window from pulling forward before UAC prompts (#5353)
1 parent 4f8a820 commit 0544681

4 files changed

Lines changed: 10 additions & 26 deletions

File tree

src/UniGetUI.Avalonia/Views/MainWindow.axaml.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
using UniGetUI.Avalonia.Views.Controls;
2020
using UniGetUI.Avalonia.Views.DialogPages;
2121
using UniGetUI.Avalonia.Views.Pages;
22-
using UniGetUI.Core.Data;
2322
using UniGetUI.Core.Logging;
2423
using UniGetUI.Core.SettingsEngine;
2524
using UniGetUI.Core.Tools;
@@ -190,12 +189,6 @@ public MainWindow()
190189

191190
_trayService = new TrayService(this);
192191
_trayService.UpdateStatus();
193-
194-
// Let the elevation code activate us right before a UAC prompt, so we own the foreground
195-
// and can delegate it to the consent UI (#5146). Only activate when we're already on screen;
196-
// don't yank a tray-hidden window forward during silent/background elevation.
197-
CoreData.BringMainWindowToForegroundAsync = () =>
198-
Dispatcher.UIThread.InvokeAsync(() => { if (IsVisible) ShowFromTray(); }).GetTask();
199192
}
200193

201194
protected override void OnOpened(EventArgs e)

src/UniGetUI.Core.Data/CoreData.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,6 @@ public static string UniGetUIExecutableFile
388388
/// </summary>
389389
public static string ElevatorArgs = "";
390390

391-
/// <summary>
392-
/// Set by the UI layer to bring the main window to the foreground and wait until it is.
393-
/// Called right before a UAC prompt is triggered so the app owns the foreground and can
394-
/// delegate it to the consent UI (fixes prompts hiding behind the window with secure desktop off).
395-
/// Null in headless mode, where no window exists to activate.
396-
/// </summary>
397-
public static Func<Task>? BringMainWindowToForegroundAsync;
398-
399391
/// <summary>
400392
/// This method will return the most appropriate data directory.
401393
/// If the new directory exists, it will be used.

src/UniGetUI.Core.Tools/Tools.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -752,19 +752,18 @@ public static string EnsureSafeQueryString(string query)
752752
private static extern bool AllowSetForegroundWindow(int dwProcessId);
753753

754754
/// <summary>
755-
/// Windows: bring UniGetUI to the foreground and grant foreground rights so an imminent
756-
/// UAC consent prompt surfaces in front instead of only flashing the taskbar (#5146).
757-
/// No-op elsewhere, and when the app owns no visible foreground window to delegate.
755+
/// Windows: hand our foreground rights to the imminent UAC consent prompt so it surfaces
756+
/// in front instead of only flashing the taskbar (#5146). Windows decides whether we
757+
/// still hold that privilege and grants nothing once another app owns the foreground.
758+
/// Either way this only ever lets the consent UI come forward; it never activates our
759+
/// own window, so a minimized UniGetUI stays minimized (#5102). No-op elsewhere.
758760
/// Must be called immediately before launching the elevator.
759761
/// </summary>
760-
public static async Task PrepareForegroundForElevationAsync()
762+
public static void PrepareForegroundForElevation()
761763
{
762764
if (!OperatingSystem.IsWindows())
763765
return;
764766

765-
var bringToFront = CoreData.BringMainWindowToForegroundAsync;
766-
if (bringToFront is not null)
767-
await bringToFront();
768767
AllowSetForegroundWindow(ASFW_ANY);
769768
}
770769

@@ -824,7 +823,7 @@ public static async Task CacheUACForCurrentProcess()
824823

825824
// When admin-rights caching is enabled, the UAC consent prompt is raised here.
826825
// Surface it in front instead of letting it flash unnoticed in the taskbar (#5146).
827-
await PrepareForegroundForElevationAsync();
826+
PrepareForegroundForElevation();
828827

829828
p.Start();
830829
await p.WaitForExitAsync();

src/UniGetUI.PackageEngine.Operations/AbstractProcessOperation.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ protected override async Task<OperationVeredict> PerformOperation()
140140
CancellationToken.ThrowIfCancellationRequested();
141141

142142
// When admin-rights caching is disabled (or a cache miss), the elevator is launched
143-
// directly here and the UAC prompt is raised at this Start() — bring it to the
144-
// foreground too, not just on the cached path (#5146).
143+
// directly here and the UAC prompt is raised at this Start() — delegate foreground
144+
// rights here too, not just on the cached path (#5146).
145145
if (process.StartInfo.FileName == CoreData.ElevatorPath)
146-
await CoreTools.PrepareForegroundForElevationAsync();
146+
CoreTools.PrepareForegroundForElevation();
147147

148148
process.Start();
149149
if (CancellationToken.IsCancellationRequested)

0 commit comments

Comments
 (0)