Files
pipelines/app/lib/features/onboarding/discovery/discovered_server_row.dart
T
alan 079924d19a Recover from zero servers, sign each machine in on its own, offer every route
- Removing the primary machine hands pipelines/runs to the next saved machine
  on native hosts; removing the last machine returns to the connect screen
  instead of stranding the app on "Server endpoint not configured".
- Add server probes the new machine and asks for its own password in the same
  page; Settings rows show Connected / Sign in required / Unreachable with the
  reason and offer Sign in; no other machine's credential is ever reused.
- Unreachable addresses explain why: a TLS failure against an IP points at the
  Tailscale name, a non-Pipelines answer points at the port.
- Discovered machines list every advertised route (LAN, Tailscale IP, Tailscale
  name) as a checklist; chosen routes are saved as one machine.
- tool/connection_probe.dart replays the native login and websocket against
  real addresses for diagnosis.
2026-11-08 23:59:20 +00:00

163 lines
5.0 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import 'discovered_server.dart';
/// One discovered machine. A machine with one route is used by tapping it. A
/// machine with several routes (LAN, Tailscale IP, Tailscale name) expands to
/// a checklist so the operator chooses which of them to save; the first
/// checked route is dialled first and the rest are backups to the same machine.
class DiscoveredServerRow extends StatefulWidget {
const DiscoveredServerRow({
super.key,
required this.server,
required this.onSelect,
this.enabled = true,
});
final DiscoveredServer server;
final ValueChanged<DiscoveredServer> onSelect;
final bool enabled;
@override
State<DiscoveredServerRow> createState() => _DiscoveredServerRowState();
}
class _DiscoveredServerRowState extends State<DiscoveredServerRow> {
bool _expanded = false;
late final Set<DiscoveredAddress> _chosen = {widget.server.addresses.first};
bool get _multiple => widget.server.addresses.length > 1;
void _tap() {
if (!_multiple) {
widget.onSelect(widget.server);
return;
}
setState(() => _expanded = !_expanded);
}
void _use() {
final ordered = [
for (final address in widget.server.addresses)
if (_chosen.contains(address)) address,
];
widget.onSelect(widget.server.choosing(ordered));
}
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final server = widget.server;
final detail = _multiple
? '${server.addresses.length} addresses'
: server.address;
final subtitle = Text(
server.passwordRequired ? '$detail · password' : detail,
);
final onTap = widget.enabled ? _tap : null;
final Widget head = cupertino
? CupertinoListTile(
key: Key('discovered-${server.address}'),
leading: const Icon(CupertinoIcons.desktopcomputer),
title: Text(server.name),
subtitle: subtitle,
trailing: _multiple
? Icon(
_expanded
? CupertinoIcons.chevron_up
: CupertinoIcons.chevron_down,
)
: const CupertinoListTileChevron(),
onTap: onTap,
)
: ListTile(
key: Key('discovered-${server.address}'),
leading: const Icon(Icons.dns_outlined),
title: Text(server.name),
subtitle: subtitle,
trailing: Icon(
_multiple
? (_expanded ? Icons.expand_less : Icons.expand_more)
: Icons.chevron_right,
),
enabled: widget.enabled,
onTap: onTap,
);
if (!_multiple || !_expanded) return head;
final useLabel = 'Use ${server.name}';
final use = cupertino
? CupertinoButton.filled(
key: Key('discovered-use-${server.address}'),
onPressed: widget.enabled && _chosen.isNotEmpty ? _use : null,
child: Text(useLabel),
)
: FilledButton(
key: Key('discovered-use-${server.address}'),
onPressed: widget.enabled && _chosen.isNotEmpty ? _use : null,
child: Text(useLabel),
);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
head,
Padding(
padding: const EdgeInsetsDirectional.only(start: 16, end: 16),
child: Text(
'Choose how to reach ${server.name}. Checked addresses are saved '
'as routes to this one machine; the first is tried first.',
),
),
for (final address in server.addresses)
_choice(context, cupertino, address),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Align(
alignment: AlignmentDirectional.centerStart,
child: use,
),
),
],
);
}
Widget _choice(
BuildContext context,
bool cupertino,
DiscoveredAddress address,
) {
final checked = _chosen.contains(address);
void toggle(bool? value) => setState(() {
if (value ?? false) {
_chosen.add(address);
} else {
_chosen.remove(address);
}
});
final key = Key('discovered-route-${address.endpoint}');
final title = Text(address.label);
final subtitle = Text(address.endpoint.toString());
if (cupertino) {
return CupertinoListTile(
key: key,
title: title,
subtitle: subtitle,
trailing: CupertinoCheckbox(
value: checked,
onChanged: widget.enabled ? toggle : null,
),
onTap: widget.enabled ? () => toggle(!checked) : null,
);
}
return CheckboxListTile(
key: key,
value: checked,
onChanged: widget.enabled ? toggle : null,
title: title,
subtitle: subtitle,
controlAffinity: ListTileControlAffinity.leading,
);
}
}