CmdPal: Window Walker - reevaluate process type when window process is updated (#42317)

## Summary of the Pull Request

This PR moves `ProcessPackagingInspector.Inspect` from the
`WindowProcess` constructor to `UpdateProcessInfo`, ensuring the process
type is correctly re-evaluated when the window’s backing process changes
(as with UWP apps hosted in `ApplicationFrameHost.exe`).

See
4d47659ff9/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/Window.cs (L295-L350)

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Closes: #38353 
- [ ] **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
This commit is contained in:
Jiří Polášek
2025-10-13 18:52:24 +02:00
committed by GitHub
parent 4d47659ff9
commit 7c8b30246e
3 changed files with 25 additions and 7 deletions

View File

@@ -324,7 +324,7 @@ internal sealed class Window
// Correct the process data if the window belongs to a uwp app hosted by 'ApplicationFrameHost.exe'
// (This only works if the window isn't minimized. For minimized windows the required child window isn't assigned.)
if (string.Equals(_handlesToProcessCache[hWindow].Name, "ApplicationFrameHost.exe", StringComparison.OrdinalIgnoreCase))
if (_handlesToProcessCache[hWindow].IsUwpAppFrameHost)
{
new Task(() =>
{

View File

@@ -23,7 +23,7 @@ internal sealed class WindowProcess
/// <summary>
/// An indicator if the window belongs to an 'Universal Windows Platform (UWP)' process
/// </summary>
private readonly bool _isUwpAppFrameHost;
private bool _isUwpAppFrameHost;
/// <summary>
/// Gets the id of the process
@@ -126,6 +126,14 @@ internal sealed class WindowProcess
get; private set;
}
/// <summary>
/// Gets the type of the process (UWP app, packaged Win32 app, unpackaged Win32 app, ...).
/// </summary>
internal ProcessPackagingInfo ProcessType
{
get; private set;
}
/// <summary>
/// Initializes a new instance of the <see cref="WindowProcess"/> class.
/// </summary>
@@ -134,13 +142,10 @@ internal sealed class WindowProcess
/// <param name="name">New process name.</param>
internal WindowProcess(uint pid, uint tid, string name)
{
ProcessType = ProcessPackagingInfo.Empty;
UpdateProcessInfo(pid, tid, name);
ProcessType = ProcessPackagingInspector.Inspect((int)pid);
_isUwpAppFrameHost = string.Equals(Name, "ApplicationFrameHost.exe", StringComparison.OrdinalIgnoreCase);
}
public ProcessPackagingInfo ProcessType { get; private set; }
/// <summary>
/// Updates the process information of the <see cref="WindowProcess"/> instance.
/// </summary>
@@ -156,6 +161,10 @@ internal sealed class WindowProcess
// Process can be elevated only if process id is not 0 (Dummy value on error)
IsFullAccessDenied = (pid != 0) ? TestProcessAccessUsingAllAccessFlag(pid) : false;
// Update process type
ProcessType = ProcessPackagingInspector.Inspect((int)pid);
_isUwpAppFrameHost = string.Equals(Name, "ApplicationFrameHost.exe", StringComparison.OrdinalIgnoreCase);
}
/// <summary>

View File

@@ -11,4 +11,13 @@ internal sealed record ProcessPackagingInfo(
bool IsAppContainer,
string? PackageFullName,
int? LastError
);
)
{
public static ProcessPackagingInfo Empty { get; } = new(
Pid: 0,
Kind: ProcessPackagingKind.Unknown,
HasPackageIdentity: false,
IsAppContainer: false,
PackageFullName: null,
LastError: null);
}