-
Notifications
You must be signed in to change notification settings - Fork 43
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
Display a friendlier name for "Open With" menus in Windows #225
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e3c5e0c
Specify FriendlyTypeName on Windows file type association
jaimergp 1ae9bd2
allow errors on cleanup
jaimergp 6f8698b
try indexed icon
jaimergp 5a0ec67
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c037a7f
expose app_name and AUMI too
jaimergp 774ecfb
Enable some code cleanups
jaimergp b9dfa8e
Debug on Windows
jaimergp 006c579
do not quote icons
jaimergp 869665a
pre-commit
jaimergp 7a03b1d
add news
jaimergp cdb3cf4
add docstrings
jaimergp e31fb56
consistent types
jaimergp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
from .win_utils.knownfolders import folder_path as windows_folder_path | ||
from .win_utils.knownfolders import windows_terminal_settings_files | ||
from .win_utils.registry import ( | ||
notify_shell_changes, | ||
register_file_extension, | ||
register_url_protocol, | ||
unregister_file_extension, | ||
|
@@ -198,14 +199,19 @@ def create(self) -> Tuple[Path, ...]: | |
|
||
for location in self.menu.terminal_profile_locations: | ||
self._add_remove_windows_terminal_profile(location, remove=False) | ||
self._register_file_extensions() | ||
self._register_url_protocols() | ||
changed_extensions = self._register_file_extensions() | ||
changed_protocols = self._register_url_protocols() | ||
if changed_extensions or changed_protocols: | ||
notify_shell_changes() | ||
|
||
return paths | ||
|
||
def remove(self) -> Tuple[Path, ...]: | ||
self._unregister_file_extensions() | ||
self._unregister_url_protocols() | ||
changed_extensions = self._unregister_file_extensions() | ||
changed_protocols = self._unregister_url_protocols() | ||
if changed_extensions or changed_protocols: | ||
notify_shell_changes() | ||
|
||
for location in self.menu.terminal_profile_locations: | ||
self._add_remove_windows_terminal_profile(location, remove=True) | ||
|
||
|
@@ -433,7 +439,7 @@ def _cmd_ftype(identifier, command=None, query=False, remove=False) -> Completed | |
arg = f"{identifier}=" | ||
return logged_run(["cmd", "/D", "/C", f"assoc {arg}"], check=True) | ||
|
||
def _register_file_extensions(self): | ||
def _register_file_extensions(self) -> bool: | ||
"""WIP""" | ||
extensions = self.metadata["file_extensions"] | ||
if not extensions: | ||
|
@@ -444,7 +450,16 @@ def _register_file_extensions(self): | |
exts = list(dict.fromkeys([ext.lower() for ext in extensions])) | ||
for ext in exts: | ||
identifier = self._ftype_identifier(ext) | ||
register_file_extension(ext, identifier, command, icon=icon, mode=self.menu.mode) | ||
register_file_extension( | ||
ext, | ||
identifier, | ||
command, | ||
icon=icon, | ||
app_name=self.render_key("name"), | ||
app_user_model_id=self._app_user_model_id(), | ||
mode=self.menu.mode, | ||
) | ||
return True | ||
|
||
def _unregister_file_extensions(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here: return a |
||
extensions = self.metadata["file_extensions"] | ||
|
@@ -455,6 +470,7 @@ def _unregister_file_extensions(self): | |
for ext in exts: | ||
identifier = self._ftype_identifier(ext) | ||
unregister_file_extension(ext, identifier, mode=self.menu.mode) | ||
return True | ||
|
||
def _register_url_protocols(self): | ||
"See https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa767914(v=vs.85)" # noqa | ||
|
@@ -465,7 +481,16 @@ def _register_url_protocols(self): | |
icon = self.render_key("icon") | ||
for protocol in protocols: | ||
identifier = self._ftype_identifier(protocol) | ||
register_url_protocol(protocol, command, identifier, icon=icon, mode=self.menu.mode) | ||
register_url_protocol( | ||
protocol, | ||
command, | ||
identifier, | ||
icon=icon, | ||
app_name=self.render_key("name"), | ||
app_user_model_id=self._app_user_model_id(), | ||
mode=self.menu.mode, | ||
) | ||
return True | ||
|
||
def _unregister_url_protocols(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here: return a |
||
protocols = self.metadata["url_protocols"] | ||
|
@@ -474,6 +499,7 @@ def _unregister_url_protocols(self): | |
for protocol in protocols: | ||
identifier = self._ftype_identifier(protocol) | ||
unregister_url_protocol(protocol, identifier, mode=self.menu.mode) | ||
return True | ||
|
||
def _app_user_model_id(self): | ||
aumi = self.render_key("app_user_model_id") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
### Enhancements | ||
|
||
* <news item> | ||
|
||
### Bug fixes | ||
|
||
* Display shortcut name in Windows' "Open with" menu entries. (#225) | ||
|
||
### Deprecations | ||
|
||
* <news item> | ||
|
||
### Docs | ||
|
||
* <news item> | ||
|
||
### Other | ||
|
||
* <news item> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't always return
bool
. I'd changereturn
toreturn False