mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
Dependencies: Upgrade WinUIEx to 2.8.0 (#40639)
## Summary of the Pull Request This change upgrades the WinUIEx NuGet package from version 2.2.0 to 2.8.0. - Prevents the window itself from taking focus when it should not. - Removes dead code from Settings.UI (the code triggered error [WinUIEX1001](https://dotmorten.github.io/WinUIEx/rules/WinUIEx1001.html) -- Window.Current is always null). ## PR Checklist - [x] Closes: #40637 - [x] Closes: #7647 - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed I've built and run [projects utilizing WinUIEx](https://github.com/search?q=repo%3Amicrosoft%2FPowerToys+WinUIEx+path%3A*.*proj&type=code): - Microsoft.CmdPal.UI - MeasureToolUI - FileLocksmithUI - EnvironmentVariables - AdvancedPaste - Peek.UI - RegistryPreview - PowerToys.Settings - Hosts
This commit is contained in:
@@ -108,7 +108,7 @@
|
|||||||
<PackageVersion Include="UnicodeInformation" Version="2.6.0" />
|
<PackageVersion Include="UnicodeInformation" Version="2.6.0" />
|
||||||
<PackageVersion Include="UnitsNet" Version="5.56.0" />
|
<PackageVersion Include="UnitsNet" Version="5.56.0" />
|
||||||
<PackageVersion Include="UTF.Unknown" Version="2.6.0" />
|
<PackageVersion Include="UTF.Unknown" Version="2.6.0" />
|
||||||
<PackageVersion Include="WinUIEx" Version="2.2.0" />
|
<PackageVersion Include="WinUIEx" Version="2.8.0" />
|
||||||
<PackageVersion Include="WPF-UI" Version="3.0.5" />
|
<PackageVersion Include="WPF-UI" Version="3.0.5" />
|
||||||
<PackageVersion Include="WyHash" Version="1.0.5" />
|
<PackageVersion Include="WyHash" Version="1.0.5" />
|
||||||
<PackageVersion Include="WixToolset.Heat" Version="5.0.2" />
|
<PackageVersion Include="WixToolset.Heat" Version="5.0.2" />
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
// Copyright (c) Microsoft Corporation
|
|
||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
||||||
// See the LICENSE file in the project root for more information.
|
|
||||||
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UI.Activation
|
|
||||||
{
|
|
||||||
// For more information on understanding and extending activation flow see
|
|
||||||
// https://github.com/Microsoft/WindowsTemplateStudio/blob/master/docs/activation.md
|
|
||||||
internal abstract class ActivationHandler
|
|
||||||
{
|
|
||||||
public abstract bool CanHandle(object args);
|
|
||||||
|
|
||||||
public abstract Task HandleAsync(object args);
|
|
||||||
}
|
|
||||||
|
|
||||||
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "abstract T and abstract")]
|
|
||||||
internal abstract class ActivationHandler<T> : ActivationHandler
|
|
||||||
where T : class
|
|
||||||
{
|
|
||||||
public override async Task HandleAsync(object args)
|
|
||||||
{
|
|
||||||
await HandleInternalAsync(args as T).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool CanHandle(object args)
|
|
||||||
{
|
|
||||||
// CanHandle checks the args is of type you have configured
|
|
||||||
return args is T && CanHandleInternal(args as T);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Override this method to add the activation logic in your activation handler
|
|
||||||
protected abstract Task HandleInternalAsync(T args);
|
|
||||||
|
|
||||||
// You can override this method to add extra validation on activation args
|
|
||||||
// to determine if your ActivationHandler should handle this activation args
|
|
||||||
protected virtual bool CanHandleInternal(T args)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
// Copyright (c) Microsoft Corporation
|
|
||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
||||||
// See the LICENSE file in the project root for more information.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using Microsoft.PowerToys.Settings.UI.Services;
|
|
||||||
using Windows.ApplicationModel.Activation;
|
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UI.Activation
|
|
||||||
{
|
|
||||||
internal sealed class DefaultActivationHandler : ActivationHandler<IActivatedEventArgs>
|
|
||||||
{
|
|
||||||
private readonly Type navElement;
|
|
||||||
|
|
||||||
public DefaultActivationHandler(Type navElement)
|
|
||||||
{
|
|
||||||
this.navElement = navElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override async Task HandleInternalAsync(IActivatedEventArgs args)
|
|
||||||
{
|
|
||||||
// When the navigation stack isn't restored, navigate to the first page and configure
|
|
||||||
// the new page by passing required information in the navigation parameter
|
|
||||||
object arguments = null;
|
|
||||||
if (args is LaunchActivatedEventArgs launchArgs)
|
|
||||||
{
|
|
||||||
arguments = launchArgs.Arguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
NavigationService.Navigate(navElement, arguments);
|
|
||||||
await Task.CompletedTask.ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool CanHandleInternal(IActivatedEventArgs args)
|
|
||||||
{
|
|
||||||
// None of the ActivationHandlers has handled the app activation
|
|
||||||
return NavigationService.Frame.Content == null && navElement != null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
// Copyright (c) Microsoft Corporation
|
|
||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
||||||
// See the LICENSE file in the project root for more information.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using Microsoft.PowerToys.Settings.UI.Activation;
|
|
||||||
using Microsoft.UI.Xaml;
|
|
||||||
using Microsoft.UI.Xaml.Controls;
|
|
||||||
using Windows.ApplicationModel.Activation;
|
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UI.Services
|
|
||||||
{
|
|
||||||
// For more information on understanding and extending activation flow see
|
|
||||||
// https://github.com/Microsoft/WindowsTemplateStudio/blob/master/docs/activation.md
|
|
||||||
internal sealed class ActivationService
|
|
||||||
{
|
|
||||||
private readonly App app;
|
|
||||||
private readonly Type defaultNavItem;
|
|
||||||
private Lazy<UIElement> shell;
|
|
||||||
|
|
||||||
private object lastActivationArgs;
|
|
||||||
|
|
||||||
public ActivationService(App app, Type defaultNavItem, Lazy<UIElement> shell = null)
|
|
||||||
{
|
|
||||||
this.app = app;
|
|
||||||
this.shell = shell;
|
|
||||||
this.defaultNavItem = defaultNavItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task ActivateAsync(object activationArgs)
|
|
||||||
{
|
|
||||||
if (IsInteractive(activationArgs))
|
|
||||||
{
|
|
||||||
// Initialize services that you need before app activation
|
|
||||||
// take into account that the splash screen is shown while this code runs.
|
|
||||||
await InitializeAsync().ConfigureAwait(false);
|
|
||||||
|
|
||||||
// Do not repeat app initialization when the Window already has content,
|
|
||||||
// just ensure that the window is active
|
|
||||||
if (Window.Current.Content == null)
|
|
||||||
{
|
|
||||||
// Create a Shell or Frame to act as the navigation context
|
|
||||||
Window.Current.Content = shell?.Value ?? new Frame();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Depending on activationArgs one of ActivationHandlers or DefaultActivationHandler
|
|
||||||
// will navigate to the first page
|
|
||||||
await HandleActivationAsync(activationArgs).ConfigureAwait(false);
|
|
||||||
lastActivationArgs = activationArgs;
|
|
||||||
|
|
||||||
if (IsInteractive(activationArgs))
|
|
||||||
{
|
|
||||||
// Ensure the current window is active
|
|
||||||
Window.Current.Activate();
|
|
||||||
|
|
||||||
// Tasks after activation
|
|
||||||
await StartupAsync().ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task InitializeAsync()
|
|
||||||
{
|
|
||||||
await Task.CompletedTask.ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task HandleActivationAsync(object activationArgs)
|
|
||||||
{
|
|
||||||
var activationHandler = GetActivationHandlers()
|
|
||||||
.FirstOrDefault(h => h.CanHandle(activationArgs));
|
|
||||||
|
|
||||||
if (activationHandler != null)
|
|
||||||
{
|
|
||||||
await activationHandler.HandleAsync(activationArgs).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IsInteractive(activationArgs))
|
|
||||||
{
|
|
||||||
var defaultHandler = new DefaultActivationHandler(defaultNavItem);
|
|
||||||
if (defaultHandler.CanHandle(activationArgs))
|
|
||||||
{
|
|
||||||
await defaultHandler.HandleAsync(activationArgs).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task StartupAsync()
|
|
||||||
{
|
|
||||||
await Task.CompletedTask.ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IEnumerable<ActivationHandler> GetActivationHandlers()
|
|
||||||
{
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool IsInteractive(object args)
|
|
||||||
{
|
|
||||||
return args is IActivatedEventArgs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -24,12 +24,6 @@ namespace Microsoft.PowerToys.Settings.UI.Services
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (frame == null)
|
|
||||||
{
|
|
||||||
frame = Window.Current.Content as Frame;
|
|
||||||
RegisterFrameEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user