From ee2f7097ceff66a84b39f88bfbfcabf358de8148 Mon Sep 17 00:00:00 2001 From: Vassiliy Yegorov Date: Tue, 9 Jun 2026 21:28:54 +0700 Subject: [PATCH] feat(app): M2 layout TS types + bridge commands Co-Authored-By: Claude Opus 4.8 (1M context) --- app/src/layoutTypes.ts | 42 +++++++++++++++++++++++++++++ app/src/socketBridge.ts | 60 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 app/src/layoutTypes.ts diff --git a/app/src/layoutTypes.ts b/app/src/layoutTypes.ts new file mode 100644 index 0000000..e8ca7c0 --- /dev/null +++ b/app/src/layoutTypes.ts @@ -0,0 +1,42 @@ +export type Orient = "h" | "v"; + +export type LayoutNode = + | { leaf: { surface_id: string } } + | { split: { orient: Orient; ratios: number[]; children: LayoutNode[] } }; + +export interface SurfaceView { + spec: { + command: string; + args: string[]; + cwd: string; + agent_label: string | null; + cols: number; + rows: number; + autostart: boolean; + }; + running: boolean; +} + +export interface Group { + id: string; + name: string; + color: string; + order: number; +} + +export interface WorkspaceView { + id: string; + path: string; + name: string; + group_id: string | null; + order: number; + unread: boolean; + layout: LayoutNode | null; + surfaces: Record; +} + +export function leafIds(node: LayoutNode | null): string[] { + if (!node) return []; + if ("leaf" in node) return [node.leaf.surface_id]; + return node.split.children.flatMap(leafIds); +} diff --git a/app/src/socketBridge.ts b/app/src/socketBridge.ts index 9688ee6..28c5062 100644 --- a/app/src/socketBridge.ts +++ b/app/src/socketBridge.ts @@ -1,5 +1,6 @@ import { invoke, Channel } from "@tauri-apps/api/core"; import { listen } from "@tauri-apps/api/event"; +import type { Group, WorkspaceView } from "./layoutTypes"; export interface WorkspaceStatus { workspace_id: string; @@ -73,3 +74,62 @@ export function onDaemonEvent(handler: (evt: DaemonEvt) => void): Promise<() => export function onDaemonRawEvent(name: string, handler: () => void): Promise<() => void> { return listen(name, () => handler()); } + +// ---- M2 additions ---- + +export interface StatusResult { + groups: Group[]; + workspaces: WorkspaceView[]; +} + +export async function getStatusFull(): Promise { + return await invoke("status"); +} + +export async function splitSurface(surfaceId: string, dir: "right" | "down", command?: string, args: string[] = []): Promise { + const data = await invoke<{ surface_id: string }>("split_surface", { surfaceId, dir, command: command ?? null, args }); + return data.surface_id; +} + +export async function setRatios(workspaceId: string, nodePath: number[], ratios: number[]): Promise { + await invoke("set_ratios", { workspaceId, nodePath, ratios }); +} + +export async function moveSurface(surfaceId: string, targetSurfaceId: string, edge: "left" | "right" | "top" | "bottom"): Promise { + await invoke("move_surface", { surfaceId, targetSurfaceId, edge }); +} + +export async function applyPreset(workspaceId: string, presetId: string, slots: { command?: string; args?: string[] }[]): Promise { + const data = await invoke<{ surface_ids: string[] }>("apply_preset", { + workspaceId, presetId, + slots: slots.map((s) => ({ command: s.command ?? null, args: s.args ?? [] })), + }); + return data.surface_ids; +} + +export async function restartSurface(surfaceId: string): Promise { + await invoke("restart_surface", { surfaceId }); +} + +export async function closeWorkspaceCmd(workspaceId: string): Promise { + await invoke("close_workspace", { workspaceId }); +} + +export async function setWorkspaceMeta(workspaceId: string, meta: { name?: string; groupId?: string | null; unread?: boolean; order?: number }): Promise { + await invoke("set_workspace_meta", { + workspaceId, + name: meta.name ?? null, + groupId: meta.groupId === undefined ? null : meta.groupId, + unread: meta.unread ?? null, + order: meta.order ?? null, + }); +} + +export async function createGroup(name: string, color: string): Promise { + const data = await invoke<{ group_id: string }>("create_group", { name, color }); + return data.group_id; +} + +export async function closeSurfaceCmd(surfaceId: string): Promise { + await invoke("close_surface", { surfaceId }); +}