Fix mouse backward and forward buttons not updating the in-app buttons #5242
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.
Fix mouse backward and forward buttons not updating the in-app buttons
Pull Request Type
Related issue
closes #4408
Description
Inspired by a comment on the navigation history dropdown pull request about fixing the mouse button issue by switching to an Electron-only API, I decided to see if there was an alternative way to solve it that without making existing functionality Electron only. I found the Navigation API which is supported in Electron, Android WebView as well as Chromium browsers (both desktop and mobile) https://developer.mozilla.org/en-US/docs/Web/API/Navigation_API#browser_compatibility. While it isn't supported in Firefox and Safari, that will only affect the web build in the unofficial FreeTubeAndroid fork and I think there is a good argument to be made that the back and forward buttons aren't needed there anyway because you can just use the ones built-into the web browser, so in those two browsers, the back and forward buttons will always be enabled, so they are still usable, they just won't get disabled when you can't navigate in a certain direction.
With that out of the way, here is some information to the pull request itself. As the Navigation API provides
canGoForward
andcanGoBack
properties, we no longer need our logic that relies on trying to track the navigation index ourselves. It also means we no longer need to send an IPC message from the main process into the window when the user triggers the navigation through the app menu or the keyboard shortcuts and can just use the convenient.goBack()
and.goForward()
methods on the webContents instance, as the Navigation API keeps track of whether you can go forwards or back for us.Testing
If you have a mouse that has extra buttons to let you navigate back and forwards, test that those work and that the back and forward buttons in the app update their enabled and disabled state correctly.
I know it doesn't count for much as I opened the pull request, but my mouse has those buttons and for me it worked correctly.
Regression tests:
Back
andForward
entries in theView
app menu still work and update the back and forward arrow button disabled state correctly.Desktop