079924d19a
- 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.
165 lines
5.7 KiB
Dart
165 lines
5.7 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../core/servers/machine_access.dart';
|
|
import '../../core/servers/server_catalog.dart';
|
|
import 'settings_row.dart';
|
|
import 'settings_theme.dart';
|
|
|
|
/// What a saved server's menu can do.
|
|
enum SavedServerAction { use, edit, remove, signIn }
|
|
|
|
/// The key of a saved server's actions menu button.
|
|
ValueKey<String> savedServerMenuKey(String id) =>
|
|
ValueKey<String>('settings.server.$id.menu');
|
|
|
|
/// One saved machine: a selection mark, the name, its live state (connected,
|
|
/// sign-in required, unreachable), "Pipelines and runs server" on the primary
|
|
/// and each address as a subtitle line. The trailing menu offers Sign in when
|
|
/// the machine wants its own password, plus Use, Edit and Remove.
|
|
class SavedServerRow extends StatelessWidget {
|
|
const SavedServerRow({
|
|
super.key,
|
|
required this.server,
|
|
required this.selected,
|
|
required this.busy,
|
|
required this.onAction,
|
|
this.status,
|
|
this.allowSelection = true,
|
|
this.primaryContext = false,
|
|
});
|
|
|
|
final bool allowSelection, primaryContext;
|
|
final SavedServer server;
|
|
final bool selected;
|
|
final bool busy;
|
|
final MachineAccessResult? status;
|
|
final ValueChanged<SavedServerAction> onAction;
|
|
|
|
String _label(SavedServerAction action) => switch (action) {
|
|
SavedServerAction.use =>
|
|
primaryContext
|
|
? 'Use ${server.name} for pipelines and runs'
|
|
: 'Use ${server.name}',
|
|
SavedServerAction.edit => 'Edit ${server.name}',
|
|
SavedServerAction.remove => 'Remove ${server.name}',
|
|
SavedServerAction.signIn => 'Sign in to ${server.name}',
|
|
};
|
|
|
|
List<SavedServerAction> get _actions => <SavedServerAction>[
|
|
if (status?.needsPassword ?? false) SavedServerAction.signIn,
|
|
if (allowSelection && !selected) SavedServerAction.use,
|
|
SavedServerAction.edit,
|
|
SavedServerAction.remove,
|
|
];
|
|
|
|
/// The state line: a tap on it signs in when that is what is missing.
|
|
String? get _stateText => switch (status?.access) {
|
|
null => null,
|
|
MachineAccess.connected => 'Connected',
|
|
MachineAccess.needsPassword => 'Sign in required',
|
|
MachineAccess.unreachable =>
|
|
status?.detail == null || status!.detail!.isEmpty
|
|
? 'Unreachable'
|
|
: 'Unreachable: ${status!.detail}',
|
|
};
|
|
|
|
Future<void> _cupertinoMenu(BuildContext context) async {
|
|
final action = await showCupertinoModalPopup<SavedServerAction>(
|
|
context: context,
|
|
builder: (context) => CupertinoActionSheet(
|
|
title: Text(server.name),
|
|
actions: <Widget>[
|
|
for (final action in _actions)
|
|
CupertinoActionSheetAction(
|
|
isDestructiveAction: action == SavedServerAction.remove,
|
|
onPressed: () => Navigator.pop(context, action),
|
|
child: Text(_label(action)),
|
|
),
|
|
],
|
|
cancelButton: CupertinoActionSheetAction(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('Cancel'),
|
|
),
|
|
),
|
|
);
|
|
if (action != null) onAction(action);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cupertino = usesCupertinoControls(context);
|
|
final Widget menu = cupertino
|
|
? CupertinoButton(
|
|
key: savedServerMenuKey(server.id),
|
|
padding: EdgeInsets.zero,
|
|
onPressed: busy ? null : () => _cupertinoMenu(context),
|
|
child: Icon(
|
|
CupertinoIcons.ellipsis_circle,
|
|
semanticLabel: '${server.name} actions',
|
|
),
|
|
)
|
|
: PopupMenuButton<SavedServerAction>(
|
|
key: savedServerMenuKey(server.id),
|
|
enabled: !busy,
|
|
tooltip: '${server.name} actions',
|
|
onSelected: onAction,
|
|
itemBuilder: (context) => <PopupMenuEntry<SavedServerAction>>[
|
|
for (final action in _actions)
|
|
PopupMenuItem(value: action, child: Text(_label(action))),
|
|
],
|
|
);
|
|
final Widget mark = !allowSelection
|
|
? Icon(cupertino ? CupertinoIcons.desktopcomputer : Icons.computer)
|
|
: selected
|
|
? Icon(
|
|
cupertino
|
|
? CupertinoIcons.checkmark_circle_fill
|
|
: Icons.check_circle,
|
|
semanticLabel: 'Selected',
|
|
color: cupertino
|
|
? CupertinoTheme.of(context).primaryColor
|
|
: Theme.of(context).colorScheme.primary,
|
|
)
|
|
: Icon(
|
|
cupertino ? CupertinoIcons.circle : Icons.radio_button_unchecked,
|
|
color: cupertino
|
|
? CupertinoColors.tertiaryLabel.resolveFrom(context)
|
|
: null,
|
|
);
|
|
final needsPassword = status?.needsPassword ?? false;
|
|
final state = _stateText;
|
|
return SettingsRow(
|
|
leading: mark,
|
|
title: Text(server.name),
|
|
subtitle: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
if (state != null)
|
|
Text(
|
|
state,
|
|
key: Key('settings.server.${server.id}.state'),
|
|
style: status?.access == MachineAccess.unreachable
|
|
? TextStyle(color: settingsErrorColor(context))
|
|
: null,
|
|
),
|
|
if (selected)
|
|
Text(
|
|
primaryContext ? 'Pipelines and runs server' : 'Selected server',
|
|
),
|
|
for (final (index, address) in server.endpoints.indexed)
|
|
Text('${index == 0 ? 'Address' : 'Backup address'}: $address'),
|
|
],
|
|
),
|
|
trailing: menu,
|
|
onTap: busy
|
|
? null
|
|
: needsPassword
|
|
? () => onAction(SavedServerAction.signIn)
|
|
: !allowSelection || selected
|
|
? null
|
|
: () => onAction(SavedServerAction.use),
|
|
);
|
|
}
|
|
}
|