Files
pipelines/app/lib/core/servers/server_context.dart
T
alan c264f865ff 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>
2026-12-02 15:58:28 +00:00

51 lines
1.6 KiB
Dart

import 'package:flutter/widgets.dart';
import '../../features/settings/server_connections.dart';
/// The machine owning this mounted app. A profile rename rebuilds consumers;
/// changing machines creates a new gateway and app instead.
class ServerContext extends InheritedNotifier<ServerConnections> {
const ServerContext({
super.key,
required ServerConnections connections,
required this.serverId,
required super.child,
}) : super(notifier: connections);
final String? serverId;
static ServerContext? maybeOf(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<ServerContext>();
/// The machine's name; a browser's unsaved page origin is named by the
/// hostname it reported.
String? get name {
if (serverId == null) return notifier!.originHostname;
for (final server in notifier!.catalog.servers) {
if (server.id == serverId) return server.name;
}
return null;
}
static String? nameFor(BuildContext context, String id) {
final scope = maybeOf(context);
for (final machine
in scope?.notifier?.catalog.servers ?? const <dynamic>[]) {
if (machine.id == id) return machine.name as String;
}
return null;
}
static Widget forServer(BuildContext context, String id, Widget child) {
final scope = maybeOf(context);
return scope == null || id.isEmpty
? child
: ServerContext(
connections: scope.notifier!,
serverId: id,
child: child,
);
}
static String metadata(BuildContext context, String detail) =>
[?maybeOf(context)?.name, if (detail.isNotEmpty) detail].join(' · ');
}