1use crate::{HostConfig, TauriNotificationService, TauriOpener};
8use origin_domain::Result;
9use origin_http::HttpClient;
10use origin_http_reqwest::ReqwestHttpClient;
11use origin_platform::{NotificationService, Opener};
12use origin_secrets::SecretStore;
13use origin_secrets_system::SystemSecretStore;
14use origin_storage::Storage;
15use origin_storage_sqlite::SqliteStorage;
16use std::sync::Arc;
17use tauri::{AppHandle, Runtime};
18
19const DATABASE_FILE: &str = "origin.sqlite3";
21
22pub fn storage<R: Runtime>(app: &AppHandle<R>, config: &HostConfig) -> Result<Arc<dyn Storage>> {
32 let _ = app;
33
34 let path = origin_platform::paths::data_dir(&config.app_id)?.join(DATABASE_FILE);
35 tracing::debug!(path = %path.display(), "opening application database");
36
37 Ok(Arc::new(SqliteStorage::open(path)?))
38}
39
40pub fn secret_store(config: &HostConfig) -> Arc<dyn SecretStore> {
42 Arc::new(SystemSecretStore::new(config.app_id.clone()))
43}
44
45pub fn notifications<R: Runtime>(app: &AppHandle<R>) -> Arc<dyn NotificationService> {
47 Arc::new(TauriNotificationService::new(app.clone()))
48}
49
50pub fn http_client<R: Runtime>(
55 app: &AppHandle<R>,
56 config: &HostConfig,
57) -> Result<Arc<dyn HttpClient>> {
58 let package = app.package_info();
59 let user_agent = format!("{}/{} ({})", package.name, package.version, config.app_id);
60
61 Ok(Arc::new(ReqwestHttpClient::new(user_agent)?))
62}
63
64pub fn opener<R: Runtime>(app: &AppHandle<R>) -> Arc<dyn Opener> {
66 Arc::new(TauriOpener::new(app.clone()))
67}