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:
parent
69130d1efb
commit
dd98636de4
23 changed files with 751 additions and 99 deletions
|
|
@ -1,8 +1,9 @@
|
|||
//! The Lutra desktop app (layer L6): a Tauri 2 shell around the engine.
|
||||
//!
|
||||
//! Builds the main window with the theme tokens injected before first paint,
|
||||
//! bridges frontend IPC to engine commands, and optionally serves the JSON
|
||||
//! control channel (`--control PORT`).
|
||||
//! bridges frontend IPC to engine commands and engine events to the window
|
||||
//! (see [`host`]), opens the project given on the command line, and
|
||||
//! optionally serves the JSON control channel (`--control PORT`).
|
||||
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
|
|
@ -53,25 +54,24 @@ fn main() -> ExitCode {
|
|||
/// A message if the engine cannot start, the control port cannot be bound,
|
||||
/// or Tauri fails.
|
||||
fn run(args: &args::Args) -> Result<(), String> {
|
||||
let host = Arc::new(Host::new().map_err(|e| e.to_string())?);
|
||||
let host = Host::new().map_err(|e| e.to_string())?;
|
||||
if let Some(port) = args.control {
|
||||
let server = lutra_control::start(port, host.clone())
|
||||
.map_err(|e| format!("cannot serve the control channel on port {port}: {e}"))?;
|
||||
eprintln!("lutra: control channel on {}", server.local_addr());
|
||||
}
|
||||
if let Some(path) = &args.path {
|
||||
eprintln!(
|
||||
"lutra: opening {} arrives with milestone M1; starting without a project",
|
||||
path.display()
|
||||
);
|
||||
}
|
||||
host.start_pump()
|
||||
.map_err(|e| format!("cannot start watching for changes: {e}"))?;
|
||||
let theme = theme::DARK;
|
||||
let setup_host = host.clone();
|
||||
let initial_path = args.path.clone();
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.manage(host)
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
engine_execute,
|
||||
engine_list_commands
|
||||
engine_list_commands,
|
||||
engine_ready
|
||||
])
|
||||
.setup(move |app| {
|
||||
setup_host.attach(app.handle().clone());
|
||||
|
|
@ -84,6 +84,11 @@ fn run(args: &args::Args) -> Result<(), String> {
|
|||
window = window.background_color(color);
|
||||
}
|
||||
window.build()?;
|
||||
if let Some(path) = &initial_path
|
||||
&& let Err(e) = setup_host.open_project(path)
|
||||
{
|
||||
eprintln!("lutra: cannot open {}: {e}", path.display());
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
|
|
@ -115,6 +120,13 @@ fn engine_list_commands(host: tauri::State<'_, Arc<Host>>) -> Vec<CommandInfo> {
|
|||
host.commands()
|
||||
}
|
||||
|
||||
/// IPC: the frontend listens for engine events now; replays the current
|
||||
/// project state it may have missed while loading.
|
||||
#[tauri::command]
|
||||
fn engine_ready(host: tauri::State<'_, Arc<Host>>) {
|
||||
host.replay_to_window();
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue