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

Move Settings deep link logic to Microsoft.PowerToys.Common.UI #13749

Merged
merged 4 commits into from
Oct 12, 2021

Conversation

stefansjfw
Copy link
Collaborator

Summary of the Pull Request

What is this about:

What is include in the PR:

How does someone test / validate:

Quality Checklist

  • Linked issue: [Settings] Support for deep-linking #7408
  • Communication: I've discussed this with core contributors in the issue.
  • Tests: Added/updated and all pass
  • Installer: Added/updated and all pass
  • Localization: All end user facing strings can be localized
  • Docs: Added/ updated
  • Binaries: Any new files are added to WXS / YML

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 Oct 11, 2021

@check-spelling-bot Report

Unrecognized words, please review:

  • stefan
Previously acknowledged words that are now absent Accessible available btn CIEXYZ coc CTriage dchristensen djsoref docsmsft dogancelik dupenv estdir Fody ftp ftps gmx htt ianjoneill inprivate installpowertoys itsme jakeoeding KERNELBASE listbox mfreadwrite mfuuid Nefario nitroin null nunit powertoyswiki PROGRAMFILES Radiobuttons sidepanel spamming systray ulazy windevbuildagents winstore xia XSmall xunit
Some files were were automatically ignored

These sample patterns would exclude them:

^src/modules/previewpane/UnitTests-MarkdownPreviewHandler/HelperFiles/MarkdownWithHTMLImageTag\.txt$

You should consider adding them to:

.github/actions/spell-check/excludes.txt

File matching is via Perl regular expressions.

To check these files, more of their words need to be in the dictionary than not. You can use patterns.txt to exclude portions, add items to the dictionary (e.g. by adding them to allow.txt), or fix typos.

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]:microsoft/PowerToys.git repository
on the stefan/move_settings_deep_link branch:

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spell-check/expect.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/spell-check/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);
'
(cat '.github/actions/spell-check/excludes.txt' - <<EOF
$should_exclude_patterns
EOF
) |grep .|
sort -f |
uniq > '.github/actions/spell-check/excludes.txt.temp' &&
mv '.github/actions/spell-check/excludes.txt.temp' '.github/actions/spell-check/excludes.txt'
}

comment_json=$(mktemp)
curl -L -s -S \
  --header "Content-Type: application/json" \
  "https://api.github.com/repos/microsoft/PowerToys/issues/comments/940164485" > "$comment_json"
comment_body=$(mktemp)
jq -r .body < "$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;
$_=<>;
s{<details>.*}{}s;
s{^#.*}{};
s{\n##.*}{};
s{(?:^|\n)\s*\*}{}g;
s{\s+}{ }g;
print' < "$comment_body")
  

should_exclude_patterns=$(perl -e '$/=undef;
$_=<>;
exit unless s{(?:You should consider excluding directory paths|You should consider adding them to).*}{}s;
s{.*These sample patterns would exclude them:}{}s;
s{.*\`\`\`([^`]*)\`\`\`.*}{$1}m;
print' < "$comment_body" | grep . || true)

update_files
rm $comment_body
git add -u
If you see a bunch of garbage

If it relates to a ...

well-formed pattern

See if there's a pattern that would match it.

If not, try writing one and adding it to the patterns.txt file.

Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

Note that patterns can't match multiline strings.

binary-ish string

Please add a file path to the excludes.txt file instead of just accepting the garbage.

File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

{
public static class SettingsDeepLink
{
public static void OpenSettings(string powerToysRelativePath, string module)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should be providing path here, it is prone to errors. Also module should be probably enum not just a string

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

path can be different, depending on modules' directory structure

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added enum

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, but this is an abstraction, modules should not care where are settings.exe stored and knowing the name of exe - from a module point I want to open settings for my module, I don't care where it is stored, what logic is used there. Exposing this information (path, module name) here breaks encapsulation and abstraction

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree. But as it is as simple as starting new process with path to .exe in the background, there's not much we can do here. I can remove first argument as both modules have same path to the exe at the moment, but as soon as some other module differs, this argument will be restored

Copy link
Contributor

Choose a reason for hiding this comment

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

you should be able to do something much simpler. We define url launch protocol for PowerToys (defined during installation)

image

This allows us to launch PT by using its url protocol, which is "powertoys:"
So you should be able to do this:

Process.Start(new ProcessStartInfo("powertoys:--open-settings=ColorPicker") { UseShellExecute = true }); (arguments might need to be passed as a second parameter, not sure if this works)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, I'm having trouble passing the argument this way

Copy link
Contributor

@martinchrzan martinchrzan Oct 11, 2021

Choose a reason for hiding this comment

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

How does it even work? If I run "C:\Program Files\PowerToys\PowerToys.exe" "--open-settings=ColorPicker" from a cmd it does not open that settings page

Copy link
Contributor

Choose a reason for hiding this comment

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

Support for that is only in the master branch I believe. Not yet in shipping version.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using url protocol and passing argument only works if PT is not running at all. Argument is processed and specific settings page is opened. If PT is already running in the background (tray icon is there), and we only need to show Settings app, argument is being ignored. So, this doesn't work unfortunately

return "VideoConference";
default:
{
return string.Empty;
Copy link
Collaborator Author

@stefansjfw stefansjfw Oct 11, 2021

Choose a reason for hiding this comment

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

on empty string, default settings window (Overview) will be opened. no need for panic here

@niels9001
Copy link
Contributor

@stefansjfw can we get this merged? I need it for ImageResizer :)

@stefansjfw
Copy link
Collaborator Author

@stefansjfw can we get this merged? I need it for ImageResizer :)

yes. I'll continue trying to make it work with PT url protocol

@stefansjfw stefansjfw merged commit 7e8e954 into master Oct 12, 2021
@stefansjfw stefansjfw deleted the stefan/move_settings_deep_link branch October 12, 2021 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants