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

@ -16,6 +16,7 @@ pub fn register_builtins(registry: &mut Registry) -> Result<(), EngineError> {
registry.register(Box::new(app::About))?;
registry.register(Box::new(app::Quit))?;
registry.register(Box::new(project::Open))?;
registry.register(Box::new(project::OpenDialog))?;
registry.register(Box::new(project::Close))?;
registry.register(Box::new(project::Children))?;
registry.register(Box::new(file::Open))?;

View file

@ -1,11 +1,32 @@
//! Project commands: `project.open`, `project.close`, `project.children`.
//! Project commands: `project.open`, `project.openDialog`, `project.close`,
//! `project.children`.
use serde::{Deserialize, Serialize};
use serde_json::{Value, json};
use super::params::{parse, project_path};
use crate::workspace::{Workspace, path_string, vfs_error};
use crate::{Command, CommandSpec, EngineError, Event, Outcome, State};
use crate::{Command, CommandSpec, Effect, EngineError, Event, Outcome, State};
/// `project.openDialog`: asks the host to show the folder picker; the host
/// runs `project.open` with the chosen folder.
pub struct OpenDialog;
impl Command for OpenDialog {
fn spec(&self) -> &CommandSpec {
&CommandSpec {
id: "project.openDialog",
label: "Open Folder…",
menu_path: Some("File/Open Folder…"),
default_shortcut: Some("Mod+O"),
params: "none; returns null and the effect pickFolder: the host shows the folder picker and runs project.open with the choice; cancelling is not an error",
}
}
fn run(&self, _state: &mut State, _params: Value) -> Result<Outcome, EngineError> {
Ok(Outcome::effect(Effect::PickFolder))
}
}
/// Closes the open project and all its buffers.
///

View file

@ -28,6 +28,9 @@ pub struct CommandSpec {
pub enum Effect {
/// Quit the application.
Quit,
/// Show the native folder picker and run `project.open` with the chosen
/// folder. Cancelling the picker does nothing and is not an error.
PickFolder,
}
/// Result of a successful command.

View file

@ -176,6 +176,14 @@ mod tests {
assert_eq!(out.effects, vec![Effect::Quit]);
}
#[test]
fn open_dialog_asks_the_host_to_pick_a_folder() {
let mut engine = Engine::new().unwrap();
let out = engine.execute("project.openDialog", Value::Null).unwrap();
assert_eq!(out.effects, vec![Effect::PickFolder]);
assert_eq!(out.value, Value::Null);
}
#[test]
fn unknown_and_disabled_commands_fail() {
let mut engine = Engine::new().unwrap();
@ -233,6 +241,7 @@ mod tests {
"project.children",
"project.close",
"project.open",
"project.openDialog",
"test.disabled",
]
);