1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-24 08:45:28 +03:00

Fix dfu permissions (#4438)

* Request permission before connecting DFU device

* Fix DFU permissions

* Little refactor
This commit is contained in:
Mark Haslinghuis 2025-04-26 11:58:17 +02:00 committed by GitHub
parent 3022548342
commit ddfc76217d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 9 deletions

View file

@ -90,6 +90,10 @@
"message": "--- I can't find my Bluetooth device---",
"description": "Option in the port selection dropdown to allow the user to give permissions to the system to access a Bluetooth device."
},
"portsSelectPermissionDFU": {
"message": "--- I can't find my DFU device ---",
"description": "Option in the port selection dropdown to allow the user to give permissions to the system to access a DFU device."
},
"bluetoothConnected": {
"message": "Connected to Bluetooth device: $1"
},

View file

@ -45,6 +45,9 @@
<option value="requestpermissionbluetooth">
{{ $t("portsSelectPermissionBluetooth") }}
</option>
<option value="requestpermissionusb">
{{ $t("portsSelectPermissionDFU") }}
</option>
</select>
</div>
<div id="auto-connect-and-baud">
@ -159,6 +162,8 @@ export default defineComponent({
EventBus.$emit("ports-input:request-permission");
} else if (value === "requestpermissionbluetooth") {
EventBus.$emit("ports-input:request-permission-bluetooth");
} else if (value === "requestpermissionusb") {
EventBus.$emit("ports-input:request-permission-usb");
} else {
EventBus.$emit("ports-input:change", value);
}

View file

@ -36,6 +36,7 @@ const PortHandler = new (function () {
PortHandler.initialize = function () {
EventBus.$on("ports-input:request-permission-bluetooth", () => this.requestDevicePermission("bluetooth"));
EventBus.$on("ports-input:request-permission", () => this.requestDevicePermission("serial"));
EventBus.$on("ports-input:request-permission-usb", () => this.requestDevicePermission("usb"));
EventBus.$on("ports-input:change", this.onChangeSelectedPort.bind(this));
// Use serial for all protocol events
@ -134,25 +135,27 @@ PortHandler.onChangeSelectedPort = function (port) {
/**
* Request permission for a device of the specified type
* @param {string} deviceType - Type of device ('serial' or 'bluetooth')
* @param {string} deviceType - Type of device ('serial', 'bluetooth', 'usb')
*/
PortHandler.requestDevicePermission = function (deviceType = "serial") {
// Determine whether to show all devices based on device type
const showAllDevices = deviceType === "serial" ? this.showAllSerialDevices : false;
PortHandler.requestDevicePermission = function (deviceType) {
const requestPromise =
deviceType === "usb"
? WEBUSBDFU.requestPermission()
: serial.requestPermissionDevice(this.showAllSerialDevices, deviceType);
// Use serial facade to request permission
serial
.requestPermissionDevice(showAllDevices, deviceType)
console.log(`${this.logHead} Requesting permission for ${deviceType} device...`);
requestPromise
.then((port) => {
if (port) {
console.log(`${this.logHead} Permission granted for ${deviceType} device:`, port);
this.selectActivePort(port);
} else {
console.log(`${this.logHead} Permission request cancelled or failed for ${deviceType}`);
console.log(`${this.logHead} Permission request cancelled or failed for ${deviceType} device`);
}
})
.catch((error) => {
console.error(`${this.logHead} Error requesting permission for ${deviceType}:`, error);
console.error(`${this.logHead} Error requesting permission for ${deviceType} device:`, error);
});
};