Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PT Run] WindowWalker: Refactor code, fix some bugs, hide UWP non-windows, prepare code for new features #15441

Merged
merged 36 commits into from
Jan 25, 2022

Conversation

htcfreek
Copy link
Collaborator

@htcfreek htcfreek commented Jan 11, 2022

Note: This is a follow up of the closed PR #15329 which had merge mistakes.


Summary of the Pull Request

What is this about:
This PR prepares the implementation of two new features into WindowWalker. They are asked in issue #6084:

  • Close the window.
  • Kill the window process/app.

For this new features we need some code changes and additional information about a window/app. And there are some bugs we should fix before implementing the new features.

What is included in this PR:
Code refactoring:

  • Refactor of the Window.cs class, implementation of a new WindowProcess.cs class and improvements to the process cache data to have less queries for static information.
  • Moving process information and code into own class.
  • Filter child window of AppFrameHost.exe by class instead of process id.
  • Improve SearchController.cs class to speed up search times.

Requirements for new features and fixes:

  • Adding additional properties for the WindowProcess (class): ThreadId, IsFullAccessDenied, IsUwpApp, DoesExist, IsShellProcess
  • Adding additional properties to Window class: CloakedState, IsCloaked

Fixes:

  • A fix for the PID which is zero for win32 applications.
  • Improved detection of process ID and thread ID
  • Ignore cloaked uwp non-windows in result list.
  • We now closing process handles we don't need anymore.

Remarks:

  • For debugging and testing I have added a tool-tip.

How does someone test / validate:

General changes: Build local and validate information in tool tip.

Speed improvements:
System for test before improvement: Win10 Pro; 2 core [Intel i7-Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz]; Ram 4,0 GB (used: ?? GB) => Times from older logs with less open windows.
System for test after improvement: Win10 Pro; 1 core [Intel i7-Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz]; Ram 2,0 GB (used: 1,7 GB)
Open windows: 65 (explorer: 20, Calculator: 20, Editor: 20, Other windows: 5)
Search term: "<explorer"

QueryTimeTestLog.txt

Query remarks Before code improvements After code improvements
After cold start of PT up to 1900 ms Up to 25 ms
On Hotkey invoke (second time) Up to 800 ms Up to 5 ms

Screenshots:

Tool tip with debug information:
image

We now can check if the process of a window equals the shell process (taskbar, start menu, ...):
image

Properties of an hidden (preloaded) uwp app window:
image

Now hidden uwp app windows aren't shown anymore:
image

Quality Checklist

Contributor License Agreement (CLA)

A CLA must be signed. If not, go over here and sign the CLA.

@github-actions
Copy link

github-actions bot commented Jan 11, 2022

@check-spelling-bot Report

🔴 Please review

See the files view or the action log for details.

Unrecognized words (3)

Hostbackdropbrush
Tickness
Visibel

Previously acknowledged words that are now absent ChaseKnowlden CleanCodeDeveloper CTLCOLORSTATIC Deuchert efgh errc Grayscale iccex ICONINFORMATION INITCOMMONCONTROLSEX INSTALLLOGATTRIBUTES INSTALLLOGMODE INSTALLUILEVEL MAINICON MAKELPARAM msiexec MSIINSTALLER NATIVEFNTCTL netlify Qin rdeveen rexit SETRANGE SETSTEP sregex STEPIT symlink UITo We'd
To accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the [email protected]:htcfreek/PowerToys.git repository
on the PT_ImproveWwNew branch:

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spelling/whitelist.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spelling/expect.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
}

comment_json=$(mktemp)
curl -L -s -S \
-H "Content-Type: application/json" \
"https://api.github.com/repos/microsoft/PowerToys/issues/comments/1009925228" > "$comment_json"
comment_body=$(mktemp)
jq -r ".body // empty" "$comment_json" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")

patch_add=$(perl -e '$/=undef; $_=<>; if (m{Unrecognized words[^<]*</summary>\n*```\n*([^<]*)```\n*</details>$}m) { print "$1" } elsif (m{Unrecognized words[^<]*\n\n((?:\w.*\n)+)\n}m) { print "$1" };' < "$comment_body")

update_files
rm $comment_body
git add -u

@github-actions
Copy link

github-actions bot commented Jan 11, 2022

@check-spelling-bot Report

🔴 Please review

See the files view or the action log for details.

Unrecognized words (5)

childs
Hostbackdropbrush
leaszt
Tickness
Visibel

Previously acknowledged words that are now absent ChaseKnowlden CleanCodeDeveloper CTLCOLORSTATIC Deuchert efgh errc Grayscale iccex ICONINFORMATION INITCOMMONCONTROLSEX INSTALLLOGATTRIBUTES INSTALLLOGMODE INSTALLUILEVEL MAINICON MAKELPARAM msiexec MSIINSTALLER NATIVEFNTCTL netlify Qin rdeveen rexit SETRANGE SETSTEP sregex STEPIT symlink UITo We'd
To accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the [email protected]:htcfreek/PowerToys.git repository
on the PT_ImproveWwNew branch:

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spelling/whitelist.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spelling/expect.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
}

comment_json=$(mktemp)
curl -L -s -S \
-H "Content-Type: application/json" \
"https://api.github.com/repos/microsoft/PowerToys/issues/comments/1009943535" > "$comment_json"
comment_body=$(mktemp)
jq -r ".body // empty" "$comment_json" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")

patch_add=$(perl -e '$/=undef; $_=<>; if (m{Unrecognized words[^<]*</summary>\n*```\n*([^<]*)```\n*</details>$}m) { print "$1" } elsif (m{Unrecognized words[^<]*\n\n((?:\w.*\n)+)\n}m) { print "$1" };' < "$comment_body")

update_files
rm $comment_body
git add -u

@github-actions
Copy link

github-actions bot commented Jan 11, 2022

@check-spelling-bot Report

🔴 Please review

See the files view or the action log for details.

Unrecognized words (7)

childs
Hostbackdropbrush
invisble
leaszt
thet
Tickness
Visibel

Previously acknowledged words that are now absent ChaseKnowlden CleanCodeDeveloper CTLCOLORSTATIC Deuchert efgh errc Grayscale iccex ICONINFORMATION INITCOMMONCONTROLSEX INSTALLLOGATTRIBUTES INSTALLLOGMODE INSTALLUILEVEL MAINICON MAKELPARAM msiexec MSIINSTALLER NATIVEFNTCTL netlify Qin rdeveen rexit SETRANGE SETSTEP sregex STEPIT symlink UITo We'd
To accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the [email protected]:htcfreek/PowerToys.git repository
on the PT_ImproveWwNew branch:

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spelling/whitelist.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spelling/expect.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
}

comment_json=$(mktemp)
curl -L -s -S \
-H "Content-Type: application/json" \
"https://api.github.com/repos/microsoft/PowerToys/issues/comments/1009964777" > "$comment_json"
comment_body=$(mktemp)
jq -r ".body // empty" "$comment_json" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")

patch_add=$(perl -e '$/=undef; $_=<>; if (m{Unrecognized words[^<]*</summary>\n*```\n*([^<]*)```\n*</details>$}m) { print "$1" } elsif (m{Unrecognized words[^<]*\n\n((?:\w.*\n)+)\n}m) { print "$1" };' < "$comment_body")

update_files
rm $comment_body
git add -u

@github-actions
Copy link

github-actions bot commented Jan 11, 2022

@check-spelling-bot Report

🔴 Please review

See the files view or the action log for details.

Unrecognized words (1)

instantiable

Previously acknowledged words that are now absent ChaseKnowlden CleanCodeDeveloper CTLCOLORSTATIC Deuchert efgh errc Grayscale iccex ICONINFORMATION INITCOMMONCONTROLSEX INSTALLLOGATTRIBUTES INSTALLLOGMODE INSTALLUILEVEL MAINICON MAKELPARAM msiexec MSIINSTALLER NATIVEFNTCTL netlify Qin rdeveen rexit SETRANGE SETSTEP sregex STEPIT symlink UITo We'd
To accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the [email protected]:htcfreek/PowerToys.git repository
on the PT_ImproveWwNew branch:

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spelling/whitelist.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spelling/expect.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
}

comment_json=$(mktemp)
curl -L -s -S \
-H "Content-Type: application/json" \
"https://api.github.com/repos/microsoft/PowerToys/issues/comments/1010023560" > "$comment_json"
comment_body=$(mktemp)
jq -r ".body // empty" "$comment_json" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")

patch_add=$(perl -e '$/=undef; $_=<>; if (m{Unrecognized words[^<]*</summary>\n*```\n*([^<]*)```\n*</details>$}m) { print "$1" } elsif (m{Unrecognized words[^<]*\n\n((?:\w.*\n)+)\n}m) { print "$1" };' < "$comment_body")

update_files
rm $comment_body
git add -u

@htcfreek htcfreek self-assigned this Jan 11, 2022
@htcfreek htcfreek added Idea-Enhancement New feature or request on an existing product Issue-Bug Something isn't working Issue-Refactoring We want to adjust code Product-PowerToys Run Improved app launch PT Run (Win+R) Window Run-Plugin Things that relate with PowerToys Run's plugin interface and removed Issue-Bug Something isn't working Idea-Enhancement New feature or request on an existing product labels Jan 11, 2022
@htcfreek htcfreek marked this pull request as ready for review January 11, 2022 15:14
@htcfreek htcfreek changed the title [PT Run] WindowWalker: Refactor code, fix some bugs, hide UWP non-windows [PT Run] WindowWalker: Refactor code, fix some bugs, hide UWP non-windows, prepare code for new features Jan 23, 2022
@htcfreek
Copy link
Collaborator Author

@davidegiacometti
Can you please take a last look on the code before I mark this PR as ready to review. Thank you.

@davidegiacometti
Copy link
Collaborator

Will review later

Copy link
Collaborator

@davidegiacometti davidegiacometti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Tested and working as expected.

@htcfreek htcfreek marked this pull request as ready for review January 23, 2022 20:27
@htcfreek htcfreek requested review from crutkas and removed request for crutkas January 23, 2022 20:32
@crutkas
Copy link
Member

crutkas commented Jan 24, 2022

@jaimecbernardo can someone look at this?

@jaimecbernardo jaimecbernardo self-requested a review January 24, 2022 18:16
Copy link
Collaborator

@jaimecbernardo jaimecbernardo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Great work here!

@jaimecbernardo
Copy link
Collaborator

Just waiting for a second pair of eyes from @yuyoyuppe and then this can go in.

@htcfreek
Copy link
Collaborator Author

@jaimecbernardo
Should I add a sentence to devdocs why we have the event handler in main method? I can do this in the next PR when adding the context menu.

(I personally think we don't need this event handler and can remove it.)

@jaimecbernardo
Copy link
Collaborator

@jaimecbernardo Should I add a sentence to devdocs why we have the event handler in main method? I can do this in the next PR when adding the context menu.

(I personally think we don't need this event handler and can remove it.)

I'm OK with removing it if you think it's not needed. (pending review, of course, would need to consider the implications)

@htcfreek
Copy link
Collaborator Author

@jaimecbernardo Should I add a sentence to devdocs why we have the event handler in main method? I can do this in the next PR when adding the context menu.
(I personally think we don't need this event handler and can remove it.)

I'm OK with removing it if you think it's not needed. (pending review, of course, would need to consider the implications)

Obsolete code is removed. PR is ready. 🚀
Let's wait for the review form @yuyoyuppe and then merge it in (for 0.55.0).

@htcfreek htcfreek added the Needs-Review This Pull Request awaits the review of a maintainer. label Jan 24, 2022
Copy link
Contributor

@yuyoyuppe yuyoyuppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Refactoring We want to adjust code Needs-Review This Pull Request awaits the review of a maintainer. Product-PowerToys Run Improved app launch PT Run (Win+R) Window Run-Plugin Things that relate with PowerToys Run's plugin interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants