Servers: name a machine after its hostname once it connects

A saved server still named by the app ('My server', 'This server',
'Original legacy server' or its address host/IP) takes the hostname the
machine reports in get_status the first time the app connects; typed
names are kept. New servers (legacy migration, Settings with a blank
name, onboarding) start with the address host. A browser on its page
origin with no saved profile shows the reported hostname too. No server
change: get_status already reports the hostname.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 15:58:28 +00:00
parent 3e817a189b
commit c264f865ff
16 changed files with 654 additions and 24 deletions
+3 -3
View File
@@ -21,7 +21,7 @@ class AppTerminals {
required bool Function() connected,
required ApiGateway gateway,
required String machineId,
required String machineName,
required String Function() machineName,
required this.layout,
WindowManager? windows,
}) : machines = pool != null
@@ -29,9 +29,9 @@ class AppTerminals {
: SingleTerminalMachines(
connection: connection,
connected: connected,
machine: TerminalMachine(
machine: () => TerminalMachine(
id: machineId,
name: machineName,
name: machineName(),
gateway: gateway,
),
) {
+36 -5
View File
@@ -58,6 +58,7 @@ import '../features/terminal/terminal_layout.dart';
import 'app_route.dart';
import 'app_router.dart';
import 'app_session.dart';
import '../core/servers/server_naming.dart';
import 'chat_destination.dart';
import 'pipelines_destination.dart';
import 'runs_destination.dart';
@@ -357,16 +358,15 @@ class _PipelinesAppState extends State<PipelinesApp>
_session.addListener(_chatSyncChanged);
widget.chatPool?.addListener(_chatSyncChanged);
_chatSyncChanged();
_session.addListener(_learnServerHostname);
_learnServerHostname();
_terminals = AppTerminals(
pool: widget.chatPool,
connection: _session,
connection: Listenable.merge([_session, ?widget.servers]),
connected: () => _session.connected,
gateway: _session.gateway,
machineId: widget.serverId ?? 'server',
machineName:
widget.servers?.catalog.active?.name ??
widget.server.uri?.host ??
'This server',
machineName: _serverName,
layout: widget.terminalLayout ?? TerminalLayout.instance,
windows: _windows,
);
@@ -605,6 +605,7 @@ class _PipelinesAppState extends State<PipelinesApp>
}
_terminals.dispose();
_session.removeListener(_chatSyncChanged);
_session.removeListener(_learnServerHostname);
widget.chatPool?.removeListener(_chatSyncChanged);
_chatWindows.dispose();
_diffWindows.dispose();
@@ -935,6 +936,36 @@ class _PipelinesAppState extends State<PipelinesApp>
}
/// A replaced socket makes open chats re-subscribe, also in windows.
/// This server's name: its saved name, the hostname a browser's unsaved
/// page origin reported, else its address.
String _serverName() {
final servers = widget.servers;
final saved = servers?.catalog.servers
.where((server) => server.id == widget.serverId)
.firstOrNull;
final host = widget.server.uri?.host ?? '';
return saved?.name ??
servers?.originHostname ??
(host.isEmpty ? 'This server' : host);
}
bool _hostnameAsked = false;
/// Asks this server once for its hostname, which names a server the app
/// named by its address. The chat pool already asks every saved machine.
void _learnServerHostname() {
final servers = widget.servers;
if (_hostnameAsked || servers == null || !_session.connected) return;
if (widget.chatPool != null && widget.serverId != null) return;
_hostnameAsked = true;
final serverId = widget.serverId;
unawaited(
fetchServerHostname(_session.gateway).then((hostname) {
if (mounted) unawaited(servers.learnHostname(serverId, hostname));
}),
);
}
void _chatSyncChanged() => _chatRuntime.syncToken.value =
widget.chatPool?.revision ?? _session.connectionEpoch;