AppFlowy/rust-lib/flowy-sdk/src/lib.rs

53 lines
1.2 KiB
Rust
Raw Normal View History

mod flowy_server;
2021-06-30 15:11:27 +00:00
pub mod module;
use crate::{
flowy_server::{ArcFlowyServer, MockFlowyServer},
user_server::MockUserServer,
};
2021-07-08 13:23:44 +00:00
use flowy_dispatch::prelude::*;
2021-06-30 15:11:27 +00:00
use module::build_modules;
pub use module::*;
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
2021-07-09 15:31:44 +00:00
2021-07-13 05:14:49 +00:00
static INIT_LOG: AtomicBool = AtomicBool::new(false);
pub struct FlowySDK {
root: String,
server: ArcFlowyServer,
}
2021-06-28 15:58:43 +00:00
impl FlowySDK {
pub fn new(root: &str) -> Self {
let server = Arc::new(MockFlowyServer {});
Self {
root: root.to_owned(),
server,
}
}
pub fn construct(self) {
FlowySDK::init_log(&self.root);
tracing::info!("🔥 Root path: {}", self.root);
flowy_infra::kv::KVStore::init(path);
FlowySDK::init_modules(&self.root, self.server);
}
fn init_log(directory: &str) {
2021-07-13 05:14:49 +00:00
if !INIT_LOG.load(Ordering::SeqCst) {
INIT_LOG.store(true, Ordering::SeqCst);
flowy_log::init_log("flowy", directory, "Debug").unwrap();
}
}
2021-06-28 15:58:43 +00:00
fn init_modules(root: &str, server: ArcFlowyServer) {
2021-07-09 15:31:44 +00:00
let config = ModuleConfig {
root: root.to_owned(),
2021-07-09 15:31:44 +00:00
};
EventDispatch::construct(|| build_modules(config, server));
2021-06-30 15:11:27 +00:00
}
2021-06-28 15:58:43 +00:00
}