Skip to main content

origin_tauri/
state.rs

1use crate::HostConfig;
2use origin_app::Application;
3use std::sync::Arc;
4use tokio_util::sync::CancellationToken;
5
6/// Tauri-managed state: the assembled application plus its host configuration.
7#[derive(Debug)]
8pub struct OriginState {
9    application: Arc<Application>,
10    config: HostConfig,
11    /// Stops the sync scheduler. Held here so shutdown can end it deliberately rather
12    /// than relying on process exit.
13    scheduler: CancellationToken,
14}
15
16impl OriginState {
17    pub(crate) fn new(
18        application: Application,
19        config: HostConfig,
20        scheduler: CancellationToken,
21    ) -> Self {
22        Self {
23            application: Arc::new(application),
24            config,
25            scheduler,
26        }
27    }
28
29    /// Stop the background scheduler.
30    pub fn shutdown(&self) {
31        self.scheduler.cancel();
32    }
33
34    pub fn application(&self) -> Arc<Application> {
35        self.application.clone()
36    }
37
38    pub fn config(&self) -> &HostConfig {
39        &self.config
40    }
41}