Fix: Rerouted the "close tab" action via event listener in WebView#18038
Fix: Rerouted the "close tab" action via event listener in WebView#18038Lamparter wants to merge 9 commits intofiles-community:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes the "close tab" action shortcuts (Ctrl+W and Ctrl+F4) on the Release Notes page by implementing JavaScript keyboard event listeners in the WebView that communicate with the Files.App action system.
Changes:
- Added JavaScript keyboard event listener to capture close tab shortcuts within the WebView
- Refactored link-click handling to use structured JSON messages instead of plain strings
- Created a WebMessage DTO class to handle typed messages from JavaScript
- Added JavaScriptModifiers mapping in HotKey class to translate C# modifiers to JavaScript event properties
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/Files.App/Views/ReleaseNotesPage.xaml.cs | Added keyboard shortcut handling via JavaScript injection, refactored message handlers to use typed WebMessage objects, and added key normalization helper |
| src/Files.App/Data/Messages/WebMessage.cs | New DTO class for deserializing JSON messages from WebView JavaScript |
| src/Files.App/Data/Commands/HotKey/HotKey.cs | Added JavaScriptModifiers dictionary to map KeyModifiers to JavaScript event property names |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
No idea why the tests are failing |
The tests passed after I reran them 🎉 Does this also enable other keyboard shortcuts? (I haven't reviewed or tested these changes yet) |
No, that would require additional work. |
|
The same issue preventing |
|
I can do that, but it will require additional work. |
|
If we can figure out why the shortcuts aren't already detected, that would be ideal and would avoid a lot of extra work. It might even help us with the touchpad scrolling issue. |
|
I don't understand enough about webview2 in winappsdk to figure out why that happens unfortunately |
| } | ||
| }); | ||
|
|
||
| window.addEventListener('keydown', function(event) { |
There was a problem hiding this comment.
Adding an event listener seems to be the simplest workaround. I wonder if we can then reroute the event to MainPage and let it handle the shortcut from there.
There was a problem hiding this comment.
After further research, it looks like enabling AllowHostInputProcessing might be a better approach to take.
There was a problem hiding this comment.
I tried it but I can't figure out how to enable that flag.
It requires the latest version of WebView2, which is fine, but AllowHostInputProcessing isn't a setting that can be just 'enabled' in the same sense that the other webview2 settings can.
There was a problem hiding this comment.
Do you plan to continue working on this or should we close the PR?
There was a problem hiding this comment.
We can close the PR for now until I figure out how the new AllowHostInputProcessing flag can be enabled, in which case I'll open another PR 🙂
Resolved / Related Issues
Steps used to test these changes
This PR implements the "close current tab" action into the release notes page WebView by an injected event listener.