Skip to main content

agent_hub_runtime/desktop/
mod.rs

1//! Desktop composition; shared behavior is configured before the host runs it.
2
3mod ipc;
4pub(crate) mod lifecycle;
5mod startup;
6pub(crate) mod tray;
7pub(crate) mod workspaces;
8
9use std::sync::Arc;
10use std::time::Instant;
11
12use crate::{commands, core};
13use lifecycle::restore_main_window;
14
15/// Configure shared application state, services, lifecycle, and trusted IPC.
16///
17/// A host can append Tauri plugins and run this builder with its own Context.
18/// Add extension commands and initialization through plugins: calling `setup`
19/// or `invoke_handler` on the returned builder replaces the shared handler.
20/// This initializes the application store; call once per desktop launch.
21pub fn builder() -> anyhow::Result<tauri::Builder<tauri::Wry>> {
22    let pre_builder_start = Instant::now();
23    let (store, startup_timings) = core::app_state::initialize_store()?;
24    let pre_builder_ms = pre_builder_start.elapsed().as_millis();
25    let store_for_setup = store.clone();
26
27    let cancel_registry = Arc::new(core::install_cancel::InstallCancelRegistry::new());
28
29    let builder_start = Instant::now();
30    let builder = tauri::Builder::default()
31        .manage(workspaces::WorkspaceWindows::default())
32        .manage(store)
33        .manage(agent_hub_core::skill_source::SkillSourceRegistry::default())
34        .manage(cancel_registry)
35        .manage(Arc::new(core::agent_usage::AgentUsage::default()))
36        .manage(Arc::new(std::sync::Mutex::new(
37            core::system_load::SystemLoad::default(),
38        )))
39        .manage(Arc::new(core::terminal::TerminalManager::default()))
40        .manage(Arc::new(core::file_preview::FilePreviews::default()))
41        .manage(Arc::new(core::preview::Preview::default()))
42        .manage(commands::preview_native::NativeViews::default())
43        .plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
44            restore_main_window(app);
45        }))
46        .plugin(tauri_plugin_dialog::init())
47        .plugin(tauri_plugin_shell::init())
48        .plugin(tauri_plugin_opener::init())
49        .plugin(tauri_plugin_clipboard_manager::init())
50        .plugin(tauri_plugin_updater::Builder::new().build())
51        .setup(move |app| {
52            startup::setup(
53                app,
54                store_for_setup,
55                startup_timings,
56                pre_builder_ms,
57                builder_start,
58            )
59        })
60        .invoke_handler(ipc::handler());
61    #[cfg(feature = "herdr")]
62    let builder = builder.manage(Arc::new(core::herdr::tools::HerdrTools::default()));
63    Ok(builder)
64}