2021-07-19 16:15:20 +08:00
|
|
|
mod deps_resolve;
|
2021-08-20 14:38:03 +08:00
|
|
|
// mod flowy_server;
|
2021-06-30 23:11:27 +08:00
|
|
|
pub mod module;
|
|
|
|
|
2021-07-08 21:23:44 +08:00
|
|
|
use flowy_dispatch::prelude::*;
|
2021-06-30 23:11:27 +08:00
|
|
|
use module::build_modules;
|
2021-07-14 21:12:52 +08:00
|
|
|
pub use module::*;
|
2021-09-04 15:12:53 +08:00
|
|
|
use std::sync::{
|
|
|
|
atomic::{AtomicBool, Ordering},
|
|
|
|
Arc,
|
|
|
|
};
|
2021-07-09 23:31:44 +08:00
|
|
|
|
2021-07-13 13:14:49 +08:00
|
|
|
static INIT_LOG: AtomicBool = AtomicBool::new(false);
|
2021-09-04 15:12:53 +08:00
|
|
|
#[derive(Clone)]
|
2021-07-14 21:12:52 +08:00
|
|
|
pub struct FlowySDK {
|
|
|
|
root: String,
|
2021-09-04 15:12:53 +08:00
|
|
|
dispatch: Arc<EventDispatch>,
|
2021-07-14 21:12:52 +08:00
|
|
|
}
|
2021-06-28 23:58:43 +08:00
|
|
|
|
|
|
|
impl FlowySDK {
|
2021-09-04 15:12:53 +08:00
|
|
|
pub fn new(root: &str) -> Self {
|
|
|
|
init_log(root);
|
|
|
|
init_kv(root);
|
2021-07-14 21:12:52 +08:00
|
|
|
|
2021-09-04 16:12:48 +08:00
|
|
|
tracing::info!("🔥 user folder: {}", root);
|
2021-09-04 15:12:53 +08:00
|
|
|
let dispatch = Arc::new(init_dispatch(root));
|
|
|
|
let root = root.to_owned();
|
|
|
|
Self { root, dispatch }
|
|
|
|
}
|
2021-07-14 21:12:52 +08:00
|
|
|
|
2021-09-04 15:12:53 +08:00
|
|
|
pub fn dispatch(&self) -> Arc<EventDispatch> { self.dispatch.clone() }
|
|
|
|
}
|
2021-07-17 10:26:05 +08:00
|
|
|
|
2021-09-04 15:12:53 +08:00
|
|
|
fn init_kv(root: &str) {
|
|
|
|
match flowy_infra::kv::KV::init(root) {
|
|
|
|
Ok(_) => {},
|
|
|
|
Err(e) => tracing::error!("Init kv store failedL: {}", e),
|
2021-07-14 21:12:52 +08:00
|
|
|
}
|
2021-09-04 15:12:53 +08:00
|
|
|
}
|
2021-07-14 21:12:52 +08:00
|
|
|
|
2021-09-04 15:12:53 +08:00
|
|
|
fn init_log(directory: &str) {
|
|
|
|
if !INIT_LOG.load(Ordering::SeqCst) {
|
|
|
|
INIT_LOG.store(true, Ordering::SeqCst);
|
2021-08-19 14:08:24 +08:00
|
|
|
|
2021-09-04 15:12:53 +08:00
|
|
|
let _ = flowy_log::Builder::new("flowy").local(directory).env_filter("info").build();
|
2021-07-13 13:14:49 +08:00
|
|
|
}
|
2021-09-04 15:12:53 +08:00
|
|
|
}
|
2021-06-28 23:58:43 +08:00
|
|
|
|
2021-09-04 15:12:53 +08:00
|
|
|
fn init_dispatch(root: &str) -> EventDispatch {
|
|
|
|
let config = ModuleConfig { root: root.to_owned() };
|
|
|
|
let dispatch = EventDispatch::construct(|| build_modules(config));
|
|
|
|
dispatch
|
2021-06-28 23:58:43 +08:00
|
|
|
}
|