Keep browser chat server connections together in saved-server settings

This commit is contained in:
2026-11-08 22:01:09 +00:00
parent 349428f11d
commit 497cd66a1e
5 changed files with 92 additions and 10 deletions
@@ -23,21 +23,27 @@ class SavedServerRow extends StatelessWidget {
required this.selected,
required this.busy,
required this.onAction,
this.allowSelection = true,
this.primaryContext = false,
});
final bool allowSelection, primaryContext;
final SavedServer server;
final bool selected;
final bool busy;
final ValueChanged<SavedServerAction> onAction;
String _label(SavedServerAction action) => switch (action) {
SavedServerAction.use => 'Use ${server.name}',
SavedServerAction.use =>
primaryContext
? 'Use ${server.name} for pipelines and runs'
: 'Use ${server.name}',
SavedServerAction.edit => 'Edit ${server.name}',
SavedServerAction.remove => 'Remove ${server.name}',
};
List<SavedServerAction> get _actions => <SavedServerAction>[
if (!selected) SavedServerAction.use,
if (allowSelection && !selected) SavedServerAction.use,
SavedServerAction.edit,
SavedServerAction.remove,
];
@@ -87,7 +93,9 @@ class SavedServerRow extends StatelessWidget {
PopupMenuItem(value: action, child: Text(_label(action))),
],
);
final Widget mark = selected
final Widget mark = !allowSelection
? Icon(cupertino ? CupertinoIcons.desktopcomputer : Icons.computer)
: selected
? Icon(
cupertino
? CupertinoIcons.checkmark_circle_fill
@@ -109,13 +117,18 @@ class SavedServerRow extends StatelessWidget {
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
if (selected) const Text('Selected server'),
if (selected)
Text(
primaryContext ? 'Pipelines and runs server' : 'Selected server',
),
for (final (index, address) in server.endpoints.indexed)
Text('${index == 0 ? 'Preferred' : 'Backup $index'}: $address'),
],
),
trailing: menu,
onTap: selected || busy ? null : () => onAction(SavedServerAction.use),
onTap: !allowSelection || selected || busy
? null
: () => onAction(SavedServerAction.use),
);
}
}
@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import '../../core/servers/server_catalog.dart';
@@ -21,7 +22,12 @@ class _ServerSaveFailure implements Exception {
}
class SavedServersSection extends StatelessWidget {
const SavedServersSection({super.key, required this.connections});
const SavedServersSection({
super.key,
required this.connections,
this.allowPrimarySelection,
});
final bool? allowPrimarySelection;
final ServerConnections connections;
Future<void> _edit(BuildContext context, [SavedServer? server]) async {
@@ -100,17 +106,27 @@ class SavedServersSection extends StatelessWidget {
builder: (context, _) {
final cupertino = usesCupertinoHost(context);
final error = connections.error;
final allowSelection = allowPrimarySelection ?? !kIsWeb;
return SettingsGroup(
title: 'Servers',
leadingRows: true,
footer: error == null
? null
: Text(error, style: TextStyle(color: settingsErrorColor(context))),
footer: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('All saved machines connect for chat.'),
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,
selected: server.id == connections.catalog.active?.id,
allowSelection: allowSelection,
primaryContext: true,
busy: connections.busy,
onAction: (act) => _act(context, server, act),
),