tsc-ui: library target with RunOptions for the mobile apps
The app moves behind `tsc_ui::run(RunOptions)`; tsc-desktop is a thin binary around it. Mobile apps pass their storage directory as data_dir. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
This commit is contained in:
4 files changed
+25
-7
No files matched your search
@@ -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"
|
||||
|
||||
@@ -104,16 +104,27 @@ fn with_app<R>(f: impl FnOnce(&mut App) -> R) -> Option<R> {
|
||||
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
|
||||
/// `<data dir>/tsc`. Mobile platforms pass their app storage directory.
|
||||
pub data_dir: Option<std::path::PathBuf>,
|
||||
}
|
||||
|
||||
/// 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=<png> 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")?;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
//! Slint user interface shared by the desktop binary and the mobile apps.
|
||||
|
||||
mod app;
|
||||
|
||||
pub use app::{RunOptions, run};
|
||||
@@ -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())
|
||||
}
|
||||
Reference in new issue
Block a user