M1.4: desktop bridge: engine events to the window, folder picker, live project tree

The desktop host publishes every engine event, from commands and from a
pump thread that calls Engine::pump_vfs every 100 ms, to control channel
subscribers and to the window as the Tauri event engine://event, in engine
order. ui/src/ipc.ts gets a typed onEngineEvent; its first subscription
calls engine_ready, and the host replays the current project and buffers,
so a project opened from the command line (lutra-desktop --control PORT
PATH) reaches the UI. project.openDialog returns Effect::PickFolder; the
host shows the native folder picker (tauri-plugin-dialog, licence checked)
and opens the choice, one picker at a time, cancel is not an error.
Capabilities shrink to event listen/unlisten.

Contract fix: the M1.5 project UI assumed shapes the engine does not use.
engineEvents.ts now translates engine events ({kind: projectOpened, ...})
and project.children results ({dir, entries, truncated}) into the UI types,
keeping role and truncated; the store maps listings through
toTreeEntries() and the project tests use the real engine shapes.

Verified in the running app on Windows 11: tree of a project given on the
command line, expanding src, a file created on disk appearing live, the
folder picker opening one dialog and opening the chosen folder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-15 06:41:49 +02:00
parent 69130d1efb
commit dd98636de4
23 changed files with 751 additions and 99 deletions

View file

@ -12,6 +12,7 @@ import { computed, ref } from "vue";
import { run, type EngineError } from "../ipc";
import {
onEngineEvent,
toTreeEntries,
type EngineEvent,
type ProjectRoot,
type TreeEntry,
@ -19,7 +20,7 @@ import {
/** Engine command ids used by the project tool window. */
export const PROJECT_COMMANDS = {
/** Lists one directory: params `{ dir }`, result `TreeEntry[]`. */
/** Lists one directory: params `{ dir }`, result `{ dir, entries, truncated }` (see `toTreeEntries`). */
children: "project.children",
/** Shows the folder picker and opens the chosen folder. */
openDialog: "project.openDialog",
@ -35,6 +36,8 @@ export interface DirState {
loading: boolean;
/** Error of the last `project.children` call, null if it succeeded. */
error: EngineError | null;
/** The engine listed only part of the directory. */
truncated: boolean;
}
/** A visible line of the flattened tree. */
@ -136,17 +139,26 @@ export const useProjectStore = defineStore("project", () => {
async function loadChildren(dir: string): Promise<void> {
const request = ++nextRequest;
requests.set(dir, request);
dirs.value[dir] = { entries: cachedEntries(dir), loading: true, error: null };
const result = await run<TreeEntry[]>(PROJECT_COMMANDS.children, { dir });
const truncated = dirs.value[dir]?.truncated ?? false;
dirs.value[dir] = { entries: cachedEntries(dir), loading: true, error: null, truncated };
const result = await run<unknown>(PROJECT_COMMANDS.children, { dir });
if (requests.get(dir) !== request) {
return;
}
if (result.ok) {
const entries = result.value;
dirs.value[dir] = { entries, loading: false, error: null };
prune(dir, entries);
const listing = result.ok ? toTreeEntries(result.value) : null;
if (listing) {
dirs.value[dir] = {
entries: listing.entries,
loading: false,
error: null,
truncated: listing.truncated,
};
prune(dir, listing.entries);
} else {
dirs.value[dir] = { entries: cachedEntries(dir), loading: false, error: result.error };
const error = result.ok
? { code: "ipc", message: `unexpected result of ${PROJECT_COMMANDS.children}` }
: result.error;
dirs.value[dir] = { entries: cachedEntries(dir), loading: false, error, truncated };
}
}