Files
pipelines/app/lib/features/onboarding/discovery/discovery_panel.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

186 lines
4.8 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import 'browser_server_discovery.dart';
import 'discovered_server.dart';
import 'discovered_server_row.dart';
import 'server_discovery.dart';
enum _Phase { idle, scanning, done, failed }
/// "Find servers on this network": browses for a while, lists what answered
/// and hands a tapped server to [onSelect]. Manual entry stays beside it.
class DiscoveryPanel extends StatefulWidget {
const DiscoveryPanel({
super.key,
required this.discovery,
required this.onSelect,
this.enabled = true,
this.scanFor = const Duration(seconds: 8),
});
final ServerDiscovery discovery;
final ValueChanged<DiscoveredServer> onSelect;
final bool enabled;
/// How long one scan browses before it settles on its results.
final Duration scanFor;
@override
State<DiscoveryPanel> createState() => _DiscoveryPanelState();
}
class _DiscoveryPanelState extends State<DiscoveryPanel> {
_Phase _phase = _Phase.idle;
List<DiscoveredServer> _servers = const [];
String? _error;
StreamSubscription<List<DiscoveredServer>>? _scan;
Timer? _timer;
@override
void dispose() {
_stop();
super.dispose();
}
void _stop() {
_timer?.cancel();
_timer = null;
unawaited(_scan?.cancel());
_scan = null;
}
void _start() {
_stop();
setState(() {
_phase = _Phase.scanning;
_servers = const [];
_error = null;
});
_scan = widget.discovery.scan().listen(
(servers) {
if (mounted) setState(() => _servers = servers);
},
onDone: () {
_timer?.cancel();
if (mounted && _phase == _Phase.scanning) {
setState(() => _phase = _Phase.done);
}
},
onError: (Object error) {
_stop();
if (mounted) {
setState(() {
_phase = _Phase.failed;
_error = '$error';
});
}
},
);
_timer = Timer(widget.scanFor, () {
_stop();
if (mounted) setState(() => _phase = _Phase.done);
});
}
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final scanning = _phase == _Phase.scanning;
final label = _phase == _Phase.idle
? 'Find servers on this network'
: 'Search again';
final enabled = widget.enabled && !scanning;
final button = cupertino
? CupertinoButton(
key: const Key('discovery-scan'),
onPressed: enabled ? _start : null,
child: Text(label),
)
: OutlinedButton.icon(
key: const Key('discovery-scan'),
onPressed: enabled ? _start : null,
icon: const Icon(Icons.wifi_find),
label: Text(label),
);
final status = switch (_phase) {
_Phase.scanning => _status(
context,
cupertino,
const Key('discovery-scanning'),
'Looking for Pipelines servers…',
busy: true,
),
_Phase.done when _servers.isEmpty => _status(
context,
cupertino,
const Key('discovery-empty'),
'No Pipelines servers answered on this network. '
'Enter the address instead.',
),
_Phase.failed => _status(
context,
cupertino,
const Key('discovery-error'),
'Could not search this network: $_error',
error: true,
),
_ => null,
};
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
button,
if (widget.discovery is BrowserServerDiscovery)
const Text('Searches this server’s local network.'),
?status,
for (final server in _servers)
DiscoveredServerRow(
key: ValueKey('discovered-row-${server.address}'),
server: server,
enabled: widget.enabled,
onSelect: widget.onSelect,
),
],
);
}
Widget _status(
BuildContext context,
bool cupertino,
Key key,
String text, {
bool busy = false,
bool error = false,
}) {
final color = !error
? null
: cupertino
? CupertinoColors.systemRed.resolveFrom(context)
: Theme.of(context).colorScheme.error;
return Padding(
key: key,
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
children: [
if (busy) ...[
cupertino
? const CupertinoActivityIndicator()
: const SizedBox.square(
dimension: 16,
child: CircularProgressIndicator(strokeWidth: 2),
),
const SizedBox(width: 12),
],
Expanded(
child: Text(text, style: TextStyle(color: color)),
),
],
),
);
}
}