Merge main into ios-port and update the iOS CFW transport

This commit is contained in:
James Babcock committed 2026-09-17 23:33:51 -07:00
commit e8e144f3f2
156 files changed
+10528 -1679

No files matched your search

+100
View File
@@ -0,0 +1,100 @@
/**
* The terminal session list as it is drawn in two places: the Terminal app's
* hub window (in the worker) and the Glanceboard's Terminal widget (on the
* main thread). The worker publishes a snapshot of the list through the
* host's worker-state channel; both painters use drawSessionRow so a row
* looks the same in each.
*
* No NativeScript imports: this module is bundled into the worker as well.
*/
import { type GrayImage, type UiFont } from "../../graphics/image";
import { truncateText } from "../../graphics/textwrap";
/** Worker-state key the Terminal worker publishes its snapshot under. */
export const TERMINAL_SESSIONS_STATE_KEY = "terminal:sessions";
/** Alternation period of the activity indicator, shared by hub rows, the widget and sidebar cursors. */
export const SESSION_ACTIVITY_STEP_MS = 800;
export type TerminalSessionRow = {
/** Connection-scoped identity (connection id + socket). */
key: string;
label: string;
/** Local-clock time (Date.now() domain) until which the session counts as active; 0 = idle. */
activeUntilMs: number;
/** Sidebar glyph ("1", "2", ...) of the view window showing this session, or null when none is open. */
openGlyph: string | null;
};
export type TerminalHostGroup = {
/** Host name, shown as a heading when more than one host is connected. */
name: string;
sessions: TerminalSessionRow[];
};
export type TerminalSessionsSnapshot = {
/** Connected hosts, each with its live sessions most-recently-updated first. */
hosts: TerminalHostGroup[];
/** The hub's status line ("Connecting...", "No connections configured.", ...). */
status: string;
/** Whether any g2mirror connection is configured at all. */
configured: boolean;
};
/** Whether a row's activity indicator should show right now. */
export function isSessionRowActive(row: TerminalSessionRow, nowMs = Date.now()): boolean {
return row.activeUntilMs > nowMs;
}
/** Width of the window-number column (one glyph plus breathing room). */
export function sessionGlyphColumnWidth(font: UiFont): number {
return font.measureText("W") + 6;
}
/** Left edge of the label in a row whose activity gutter starts at `x`. */
export function sessionLabelX(font: UiFont, x: number): number {
return x + SESSION_INDICATOR_SIZE + 4 + sessionGlyphColumnWidth(font);
}
const SESSION_INDICATOR_SIZE = 6;
/**
* One session row: the activity indicator in the gutter at `x` (a small
* square, filled on even animation phases and outlined on odd ones, drawn as
* shapes rather than a font glyph so both states read in every UI font),
* then the open view window's glyph in its own column, then the label,
* truncated (never wrapped) to fit `width`.
*/
export function drawSessionRow(
image: GrayImage,
font: UiFont,
options: {
x: number;
/** Top of the text line. */
y: number;
/** Horizontal room from `x`, label included. */
width: number;
label: string;
openGlyph: string | null;
active: boolean;
/** Animation phase (0 = filled indicator). */
phase: number;
/** Text brightness for the label (the glyph draws a little dimmer). */
value: number;
},
): void {
const { x, y, width, label, openGlyph, active, phase, value } = options;
if (active) {
const iy = y + Math.max(0, ((font.lineHeight - SESSION_INDICATOR_SIZE) / 2) | 0);
if (phase % 2 === 0) {
image.fillRect(x, iy, SESSION_INDICATOR_SIZE, SESSION_INDICATOR_SIZE, value);
} else {
image.drawRect(x, iy, SESSION_INDICATOR_SIZE, SESSION_INDICATOR_SIZE, value);
}
}
if (openGlyph) {
image.drawText(font, x + SESSION_INDICATOR_SIZE + 4, y, openGlyph, Math.max(0, value - 60));
}
const labelX = sessionLabelX(font, x);
image.drawText(font, labelX, y, truncateText(font, label, Math.max(0, x + width - labelX)), value);
}
+83 -17
View File
@@ -38,6 +38,11 @@ import { getDefaultSmallFont, getTerminalFontConfig } from "../../graphics/ui-fo
import { layoutHubHeader } from "./hub-header";
import { truncateText } from "../../graphics/textwrap";
import { TERMINAL_ICON_GLYPHS, type IconActivity } from "../../graphics/icons";
import {
drawSessionRow,
TERMINAL_SESSIONS_STATE_KEY,
type TerminalSessionsSnapshot,
} from "./session-list";
import * as frameTimings from "../../native/frame-timings";
import { getActiveDisplay } from "../../native/active-display";
import { GESTURE_DOUBLE_CLICK, type InputEvent } from "../../ui/gestures";
@@ -723,6 +728,48 @@ function renderHubWindows(): void {
for (const window of windows.values()) {
if (window.kind === "hub") scheduleRender(window);
}
// Every change the hub repaints for is one the published list may reflect.
publishSessionsSnapshot();
}
let lastPublishedSnapshot = "";
/**
* Publish the session list for main-thread consumers (the Glanceboard's
* Terminal widget): connected hosts with their sessions most-recently-updated
* first, each with its activity deadline (local clock, so the consumer can
* expire and animate it itself) and the glyph of its open view window. Posted
* only when the JSON actually changed.
*/
function publishSessionsSnapshot(): void {
const connected = connectedControls();
const snapshot: TerminalSessionsSnapshot = {
hosts: connected.map((control) => {
const connectionId = control.config.id;
const sessions = (control.state?.sessions ?? [])
.slice()
.sort(
(a, b) =>
(sessionRecency.get(recencyKey(connectionId, b.socket)) ?? 0) -
(sessionRecency.get(recencyKey(connectionId, a.socket)) ?? 0),
);
return {
name: connectionDisplayName(control.config),
sessions: sessions.map((session) => ({
key: recencyKey(connectionId, session.socket),
label: sessionLabel(session),
activeUntilMs: (sessionActivity.get(recencyKey(connectionId, session.socket)) ?? -ACTIVITY_ACTIVE_MS) + ACTIVITY_ACTIVE_MS,
openGlyph: viewGlyphForSocket(connectionId, session.socket),
})),
};
}),
status: sessionsStatusLine(),
configured: controls.size > 0,
};
const encoded = JSON.stringify(snapshot);
if (encoded === lastPublishedSnapshot) return;
lastPublishedSnapshot = encoded;
post({ type: "publish-state", key: TERMINAL_SESSIONS_STATE_KEY, state: snapshot });
}
// One animation clock for foreground hub rows and every terminal sidebar icon.
@@ -1118,6 +1165,8 @@ type HubItem = {
heading?: boolean;
/** Session with recent output: an animated indicator marks the row. */
active?: boolean;
/** Glyph of the view window showing this session (the number column). */
openGlyph?: string | null;
onSelect?: () => void;
};
@@ -1183,10 +1232,10 @@ function hubSessionItems(window: HubWindow): HubItem[] {
}
const sessions = orderedSessions(window, control);
for (const session of sessions) {
const openWindowId = viewWindowIdForSocket(control.config.id, session.socket);
items.push({
label: openWindowId ? `${sessionLabel(session)} [open]` : sessionLabel(session),
label: sessionLabel(session),
active: isSessionActive(control.config.id, session.socket),
openGlyph: viewGlyphForSocket(control.config.id, session.socket),
onSelect: () => {
const windowId = viewWindowIdForSocket(control.config.id, session.socket);
if (windowId) {
@@ -1421,6 +1470,19 @@ function handleHubInput(window: HubWindow, event: InputEvent, frameId: number):
* Includes views that were requested but whose surface hasn't opened yet, so
* a quick double-select can't spawn two windows for one session.
*/
/** Sidebar glyph of the (open or opening) view window on a session, or null. */
function viewGlyphForSocket(connectionId: string, socket: string): string | null {
for (const window of windows.values()) {
if (window.kind === "view" && window.connectionId === connectionId && window.socket === socket) {
return window.glyph || null;
}
}
for (const pending of pendingViews.values()) {
if (pending.connectionId === connectionId && pending.socket === socket) return pending.glyph || null;
}
return null;
}
function viewWindowIdForSocket(connectionId: string, socket: string): string | null {
for (const window of windows.values()) {
if (window.kind === "view" && window.connectionId === connectionId && window.socket === socket) {
@@ -1539,20 +1601,18 @@ function paintHub(window: HubWindow): GrayImage {
// an outline-only selection signals the sidebar owns input.
drawSelectionHighlight(image, 20, y - 2, window.viewportWidth - 40, hubRowH - 1, window.focused, 8);
}
image.drawText(chromeFont(), 32, y + 2, item.label, selected ? 255 : 200);
if (item.active) {
// Activity indicator in the gutter left of the label, alternating
// filled/outline each animation step (drawn shapes, not a font glyph,
// so the two states render distinctly in every UI font).
const size = 6;
const iy = y + 2 + Math.max(0, ((font.lineHeight - size) / 2) | 0);
const value = selected ? 255 : 200;
if (hubAnimationPhase === 0) {
image.fillRect(22, iy, size, size, value);
} else {
image.drawRect(22, iy, size, size, value);
}
}
// Activity gutter, open-window number column, then the label, truncated
// to the row (shared with the Glanceboard's Terminal widget).
drawSessionRow(image, chromeFont(), {
x: 22,
y: y + 2,
width: window.viewportWidth - 22 - 26,
label: item.label,
openGlyph: item.openGlyph ?? null,
active: Boolean(item.active),
phase: hubAnimationPhase,
value: selected ? 255 : 200,
});
}
if (items.length > visibleRowCount) {
drawListScrollbar(
@@ -1595,6 +1655,11 @@ function hubStatusLine(window: HubWindow): string {
if (window.mode === "connections") {
return "Select a connection to connect, disconnect, or remove.";
}
return sessionsStatusLine();
}
/** The sessions view's status line (also published with the session snapshot). */
function sessionsStatusLine(): string {
if (controls.size === 0) {
return "No connections configured.";
}
@@ -1830,7 +1895,8 @@ function toolListSessions(): ToolResult {
lines.push(`${connectionDisplayName(control.config)}:`);
}
for (const session of sessions) {
const open = viewWindowIdForSocket(control.config.id, session.socket) ? " [open]" : "";
const glyph = viewGlyphForSocket(control.config.id, session.socket);
const open = glyph ? ` [open in window ${glyph}]` : viewWindowIdForSocket(control.config.id, session.socket) ? " [open]" : "";
lines.push(`- ${sessionLabel(session)}${open}`);
}
if (!sessions.length && multiHost) {