lib.rs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. mod deps_resolve;
  2. mod flowy_server;
  3. pub mod module;
  4. pub use crate::flowy_server::{ArcFlowyServer, FlowyServerMocker};
  5. use flowy_dispatch::prelude::*;
  6. use module::build_modules;
  7. pub use module::*;
  8. use std::sync::{
  9. atomic::{AtomicBool, Ordering},
  10. Arc,
  11. };
  12. static INIT_LOG: AtomicBool = AtomicBool::new(false);
  13. pub struct FlowySDK {
  14. root: String,
  15. server: ArcFlowyServer,
  16. }
  17. impl FlowySDK {
  18. pub fn new(root: &str) -> Self {
  19. let server = Arc::new(FlowyServerMocker {});
  20. Self {
  21. root: root.to_owned(),
  22. server,
  23. }
  24. }
  25. pub fn construct(self) { FlowySDK::construct_with(&self.root, self.server.clone()) }
  26. pub fn construct_with(root: &str, server: ArcFlowyServer) {
  27. FlowySDK::init_log(root);
  28. tracing::info!("🔥 Root path: {}", root);
  29. match flowy_infra::kv::KVStore::init(root) {
  30. Ok(_) => {},
  31. Err(e) => tracing::error!("Init kv store failedL: {}", e),
  32. }
  33. FlowySDK::init_modules(root, server);
  34. }
  35. fn init_log(directory: &str) {
  36. if !INIT_LOG.load(Ordering::SeqCst) {
  37. INIT_LOG.store(true, Ordering::SeqCst);
  38. flowy_log::init_log("flowy", directory, "Debug").unwrap();
  39. }
  40. }
  41. fn init_modules(root: &str, server: ArcFlowyServer) {
  42. let config = ModuleConfig {
  43. root: root.to_owned(),
  44. };
  45. EventDispatch::construct(|| build_modules(config, server));
  46. }
  47. }