Files
pipelines/app/lib/features/settings/saved_servers_section.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

162 lines
5.3 KiB
Dart

import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import '../../core/servers/chat/machine_sign_in_dialog.dart';
import '../../core/servers/server_catalog.dart';
import '../../ui/adaptive/host.dart';
import 'saved_server_editor.dart';
import 'saved_server_row.dart';
import 'server_connections.dart';
import 'settings_group.dart';
import 'settings_row.dart';
import 'settings_theme.dart';
class _ServerSaveFailure implements Exception {
const _ServerSaveFailure(this.message);
final String message;
@override
String toString() => message;
}
class SavedServersSection extends StatelessWidget {
const SavedServersSection({
super.key,
required this.connections,
this.allowPrimarySelection,
});
final bool? allowPrimarySelection;
final ServerConnections connections;
Future<void> _edit(BuildContext context, [SavedServer? server]) async {
await editSavedServer(
context,
server: server,
authenticator: connections.authenticator,
onSave: (edited) async {
if (!await connections.save(edited)) {
throw _ServerSaveFailure(
connections.error ?? 'The server configuration could not be saved.',
);
}
},
);
}
Future<void> _remove(BuildContext context, SavedServer server) async {
final cupertino = usesCupertinoHost(context);
final confirmed = cupertino
? await showCupertinoDialog<bool>(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text('Remove ${server.name}?'),
content: const Text(
'This removes the saved configuration, not data on the server.',
),
actions: [
CupertinoDialogAction(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
CupertinoDialogAction(
isDestructiveAction: true,
onPressed: () => Navigator.pop(context, true),
child: const Text('Remove'),
),
],
),
)
: await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text('Remove ${server.name}?'),
content: const Text(
'This removes the saved configuration, not data on the server.',
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('Remove'),
),
],
),
);
if (confirmed == true) await connections.remove(server.id);
}
void _act(BuildContext context, SavedServer server, SavedServerAction act) {
switch (act) {
case SavedServerAction.use:
unawaited(connections.select(server.id));
case SavedServerAction.edit:
unawaited(_edit(context, server));
case SavedServerAction.remove:
unawaited(_remove(context, server));
case SavedServerAction.signIn:
final authenticator = connections.authenticator;
if (authenticator == null) return;
unawaited(
showMachineSignIn(
context,
name: server.name,
signIn: (password) => authenticator.authenticate(server, password),
),
);
}
}
@override
Widget build(BuildContext context) => ListenableBuilder(
listenable: Listenable.merge([connections, ?connections.authenticator]),
builder: (context, _) {
final cupertino = usesCupertinoHost(context);
final error = connections.error;
final allowSelection = allowPrimarySelection ?? !kIsWeb;
return SettingsGroup(
title: 'Servers',
leadingRows: true,
footer: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Each entry is a separate machine with its own password; all of '
'them connect for chat. Addresses inside one entry are routes '
'to that same machine.',
),
if (allowSelection)
const Text('The primary machine is used for pipelines and runs.'),
if (error != null)
Text(error, style: TextStyle(color: settingsErrorColor(context))),
],
),
children: [
for (final server in connections.catalog.servers)
SavedServerRow(
server: server,
status: connections.authenticator?.status(server.id),
selected: server.id == connections.catalog.active?.id,
allowSelection: allowSelection,
primaryContext: true,
busy: connections.busy,
onAction: (act) => _act(context, server, act),
),
SettingsRow(
action: true,
enabled: !connections.busy,
leading: Icon(cupertino ? CupertinoIcons.add : Icons.add),
title: const Text('Add server'),
onTap: () => unawaited(_edit(context)),
),
],
);
},
);
}