Skip to main content

lattice_mode/
startup.rs

1//! The generic boot-completion signal (design.md §9.1) (DB.5).
2//!
3//! Published once per boot, after `Editor::boot` returns, by each renderer's
4//! post-boot seam (TUI `App::new`, GPUI `GpuiApp::new`) — carrying the file
5//! (if any) passed on the command line. Declared here, alongside the
6//! existing [`crate::ModeEvent`] typed-event precedent, rather than as a
7//! per-renderer ad hoc signal, so any subsystem's `install(&mut boot)` can
8//! subscribe via the generic typed-event bus without a `lattice-host`
9//! dependency. `lattice-dashboard`'s startup-trigger subscription is the
10//! first consumer (`lattice_dashboard::install`).
11
12use std::path::PathBuf;
13
14/// Fired once per boot after `Editor::boot` returns. `opened_file` is the
15/// path (if any) the renderer's post-boot seam captured from the boot
16/// `Document` *before* it moved into `Editor::boot` (which consumes it).
17#[derive(Debug, Clone)]
18///
19/// # Examples
20///
21/// ```
22/// use lattice_mode::Startup;
23/// use lattice_runtime::EventBus;
24///
25/// let bus = EventBus::new();
26/// let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
27/// bus.subscribe_typed::<Startup>(tx); // e.g. from a subsystem's `install`
28/// bus.publish_typed(Startup { opened_file: None }); // the renderer, after boot
29/// assert!(rx.try_recv().unwrap().opened_file.is_none()); // no file: show a dashboard
30/// ```
31pub struct Startup {
32    /// The file named on the command line, or `None` when the editor
33    /// started without one.
34    pub opened_file: Option<PathBuf>,
35}
36
37// DB.5: register as a typed event so `EventBus::publish_typed` /
38// `subscribe_typed` can carry it -- same mechanism `ModeEvent` uses
39// (`event.rs`).
40lattice_protocol::register_event!(
41    Startup,
42    "editor.startup",
43    "Published once per boot, after Editor::boot returns, carrying the file \
44     (if any) opened on the command line.",
45    "lattice-mode",
46);