diff --git a/crates/tsc-ui/Cargo.toml b/crates/tsc-ui/Cargo.toml index 07348ff..d053477 100644 --- a/crates/tsc-ui/Cargo.toml +++ b/crates/tsc-ui/Cargo.toml @@ -8,6 +8,10 @@ license.workspace = true repository.workspace = true publish.workspace = true +[lib] +name = "tsc_ui" +path = "src/lib.rs" + [[bin]] name = "tsc-desktop" path = "src/main.rs" diff --git a/crates/tsc-ui/src/app.rs b/crates/tsc-ui/src/app.rs index d46810a..adff0a5 100644 --- a/crates/tsc-ui/src/app.rs +++ b/crates/tsc-ui/src/app.rs @@ -104,16 +104,27 @@ fn with_app(f: impl FnOnce(&mut App) -> R) -> Option { APP.with(|app| app.borrow_mut().as_mut().map(f)) } -pub fn run() -> Result<()> { +/// Start options for [`run`]. +#[derive(Clone, Debug, Default)] +pub struct RunOptions { + /// Where the client database lives. Default: `TSC_DATA_DIR`, else + /// `/tsc`. Mobile platforms pass their app storage directory. + pub data_dir: Option, +} + +/// Run the app on the current thread until the window closes. The Slint +/// platform must be set up before (the default backend on desktop). +pub fn run(options: RunOptions) -> Result<()> { let runtime = Runtime::new()?; let engine = runtime.block_on(async { Engine::start() }); // Development switches: TSC_DATA_DIR isolates the database, // TSC_AUTOCONNECT=voice|observe connects the first bookmark on start, // TSC_SCREENSHOT= saves the window after TSC_SCREENSHOT_DELAY seconds and exits. - let dir = match std::env::var_os("TSC_DATA_DIR") { - Some(dir) => dir.into(), - None => dirs::data_dir().unwrap_or_else(|| ".".into()).join("tsc"), + let dir = match (options.data_dir, std::env::var_os("TSC_DATA_DIR")) { + (Some(dir), _) => dir, + (None, Some(dir)) => dir.into(), + (None, None) => dirs::data_dir().unwrap_or_else(|| ".".into()).join("tsc"), }; let store = Store::open(&dir.join("client.db")).context("failed to open the client database")?; diff --git a/crates/tsc-ui/src/lib.rs b/crates/tsc-ui/src/lib.rs new file mode 100644 index 0000000..f65782f --- /dev/null +++ b/crates/tsc-ui/src/lib.rs @@ -0,0 +1,5 @@ +//! Slint user interface shared by the desktop binary and the mobile apps. + +mod app; + +pub use app::{RunOptions, run}; diff --git a/crates/tsc-ui/src/main.rs b/crates/tsc-ui/src/main.rs index 87aaa36..ededc93 100644 --- a/crates/tsc-ui/src/main.rs +++ b/crates/tsc-ui/src/main.rs @@ -1,7 +1,5 @@ //! Desktop client. -mod app; - use anyhow::Result; use tracing_subscriber::EnvFilter; @@ -11,5 +9,5 @@ fn main() -> Result<()> { EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("warn")), ) .init(); - app::run() + tsc_ui::run(tsc_ui::RunOptions::default()) }