1#[macro_use]
19extern crate tracing;
20
21pub mod blocking;
22pub mod experiments;
23pub mod io;
24pub mod macros;
25pub mod model;
26pub mod search;
27pub mod service;
28pub mod subscribers;
29#[cfg(target_family = "wasm")]
30pub mod wasm;
31
32#[derive(Clone)]
33pub struct Lb {
34 pub config: Config,
35 pub user_last_seen: Arc<RwLock<Instant>>,
36 pub user_wake: Arc<Notify>,
37 pub keychain: Keychain,
38 pub db: LbDb,
39 pub docs: AsyncDocs,
40 pub client: Network,
41 pub events: EventSubs,
42 pub status: StatusUpdater,
43 pub syncer: Syncer,
44}
45
46impl Lb {
47 #[instrument(name = "Lb::init", level = "info", skip_all, err(Debug))]
48 pub async fn init(config: Config) -> LbResult<Self> {
49 logging::init(&config)?;
50
51 let docs = AsyncDocs::from(&config);
52 let db = io::init_with_migration(Path::new(&config.writeable_path))
53 .map_err(|err| LbErrKind::Unexpected(format!("{err:#?}")))?;
54 let keychain = Keychain::from(db.schema.account.as_ref());
55 let db = Arc::new(RwLock::new(db));
56 let client = Network { client_type: config.client_type, ..Network::default() };
57
58 let status = StatusUpdater::default();
59 let syncer = Default::default();
60 let events = EventSubs::default();
61 let user_last_seen = Arc::new(RwLock::new(Instant::now()));
62 let user_wake = Arc::new(Notify::new());
63
64 let result = Self {
65 config,
66 keychain,
67 db,
68 docs,
69 client,
70 syncer,
71 events,
72 status,
73 user_last_seen,
74 user_wake,
75 };
76
77 #[cfg(not(target_family = "wasm"))]
78 {
79 result.setup_syncer();
80 result.setup_status().await?;
81 }
82
83 Ok(result)
84 }
85}
86
87pub fn get_code_version() -> &'static str {
88 env!("CARGO_PKG_VERSION")
89}
90
91pub static DEFAULT_API_LOCATION: &str = "https://app.lockbook.net";
92pub static CORE_CODE_VERSION: &str = env!("CARGO_PKG_VERSION");
93
94use crate::subscribers::syncer::Syncer;
95
96use crate::service::logging;
97use io::LbDb;
98use io::docs::AsyncDocs;
99use io::network::Network;
100use model::core_config::Config;
101pub use model::errors::{LbErrKind, LbResult};
102use service::events::EventSubs;
103use service::keychain::Keychain;
104use std::path::Path;
105use std::sync::Arc;
106use subscribers::status::StatusUpdater;
107use tokio::sync::{Notify, RwLock};
108pub use uuid::Uuid;
109use web_time::Instant;