Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/UniGetUI.Avalonia/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
using UniGetUI.Avalonia.Views.Controls;
using UniGetUI.Avalonia.Views.DialogPages;
using UniGetUI.Avalonia.Views.Pages;
using UniGetUI.Core.Data;
using UniGetUI.Core.Logging;
using UniGetUI.Core.SettingsEngine;
using UniGetUI.Core.Tools;
Expand Down Expand Up @@ -190,12 +189,6 @@ public MainWindow()

_trayService = new TrayService(this);
_trayService.UpdateStatus();

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

protected override void OnOpened(EventArgs e)
Expand Down
8 changes: 0 additions & 8 deletions src/UniGetUI.Core.Data/CoreData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,6 @@ public static string UniGetUIExecutableFile
/// </summary>
public static string ElevatorArgs = "";

/// <summary>
/// Set by the UI layer to bring the main window to the foreground and wait until it is.
/// Called right before a UAC prompt is triggered so the app owns the foreground and can
/// delegate it to the consent UI (fixes prompts hiding behind the window with secure desktop off).
/// Null in headless mode, where no window exists to activate.
/// </summary>
public static Func<Task>? BringMainWindowToForegroundAsync;

/// <summary>
/// This method will return the most appropriate data directory.
/// If the new directory exists, it will be used.
Expand Down
15 changes: 7 additions & 8 deletions src/UniGetUI.Core.Tools/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -752,19 +752,18 @@
private static extern bool AllowSetForegroundWindow(int dwProcessId);

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

var bringToFront = CoreData.BringMainWindowToForegroundAsync;
if (bringToFront is not null)
await bringToFront();
AllowSetForegroundWindow(ASFW_ANY);
Comment thread
GabrielDuf marked this conversation as resolved.
}

Expand Down Expand Up @@ -824,7 +823,7 @@

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

p.Start();
await p.WaitForExitAsync();
Expand Down Expand Up @@ -1523,7 +1522,7 @@
}

Task reads = Task.WhenAll(stdout, stderr);
reads.ContinueWith(

Check warning on line 1525 in src/UniGetUI.Core.Tools/Tools.cs

View workflow job for this annotation

GitHub Actions / Linux (Avalonia)

Do not create tasks without passing a TaskScheduler (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2008)

Check warning on line 1525 in src/UniGetUI.Core.Tools/Tools.cs

View workflow job for this annotation

GitHub Actions / Windows (Avalonia)

Do not create tasks without passing a TaskScheduler (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2008)

Check warning on line 1525 in src/UniGetUI.Core.Tools/Tools.cs

View workflow job for this annotation

GitHub Actions / Windows (Avalonia)

Do not create tasks without passing a TaskScheduler (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2008)

Check warning on line 1525 in src/UniGetUI.Core.Tools/Tools.cs

View workflow job for this annotation

GitHub Actions / Linux (NativeAOT)

Do not create tasks without passing a TaskScheduler (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2008)

Check warning on line 1525 in src/UniGetUI.Core.Tools/Tools.cs

View workflow job for this annotation

GitHub Actions / Windows (NativeAOT)

Do not create tasks without passing a TaskScheduler (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2008)

Check warning on line 1525 in src/UniGetUI.Core.Tools/Tools.cs

View workflow job for this annotation

GitHub Actions / test-codebase

Do not create tasks without passing a TaskScheduler (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2008)

Check warning on line 1525 in src/UniGetUI.Core.Tools/Tools.cs

View workflow job for this annotation

GitHub Actions / test-codebase

Do not create tasks without passing a TaskScheduler (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2008)

Check warning on line 1525 in src/UniGetUI.Core.Tools/Tools.cs

View workflow job for this annotation

GitHub Actions / test-codebase

Do not create tasks without passing a TaskScheduler (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2008)

Check warning on line 1525 in src/UniGetUI.Core.Tools/Tools.cs

View workflow job for this annotation

GitHub Actions / test-codebase

Do not create tasks without passing a TaskScheduler (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2008)
completed => _ = completed.Exception,
TaskContinuationOptions.OnlyOnFaulted
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ protected override async Task<OperationVeredict> PerformOperation()
CancellationToken.ThrowIfCancellationRequested();

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

process.Start();
if (CancellationToken.IsCancellationRequested)
Expand Down
Loading