mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-27 14:06:38 +10:00
Add web serial support and USB tests
This commit is contained in:
committed by
just-stuff-tm
parent
22a53439b1
commit
c23a1da430
@@ -157,30 +157,55 @@ class _ConnectionMethodButton extends StatelessWidget {
|
||||
? constraints.maxWidth
|
||||
: 320.0;
|
||||
final isCompact = availableHeight < 72.0 || availableWidth < 180.0;
|
||||
final baseGap = isCompact ? 8.0 : 12.0;
|
||||
final content = Flex(
|
||||
direction: isCompact ? Axis.horizontal : Axis.vertical,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(icon, size: isCompact ? 24.0 : 60.0, color: iconColor),
|
||||
SizedBox(
|
||||
width: isCompact ? baseGap : 0,
|
||||
height: isCompact ? 0 : baseGap,
|
||||
),
|
||||
Text(
|
||||
label,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.visible,
|
||||
style:
|
||||
(isCompact
|
||||
final useTightVertical = !isCompact && availableHeight < 120.0;
|
||||
final baseGap = isCompact
|
||||
? 8.0
|
||||
: (useTightVertical
|
||||
? math.max(4.0, math.min(8.0, availableHeight * 0.06))
|
||||
: 12.0);
|
||||
final labelStyle =
|
||||
(isCompact
|
||||
? theme.textTheme.titleMedium
|
||||
: (useTightVertical
|
||||
? theme.textTheme.titleMedium
|
||||
: theme.textTheme.titleLarge)
|
||||
?.copyWith(fontWeight: FontWeight.w600),
|
||||
),
|
||||
],
|
||||
);
|
||||
: theme.textTheme.titleLarge))
|
||||
?.copyWith(fontWeight: FontWeight.w600);
|
||||
final verticalIconSize = useTightVertical
|
||||
? math.max(32.0, math.min(48.0, availableHeight * 0.42))
|
||||
: 60.0;
|
||||
final content = isCompact
|
||||
? Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(icon, size: 24.0, color: iconColor),
|
||||
SizedBox(width: baseGap),
|
||||
Flexible(
|
||||
child: Text(
|
||||
label,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: labelStyle,
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(icon, size: verticalIconSize, color: iconColor),
|
||||
SizedBox(height: baseGap),
|
||||
Text(
|
||||
label,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.visible,
|
||||
style: labelStyle,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
return Center(
|
||||
child: FittedBox(
|
||||
|
||||
+14
-23
@@ -6,6 +6,7 @@ import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../utils/usb_port_labels.dart';
|
||||
import 'contacts_screen.dart';
|
||||
|
||||
class UsbScreen extends StatefulWidget {
|
||||
@@ -31,6 +32,14 @@ class _UsbScreenState extends State<UsbScreen> {
|
||||
_connector = context.read<MeshCoreConnector>();
|
||||
_connectionListener = () {
|
||||
if (!mounted) return;
|
||||
final activeUsbPort = _connector.activeUsbPort;
|
||||
if (activeUsbPort != null &&
|
||||
activeUsbPort.isNotEmpty &&
|
||||
activeUsbPort != _selectedPort) {
|
||||
setState(() {
|
||||
_selectedPort = activeUsbPort;
|
||||
});
|
||||
}
|
||||
if (_connector.state == MeshCoreConnectionState.disconnected) {
|
||||
_navigatedToContacts = false;
|
||||
if (_isConnecting) {
|
||||
@@ -192,7 +201,7 @@ class _UsbScreenState extends State<UsbScreen> {
|
||||
FilledButton.icon(
|
||||
onPressed: _canConnect
|
||||
? () {
|
||||
final rawPortName = _normalizedPortName(
|
||||
final rawPortName = normalizeUsbPortName(
|
||||
_selectedPort!,
|
||||
);
|
||||
debugPrint(
|
||||
@@ -236,7 +245,7 @@ class _UsbScreenState extends State<UsbScreen> {
|
||||
child: FilledButton.icon(
|
||||
onPressed: _canConnect
|
||||
? () {
|
||||
final rawPortName = _normalizedPortName(
|
||||
final rawPortName = normalizeUsbPortName(
|
||||
_selectedPort!,
|
||||
);
|
||||
debugPrint(
|
||||
@@ -322,7 +331,7 @@ class _UsbScreenState extends State<UsbScreen> {
|
||||
final port = _ports[index];
|
||||
final isSelected = port == _selectedPort;
|
||||
final displayName = _friendlyPortName(port);
|
||||
final rawName = _normalizedPortName(port);
|
||||
final rawName = normalizeUsbPortName(port);
|
||||
final showRawName = rawName != displayName;
|
||||
return Material(
|
||||
color: isSelected
|
||||
@@ -416,7 +425,7 @@ class _UsbScreenState extends State<UsbScreen> {
|
||||
if (selectedPort == null || selectedPort.isEmpty) {
|
||||
return;
|
||||
}
|
||||
final rawPortName = _normalizedPortName(selectedPort);
|
||||
final rawPortName = normalizeUsbPortName(selectedPort);
|
||||
|
||||
setState(() {
|
||||
_isConnecting = true;
|
||||
@@ -434,23 +443,5 @@ class _UsbScreenState extends State<UsbScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
String _normalizedPortName(String portLabel) {
|
||||
final separatorIndex = portLabel.indexOf(' - ');
|
||||
final normalized = separatorIndex >= 0
|
||||
? portLabel.substring(0, separatorIndex)
|
||||
: portLabel;
|
||||
return normalized.trim();
|
||||
}
|
||||
|
||||
String _friendlyPortName(String portLabel) {
|
||||
final separatorIndex = portLabel.indexOf(' - ');
|
||||
if (separatorIndex < 0) {
|
||||
return portLabel.trim();
|
||||
}
|
||||
final friendlyName = portLabel.substring(separatorIndex + 3).trim();
|
||||
if (friendlyName.isEmpty) {
|
||||
return _normalizedPortName(portLabel);
|
||||
}
|
||||
return friendlyName;
|
||||
}
|
||||
String _friendlyPortName(String portLabel) => friendlyUsbPortName(portLabel);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user