Skip to main content

origin_app/
application.rs

1use crate::module::ModuleRegistry;
2use crate::platform::Platform;
3use origin_domain::Result;
4use serde::Serialize;
5use std::sync::Arc;
6
7/// Product identity, as the frontend needs it to render the shell.
8#[derive(Debug, Clone, Serialize)]
9#[cfg_attr(feature = "ts", derive(ts_rs::TS))]
10pub struct AppInfo {
11    pub id: String,
12    pub name: String,
13    pub version: String,
14    /// Modules compiled into this build, in registration order.
15    pub modules: Vec<String>,
16}
17
18/// A fully assembled application.
19///
20/// It knows nothing about Tauri. The host layer takes one of these and exposes it to
21/// the desktop shell; a CLI or a headless agent could take the same value.
22#[derive(Debug)]
23pub struct Application {
24    platform: Platform,
25    registry: ModuleRegistry,
26}
27
28impl Application {
29    pub(crate) fn new(platform: Platform, registry: ModuleRegistry) -> Self {
30        Self { platform, registry }
31    }
32
33    pub fn platform(&self) -> &Platform {
34        &self.platform
35    }
36
37    /// Resolve a service registered by a module.
38    pub fn service<T: Send + Sync + 'static>(&self) -> Option<Arc<T>> {
39        self.registry.service::<T>()
40    }
41
42    /// Resolve a service or fail with a configuration error.
43    pub fn require<T: Send + Sync + 'static>(&self) -> Result<Arc<T>> {
44        self.registry.require::<T>()
45    }
46
47    /// Ids of the registered modules, in registration order.
48    pub fn modules(&self) -> &[&'static str] {
49        self.registry.module_ids()
50    }
51}