Files
alan 9e218f755a Consolidate startup and shell on Material
Remove alternate application hosts, page scaffolds, connection controls and icon metadata while preserving Material routing. Isolate navigation fixtures from native update plugins and retain separate startup-update regressions.
2026-11-11 20:11:17 +00:00

88 lines
3.1 KiB
Dart

import '../core/servers/chat/chat_server_pool.dart';
import 'package:flutter/material.dart';
import '../features/chat/chat_runtime.dart';
import '../features/chat/screen.dart';
import '../features/chat/windows/chat_windows.dart';
import '../ui/adaptive/top_bar_notices.dart';
import 'app_session.dart';
import 'connection_status.dart';
import 'server_endpoint.dart';
/// The Chat destination: the shared session list and one read-only thread.
///
/// Before the shared socket accepts its first connection nothing is requested,
/// so an offline launch cannot look like an empty chat list. After that the
/// screen stays mounted through drops; a reconnect advances [syncToken] so the
/// open conversation re-subscribes and re-reads without losing its selection.
class ChatDestination extends StatelessWidget {
const ChatDestination({
super.key,
required this.session,
required this.server,
this.pool,
this.initialSessionId,
this.onSessionSelected,
this.onBack,
this.onWorkspaceEmpty,
this.onAvailableSessionsChanged,
this.runtime,
this.windows,
});
final AppSession session;
final ChatServerPool? pool;
final ServerEndpoint server;
final String? initialSessionId;
final ValueChanged<String>? onSessionSelected;
final VoidCallback? onBack;
final VoidCallback? onWorkspaceEmpty;
final ValueChanged<Set<String>>? onAvailableSessionsChanged;
/// The chats' app-lifetime state and floating windows (see [ChatScreen]).
final ChatRuntime? runtime;
final ChatWindows? windows;
@override
Widget build(BuildContext context) => AnimatedBuilder(
animation: Listenable.merge([session, ?pool]),
builder: (context, _) {
// Saved machines connect independently; their state and sign-in live
// in Settings, so the chat itself carries no connection chrome.
if (pool != null && pool!.servers.catalog.servers.isNotEmpty) {
return _chatScreen();
}
if ((server.requiresConfiguration || server.error != null) &&
session.endpoint == null) {
return ConnectionGate(session: session, server: server);
}
if (!session.everConnected) {
if (session.connected) return _chatScreen();
return ConnectionGate(session: session, server: server);
}
// The banner stays below the top bar; without it the chat screen
// reaches the top edge (an open chat beside the list draws its own bar
// there).
return TopBarNotices(
notices: [if (!session.connected) ConnectionBanner(session: session)],
child: _chatScreen(),
);
},
);
Widget _chatScreen() => ChatScreen(
gateway: pool?.gateway ?? session.gateway,
persistWorkspace: true,
initialSessionId: initialSessionId == null
? null
: pool?.gateway.normalizeId(initialSessionId!) ?? initialSessionId,
syncToken: pool?.revision ?? session.connectionEpoch,
onSessionSelected: onSessionSelected,
onBack: onBack,
onWorkspaceEmpty: onWorkspaceEmpty,
onAvailableSessionsChanged: onAvailableSessionsChanged,
runtime: runtime,
windows: windows,
);
}