Enhance USB functionality by adding request port label management and platform support checks

This commit is contained in:
just_stuff_tm
2026-03-02 05:28:31 -05:00
committed by just-stuff-tm
parent ca5784f3f8
commit 781090243c
7 changed files with 93 additions and 34 deletions
+10
View File
@@ -33,4 +33,14 @@ class PlatformInfo {
/// Whether the app is running on a desktop platform (macOS, Windows, or Linux).
static bool get isDesktop => isMacOS || isWindows || isLinux;
/// Whether the current platform supports a native USB serial backend.
static bool get supportsNativeUsbSerial => isAndroid || isWindows || isLinux;
/// Whether the current browser supports the Web Serial backend.
static bool get supportsWebSerial => isWeb && isChrome;
/// Whether USB serial is expected to be available on the current platform.
static bool get supportsUsbSerial =>
supportsNativeUsbSerial || supportsWebSerial;
}
+2 -3
View File
@@ -1,5 +1,3 @@
const String usbRequestPortLabel = 'Choose USB Device';
String normalizeUsbPortName(String portLabel) {
final separatorIndex = portLabel.indexOf(' - ');
final normalized = separatorIndex >= 0
@@ -23,10 +21,11 @@ String friendlyUsbPortName(String portLabel) {
String describeWebUsbPort({
required int? vendorId,
required int? productId,
String requestPortLabel = 'Choose USB Device',
Map<String, String> knownUsbNames = const <String, String>{},
}) {
if (vendorId == null && productId == null) {
return usbRequestPortLabel;
return requestPortLabel;
}
final vendorHex = vendorId?.toRadixString(16).padLeft(4, '0').toUpperCase();