mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-25 17:25:16 +03:00
Fix dfu permissions (#4438)
* Request permission before connecting DFU device * Fix DFU permissions * Little refactor
This commit is contained in:
parent
3022548342
commit
ddfc76217d
3 changed files with 21 additions and 9 deletions
|
@ -90,6 +90,10 @@
|
||||||
"message": "--- I can't find my Bluetooth device---",
|
"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."
|
"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": {
|
"bluetoothConnected": {
|
||||||
"message": "Connected to Bluetooth device: $1"
|
"message": "Connected to Bluetooth device: $1"
|
||||||
},
|
},
|
||||||
|
|
|
@ -45,6 +45,9 @@
|
||||||
<option value="requestpermissionbluetooth">
|
<option value="requestpermissionbluetooth">
|
||||||
{{ $t("portsSelectPermissionBluetooth") }}
|
{{ $t("portsSelectPermissionBluetooth") }}
|
||||||
</option>
|
</option>
|
||||||
|
<option value="requestpermissionusb">
|
||||||
|
{{ $t("portsSelectPermissionDFU") }}
|
||||||
|
</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div id="auto-connect-and-baud">
|
<div id="auto-connect-and-baud">
|
||||||
|
@ -159,6 +162,8 @@ export default defineComponent({
|
||||||
EventBus.$emit("ports-input:request-permission");
|
EventBus.$emit("ports-input:request-permission");
|
||||||
} else if (value === "requestpermissionbluetooth") {
|
} else if (value === "requestpermissionbluetooth") {
|
||||||
EventBus.$emit("ports-input:request-permission-bluetooth");
|
EventBus.$emit("ports-input:request-permission-bluetooth");
|
||||||
|
} else if (value === "requestpermissionusb") {
|
||||||
|
EventBus.$emit("ports-input:request-permission-usb");
|
||||||
} else {
|
} else {
|
||||||
EventBus.$emit("ports-input:change", value);
|
EventBus.$emit("ports-input:change", value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ const PortHandler = new (function () {
|
||||||
PortHandler.initialize = function () {
|
PortHandler.initialize = function () {
|
||||||
EventBus.$on("ports-input:request-permission-bluetooth", () => this.requestDevicePermission("bluetooth"));
|
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", () => this.requestDevicePermission("serial"));
|
||||||
|
EventBus.$on("ports-input:request-permission-usb", () => this.requestDevicePermission("usb"));
|
||||||
EventBus.$on("ports-input:change", this.onChangeSelectedPort.bind(this));
|
EventBus.$on("ports-input:change", this.onChangeSelectedPort.bind(this));
|
||||||
|
|
||||||
// Use serial for all protocol events
|
// Use serial for all protocol events
|
||||||
|
@ -134,25 +135,27 @@ PortHandler.onChangeSelectedPort = function (port) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request permission for a device of the specified type
|
* 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") {
|
PortHandler.requestDevicePermission = function (deviceType) {
|
||||||
// Determine whether to show all devices based on device type
|
const requestPromise =
|
||||||
const showAllDevices = deviceType === "serial" ? this.showAllSerialDevices : false;
|
deviceType === "usb"
|
||||||
|
? WEBUSBDFU.requestPermission()
|
||||||
|
: serial.requestPermissionDevice(this.showAllSerialDevices, deviceType);
|
||||||
|
|
||||||
// Use serial facade to request permission
|
console.log(`${this.logHead} Requesting permission for ${deviceType} device...`);
|
||||||
serial
|
|
||||||
.requestPermissionDevice(showAllDevices, deviceType)
|
requestPromise
|
||||||
.then((port) => {
|
.then((port) => {
|
||||||
if (port) {
|
if (port) {
|
||||||
console.log(`${this.logHead} Permission granted for ${deviceType} device:`, port);
|
console.log(`${this.logHead} Permission granted for ${deviceType} device:`, port);
|
||||||
this.selectActivePort(port);
|
this.selectActivePort(port);
|
||||||
} else {
|
} 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) => {
|
.catch((error) => {
|
||||||
console.error(`${this.logHead} Error requesting permission for ${deviceType}:`, error);
|
console.error(`${this.logHead} Error requesting permission for ${deviceType} device:`, error);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue