mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-13 20:32:02 +10:00
Run dart format
This commit is contained in:
@@ -906,10 +906,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
try {
|
try {
|
||||||
await _usbFrameSubscription?.cancel();
|
await _usbFrameSubscription?.cancel();
|
||||||
_usbFrameSubscription = null;
|
_usbFrameSubscription = null;
|
||||||
_appDebugLogService?.info(
|
_appDebugLogService?.info('connectUsb: opening serial port…', tag: 'USB');
|
||||||
'connectUsb: opening serial port…',
|
|
||||||
tag: 'USB',
|
|
||||||
);
|
|
||||||
await _usbManager.connect(portName: portName, baudRate: baudRate);
|
await _usbManager.connect(portName: portName, baudRate: baudRate);
|
||||||
_appDebugLogService?.info(
|
_appDebugLogService?.info(
|
||||||
'connectUsb: serial port opened, label=${_usbManager.activePortDisplayLabel}',
|
'connectUsb: serial port opened, label=${_usbManager.activePortDisplayLabel}',
|
||||||
|
|||||||
@@ -24,8 +24,7 @@ class MeshCoreUsbManager {
|
|||||||
// --- Configuration ---
|
// --- Configuration ---
|
||||||
Future<List<String>> listPorts() => _service.listPorts();
|
Future<List<String>> listPorts() => _service.listPorts();
|
||||||
|
|
||||||
void setRequestPortLabel(String label) =>
|
void setRequestPortLabel(String label) => _service.setRequestPortLabel(label);
|
||||||
_service.setRequestPortLabel(label);
|
|
||||||
|
|
||||||
void setFallbackDeviceName(String label) =>
|
void setFallbackDeviceName(String label) =>
|
||||||
_service.setFallbackDeviceName(label);
|
_service.setFallbackDeviceName(label);
|
||||||
@@ -36,7 +35,10 @@ class MeshCoreUsbManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- Connection lifecycle ---
|
// --- Connection lifecycle ---
|
||||||
Future<void> connect({required String portName, int baudRate = 115200}) async {
|
Future<void> connect({
|
||||||
|
required String portName,
|
||||||
|
int baudRate = 115200,
|
||||||
|
}) async {
|
||||||
_debugLog?.info(
|
_debugLog?.info(
|
||||||
'UsbManager.connect: portName=$portName baud=$baudRate',
|
'UsbManager.connect: portName=$portName baud=$baudRate',
|
||||||
tag: 'USB',
|
tag: 'USB',
|
||||||
|
|||||||
@@ -107,7 +107,8 @@ class _UsbScreenState extends State<UsbScreen> {
|
|||||||
bottomNavigationBar: Consumer<MeshCoreConnector>(
|
bottomNavigationBar: Consumer<MeshCoreConnector>(
|
||||||
builder: (context, connector, child) {
|
builder: (context, connector, child) {
|
||||||
final isLoading = _isLoadingPorts;
|
final isLoading = _isLoadingPorts;
|
||||||
final showBle = PlatformInfo.isWeb ||
|
final showBle =
|
||||||
|
PlatformInfo.isWeb ||
|
||||||
PlatformInfo.isAndroid ||
|
PlatformInfo.isAndroid ||
|
||||||
PlatformInfo.isIOS;
|
PlatformInfo.isIOS;
|
||||||
|
|
||||||
@@ -238,7 +239,7 @@ class _UsbScreenState extends State<UsbScreen> {
|
|||||||
|
|
||||||
final isConnecting =
|
final isConnecting =
|
||||||
connector.state == MeshCoreConnectionState.connecting &&
|
connector.state == MeshCoreConnectionState.connecting &&
|
||||||
connector.activeTransport == MeshCoreTransportType.usb;
|
connector.activeTransport == MeshCoreTransportType.usb;
|
||||||
|
|
||||||
return ListView.separated(
|
return ListView.separated(
|
||||||
padding: const EdgeInsets.all(8),
|
padding: const EdgeInsets.all(8),
|
||||||
@@ -259,8 +260,7 @@ class _UsbScreenState extends State<UsbScreen> {
|
|||||||
),
|
),
|
||||||
subtitle: showRawName ? Text(rawName) : null,
|
subtitle: showRawName ? Text(rawName) : null,
|
||||||
trailing: ElevatedButton(
|
trailing: ElevatedButton(
|
||||||
onPressed:
|
onPressed: isConnecting ? null : () => _connectPort(port),
|
||||||
isConnecting ? null : () => _connectPort(port),
|
|
||||||
child: Text(l10n.common_connect),
|
child: Text(l10n.common_connect),
|
||||||
),
|
),
|
||||||
onTap: isConnecting ? null : () => _connectPort(port),
|
onTap: isConnecting ? null : () => _connectPort(port),
|
||||||
@@ -329,8 +329,10 @@ class _UsbScreenState extends State<UsbScreen> {
|
|||||||
if (_connector.state != MeshCoreConnectionState.disconnected) return;
|
if (_connector.state != MeshCoreConnectionState.disconnected) return;
|
||||||
|
|
||||||
final rawPortName = normalizeUsbPortName(port);
|
final rawPortName = normalizeUsbPortName(port);
|
||||||
appLogger.info('Connect tapped for $port (raw: $rawPortName)',
|
appLogger.info(
|
||||||
tag: 'UsbScreen');
|
'Connect tapped for $port (raw: $rawPortName)',
|
||||||
|
tag: 'UsbScreen',
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await _connector.connectUsb(portName: rawPortName);
|
await _connector.connectUsb(portName: rawPortName);
|
||||||
|
|||||||
@@ -101,8 +101,7 @@ class NotificationService {
|
|||||||
final addr = Platform.environment['DBUS_SESSION_BUS_ADDRESS'];
|
final addr = Platform.environment['DBUS_SESSION_BUS_ADDRESS'];
|
||||||
if (addr != null && addr.isNotEmpty) return true;
|
if (addr != null && addr.isNotEmpty) return true;
|
||||||
// Fallback: check the default socket for the current user.
|
// Fallback: check the default socket for the current user.
|
||||||
final uid = Platform.environment['UID'] ??
|
final uid = Platform.environment['UID'] ?? Platform.environment['EUID'];
|
||||||
Platform.environment['EUID'];
|
|
||||||
final path = '/run/user/${uid ?? '1000'}/bus';
|
final path = '/run/user/${uid ?? '1000'}/bus';
|
||||||
return File(path).existsSync();
|
return File(path).existsSync();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,10 +118,7 @@ class UsbSerialService {
|
|||||||
tag: 'USB Serial',
|
tag: 'USB Serial',
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
_debugLogService?.error(
|
_debugLogService?.error('Web connect failed: $error', tag: 'USB Serial');
|
||||||
'Web connect failed: $error',
|
|
||||||
tag: 'USB Serial',
|
|
||||||
);
|
|
||||||
await _cleanupFailedConnect();
|
await _cleanupFailedConnect();
|
||||||
_status = UsbSerialStatus.disconnected;
|
_status = UsbSerialStatus.disconnected;
|
||||||
_connectedPortName = null;
|
_connectedPortName = null;
|
||||||
@@ -374,10 +371,7 @@ class UsbSerialService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
_debugLogService?.error(
|
_debugLogService?.error('_pumpReads error: $error', tag: 'USB Serial');
|
||||||
'_pumpReads error: $error',
|
|
||||||
tag: 'USB Serial',
|
|
||||||
);
|
|
||||||
if (_status == UsbSerialStatus.connected) {
|
if (_status == UsbSerialStatus.connected) {
|
||||||
_addFrameError(error, stackTrace);
|
_addFrameError(error, stackTrace);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,10 +116,12 @@ void main() {
|
|||||||
);
|
);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
await tester.tap(find.ancestor(
|
await tester.tap(
|
||||||
of: find.text('Connect'),
|
find.ancestor(
|
||||||
matching: find.bySubtype<ElevatedButton>(),
|
of: find.text('Connect'),
|
||||||
));
|
matching: find.bySubtype<ElevatedButton>(),
|
||||||
|
),
|
||||||
|
);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
|
|
||||||
expect(connector.connectUsbCalls, 0);
|
expect(connector.connectUsbCalls, 0);
|
||||||
@@ -131,28 +133,29 @@ void main() {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
testWidgets(
|
testWidgets('UsbScreen sends raw port name when tapping Connect', (
|
||||||
'UsbScreen sends raw port name when tapping Connect',
|
tester,
|
||||||
(tester) async {
|
) async {
|
||||||
final connector = _FakeMeshCoreConnector(
|
final connector = _FakeMeshCoreConnector(
|
||||||
ports: <String>['COM6 - USB Serial Device (COM6)'],
|
ports: <String>['COM6 - USB Serial Device (COM6)'],
|
||||||
);
|
);
|
||||||
|
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
_buildTestApp(connector: connector, child: const UsbScreen()),
|
_buildTestApp(connector: connector, child: const UsbScreen()),
|
||||||
);
|
);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
await tester.tap(find.ancestor(
|
await tester.tap(
|
||||||
of: find.text('Connect'),
|
find.ancestor(
|
||||||
matching: find.bySubtype<ElevatedButton>(),
|
of: find.text('Connect'),
|
||||||
));
|
matching: find.bySubtype<ElevatedButton>(),
|
||||||
await tester.pump();
|
),
|
||||||
|
);
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
expect(connector.connectUsbCalls, 1);
|
expect(connector.connectUsbCalls, 1);
|
||||||
expect(connector.lastConnectPortName, 'COM6');
|
expect(connector.lastConnectPortName, 'COM6');
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
testWidgets('ScannerScreen USB action reflects platform support', (
|
testWidgets('ScannerScreen USB action reflects platform support', (
|
||||||
tester,
|
tester,
|
||||||
@@ -177,8 +180,9 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
group('Error Handling', () {
|
group('Error Handling', () {
|
||||||
testWidgets('shows error SnackBar when listing ports fails',
|
testWidgets('shows error SnackBar when listing ports fails', (
|
||||||
(tester) async {
|
tester,
|
||||||
|
) async {
|
||||||
final connector = _FakeMeshCoreConnector();
|
final connector = _FakeMeshCoreConnector();
|
||||||
connector.listUsbPortsImpl = () async {
|
connector.listUsbPortsImpl = () async {
|
||||||
throw PlatformException(
|
throw PlatformException(
|
||||||
@@ -195,9 +199,7 @@ void main() {
|
|||||||
expect(find.text('USB permission was denied.'), findsOneWidget);
|
expect(find.text('USB permission was denied.'), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('connection failure shows SnackBar error', (
|
testWidgets('connection failure shows SnackBar error', (tester) async {
|
||||||
tester,
|
|
||||||
) async {
|
|
||||||
final connector = _FakeMeshCoreConnector(ports: <String>['COM1']);
|
final connector = _FakeMeshCoreConnector(ports: <String>['COM1']);
|
||||||
var connectAttempted = false;
|
var connectAttempted = false;
|
||||||
connector.connectUsbImpl = ({required String portName}) async {
|
connector.connectUsbImpl = ({required String portName}) async {
|
||||||
@@ -210,10 +212,12 @@ void main() {
|
|||||||
);
|
);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
await tester.tap(find.ancestor(
|
await tester.tap(
|
||||||
of: find.text('Connect'),
|
find.ancestor(
|
||||||
matching: find.bySubtype<ElevatedButton>(),
|
of: find.text('Connect'),
|
||||||
));
|
matching: find.bySubtype<ElevatedButton>(),
|
||||||
|
),
|
||||||
|
);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(connectAttempted, isTrue);
|
expect(connectAttempted, isTrue);
|
||||||
|
|||||||
Reference in New Issue
Block a user