61c7eee2b0
"Open in new window" sits beside Float: the chat pane and chat list row menus, a floating chat window's title bar, the terminal options menu and the diff bar, plus Alt+Shift+Y for the chat with the keyboard (listed in the shortcut help). Once the window opens the item leaves the main window as Float takes a pane out of the tiling. The window is its own app instance at /window/chat/<id>, /window/terminal?tab=<key> or /window/diff/<token>: only that item, named after it, with "Bring back to main window". It has its own connection and writes no shared layout (no open-chat workspace, window store or terminal layout) and posts no notifications, so they stay the main window's. Web opens a popup window (a blocked popup offers a tab); Linux and macOS start a second process with --detached (Flutter's multi-window API is still experimental); Android and iOS hide the action. The capture kit gains a follow step for windows a page opens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
93 lines
3.2 KiB
Dart
93 lines
3.2 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
import '../core/api_gateway.dart';
|
|
import '../core/servers/chat/chat_server_pool.dart';
|
|
import '../features/terminal/terminal_hub.dart';
|
|
import '../features/terminal/terminal_layout.dart';
|
|
import '../features/terminal/terminal_machines.dart';
|
|
import '../features/terminal/terminal_surface.dart';
|
|
import '../features/terminal/terminal_toggle_button.dart';
|
|
import '../features/terminal/terminal_window.dart';
|
|
import '../shell/list_detail_policy.dart';
|
|
import '../shell/windows/window_manager.dart';
|
|
|
|
/// The app's machine terminals: one hub over every connected machine (the
|
|
/// chat pool's, else the app's own server), kept for the app's lifetime so
|
|
/// shells and their output survive navigation and hidden panels.
|
|
class AppTerminals {
|
|
AppTerminals({
|
|
required ChatServerPool? pool,
|
|
required Listenable connection,
|
|
required bool Function() connected,
|
|
required ApiGateway gateway,
|
|
required String machineId,
|
|
required String Function() machineName,
|
|
required this.layout,
|
|
WindowManager? windows,
|
|
}) : machines = pool != null
|
|
? PoolTerminalMachines(pool)
|
|
: SingleTerminalMachines(
|
|
connection: connection,
|
|
connected: connected,
|
|
machine: () => TerminalMachine(
|
|
id: machineId,
|
|
name: machineName(),
|
|
gateway: gateway,
|
|
),
|
|
) {
|
|
hub = TerminalHub(machines);
|
|
if (windows != null) {
|
|
floating = TerminalWindows(manager: windows, hub: hub, layout: layout)
|
|
..start();
|
|
}
|
|
}
|
|
|
|
final ValueNotifier<List<TerminalMachine>> machines;
|
|
final TerminalLayout layout;
|
|
late final TerminalHub hub;
|
|
|
|
/// The terminal's floating window in the app's window system; null
|
|
/// without one (the float mode then shows nothing).
|
|
TerminalWindows? floating;
|
|
|
|
/// [shell] with the terminal panel, window or page around it, and the
|
|
/// app's floating [windows] above both.
|
|
/// [onChat]: whether the phone shortcut that reopens the terminal shows on
|
|
/// this page. Pages whose own bar carries Terminal pass false.
|
|
Widget surround(Widget shell, {bool onChat = true, Widget? windows}) =>
|
|
TerminalSurface(
|
|
hub: hub,
|
|
layout: layout,
|
|
shortcutHere: onChat,
|
|
windows: windows,
|
|
floating: floating,
|
|
child: shell,
|
|
);
|
|
|
|
/// The bar button showing or hiding the terminal.
|
|
Widget toggle() => TerminalToggleButton(layout: layout);
|
|
|
|
/// The Chat tab's shell-bar button. Only a wide layout shows the shell bar
|
|
/// over an open chat, so only there is it kept. A narrow layout has none:
|
|
/// its open chat's own bar carries the terminal (see
|
|
/// `terminalChatBarAction`), and a chat list's bar has none (the shortcut
|
|
/// still shows the terminal).
|
|
Widget? barToggle(BuildContext context) =>
|
|
showsListBesideDetail(context) ? toggle() : null;
|
|
|
|
/// The terminal came back from a detached window: it shows again, on
|
|
/// [tabKey] once that tab is listed.
|
|
void bringBack(String tabKey) {
|
|
hub.activate();
|
|
final tab = hub.tabs.where((tab) => tab.key == tabKey).firstOrNull;
|
|
if (tab != null) hub.select(tab);
|
|
layout.show();
|
|
}
|
|
|
|
void dispose() {
|
|
floating?.dispose();
|
|
hub.dispose();
|
|
machines.dispose();
|
|
}
|
|
}
|