-
-
Notifications
You must be signed in to change notification settings - Fork 919
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
Make port_handler work with PWA #3958
Conversation
✅ Deploy Preview for origin-betaflight-app ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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.
Glad that this works, but targetting vue componets with jquery is a slippery slope and can lead to unexpected results.
In order to connect vue to the rest of the things it's better to use something like event bus.
We have a basic example with config storage
https://github.com/betaflight/betaflight-configurator/blob/18eb8dd1b20a721fd1ec082d1ac306bb1f9b6d6d/src/components/eventBus.js
EventBus.$emit(`config-storage:set`, 'element'); |
betaflight-configurator/src/components/port-picker/PortsInput.vue
Lines 81 to 86 in 18eb8dd
mounted() { | |
EventBus.$on('config-storage:set', this.setShowVirtual); | |
}, | |
destroyed() { | |
EventBus.$off('config-storage:set', this.setShowVirtual); | |
}, |
src/js/webSerial.js
Outdated
navigator.serial.addEventListener("connect", device => { | ||
this.dispatchEvent(new CustomEvent("addedDevice", { detail: device.target })); | ||
}); | ||
|
||
navigator.serial.addEventListener("disconnect", device => { | ||
this.dispatchEvent(new CustomEvent("removedDevice", { detail: device.target })); | ||
}); |
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.
Wondering if we need this here? We are not using the event.detail
later on and all this is doing is proxying the events.
Could we just use navigator.serial
directly in the port_handler under the isWeb
branch?
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.
I think is good to "isolate" the webserial. If we have a webserial.js to isolate all the serial operations, then it's responsible of indicating all the important events, like sending datan, new devices, etc.
I think more, it will be good to send events like "connected", "disconnected", etc. Will make a lot more simple the rest of the code, but maybe for other PR.
About the event detail, I will remove it, now we don't use it, but maybe we can act different in a future depending on the type of device connected or similar. My idea was to "add" or "remove" the device from the list in the port handler without calling the "getPorts" again, but the code is not ready for that, at least while we maintain compatibility with nw.js.
@chmelevskij two doubts about the EventBus code. The Config Storage is emitting the message, with the text 'element' and not the value of the variable. It's that right? |
c93c1b5
to
3f5c126
Compare
Pushed changes. I was trying to do a complete refactor, and I did it, but the serial_backend.js was not happy. I will continue working in the complete refactor that will make this code a lot simpler. |
great work!
|
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.
- approving on basis of future fixes/refactors.
- will need rebase on the DFU mode fix.
The auto-connect switch is missing. I don't have modified the behaviour, but of course is one of the things missing. |
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.
- Perhaps DEFAULT_PORT should be
Make selection
- cannot connect without choosing first. - If device already has permission it should be pre-selected (after disconnect - connect)
- After selecting find my device it reverts to manual. So connect does not work.
3b0c55f
to
5b7f7c8
Compare
The default port, we can add what we want, it always tries to show the "best" device detected. For this reason if there is not device, manual is not a bad option. |
5b7f7c8
to
f3a9541
Compare
Fixed some sonar issues too... |
f3a9541
to
5e605c2
Compare
d36f99b
to
a9c862a
Compare
@haslinghuis rebased!! |
Added a little commit to hide the baud selection in port-picker when virtual is selected |
Added new commit to show the port override option for "manual". It does not use it, but now is ready for it. |
The latest one, the state of the port was not correct when loading the page, only reacted to changes in the options checkbox. Now it loads the value when loading the component too. |
Fresh build. After After giving permission Doing that again we get: Note all |
Ok, I think I can look at it later... |
@haslinghuis can you test this new version? |
@McGiverGim yes that works. Only thing left is selecting the firmware port if detected instead of manual. |
I can't reproduce it. In my case, it detects the betaflight port perfectly, each time. Maybe you're using Linux? My VM with Linux it's dead, I can't try right now. |
On startup manual is selected - STM32 entry is in portpicker list. Screencast.from.16-05-24.19.42.36.webm |
Yes, I understand the problem, but in my Windows it is detected correctly each time. I suspect it has something to do with Linux, I will try to recover the VM... |
Debian 12; what is the expected behavior here? |
Quality Gate failedFailed conditions |
@haslinghuis fixed. |
|
This makes port_handler work again. This fixes several problems with PWA, like the auto-connect, save and reboot and the list of ports in the combo. I'm sure some things can be done better but it's difficult maintaining nwjs compatibility.
Some things to note:
For the rest, I pushed the PR to let test if this fixes the CLI and Presets problems.