Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/webusb_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,18 +779,18 @@ impl UsbDevice {
self.device_guard().is_some()
}

#[napi(getter, ts_return_type = "USBConfiguration")]
#[napi(getter, ts_return_type = "USBConfiguration | null")]
pub fn configuration(&self) -> Result<Option<UsbConfiguration>> {
let device = match self.device_guard().as_ref() {
Some(device) => device.clone(),
None => self._open()?,
};

let config = device
.active_configuration()
.map_err(|e| napi::Error::from_reason(format!("configuration error: {e}")))?;

Ok(Some(UsbConfiguration::new(&self, &device, config)?))
// Null when the device is unconfigured, as per WebUSB spec
match device.active_configuration() {
Ok(config) => Ok(Some(UsbConfiguration::new(&self, &device, config)?)),
Err(_) => Ok(None),
}
}

#[napi(getter, ts_return_type = "Array<USBConfiguration>")]
Expand Down
Loading