diff --git a/.idea/appflowy_client.iml b/.idea/appflowy_client.iml
index 5c6b5b4d21..fbd3a47727 100644
--- a/.idea/appflowy_client.iml
+++ b/.idea/appflowy_client.iml
@@ -86,6 +86,9 @@
+
+
+
diff --git a/app_flowy/macos/Podfile.lock b/app_flowy/macos/Podfile.lock
index 8aca69f25a..54e66df1b4 100644
--- a/app_flowy/macos/Podfile.lock
+++ b/app_flowy/macos/Podfile.lock
@@ -1,6 +1,8 @@
PODS:
- flowy_editor (0.0.1):
- FlutterMacOS
+ - flowy_infra_ui (0.0.1):
+ - FlutterMacOS
- flowy_sdk (0.0.1):
- FlutterMacOS
- FlutterMacOS (1.0.0)
@@ -13,6 +15,7 @@ PODS:
DEPENDENCIES:
- flowy_editor (from `Flutter/ephemeral/.symlinks/plugins/flowy_editor/macos`)
+ - flowy_infra_ui (from `Flutter/ephemeral/.symlinks/plugins/flowy_infra_ui/macos`)
- flowy_sdk (from `Flutter/ephemeral/.symlinks/plugins/flowy_sdk/macos`)
- FlutterMacOS (from `Flutter/ephemeral`)
- path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`)
@@ -22,6 +25,8 @@ DEPENDENCIES:
EXTERNAL SOURCES:
flowy_editor:
:path: Flutter/ephemeral/.symlinks/plugins/flowy_editor/macos
+ flowy_infra_ui:
+ :path: Flutter/ephemeral/.symlinks/plugins/flowy_infra_ui/macos
flowy_sdk:
:path: Flutter/ephemeral/.symlinks/plugins/flowy_sdk/macos
FlutterMacOS:
@@ -35,6 +40,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
flowy_editor: 26060a984848e6afac1f6a4455511f4114119d8d
+ flowy_infra_ui: 9d5021b1610fe0476eb1191bf7cd41c4a4138d8f
flowy_sdk: c302ac0a22dea596db0df8073b9637b2bf2ff6fd
FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424
path_provider_macos: a0a3fd666cb7cd0448e936fb4abad4052961002b
diff --git a/rust-lib/flowy-sdk/Cargo.toml b/rust-lib/flowy-sdk/Cargo.toml
index 9be05f9cf8..6150dd01a3 100644
--- a/rust-lib/flowy-sdk/Cargo.toml
+++ b/rust-lib/flowy-sdk/Cargo.toml
@@ -15,6 +15,7 @@ flowy-workspace = { path = "../flowy-workspace" }
flowy-database = { path = "../flowy-database" }
tracing = { version = "0.1" }
log = "0.4.14"
+futures-core = { version = "0.3", default-features = false }
[dev-dependencies]
serde = { version = "1.0", features = ["derive"] }
diff --git a/rust-lib/flowy-sdk/src/module.rs b/rust-lib/flowy-sdk/src/module.rs
index ed0afda2f2..b13c3e336a 100644
--- a/rust-lib/flowy-sdk/src/module.rs
+++ b/rust-lib/flowy-sdk/src/module.rs
@@ -1,11 +1,10 @@
-use flowy_dispatch::prelude::Module;
-use flowy_user::prelude::*;
-
use crate::flowy_server::{ArcFlowyServer, FlowyServerMocker};
use flowy_database::DBConnection;
-
+use flowy_dispatch::prelude::Module;
+use flowy_user::{errors::UserError, prelude::*};
use flowy_workspace::prelude::*;
-use std::sync::Arc;
+use futures_core::future::BoxFuture;
+use std::{pin::Pin, sync::Arc};
pub struct ModuleConfig {
pub root: String,
@@ -33,7 +32,18 @@ pub struct WorkspaceUserImpl {
}
impl WorkspaceUser for WorkspaceUserImpl {
- fn set_current_workspace(&self, id: &str) { UserSession::set_current_workspace(id); }
+ fn set_current_workspace(&self, workspace_id: &str) -> BoxFuture<()> {
+ let user_session = self.user_session.clone();
+ let workspace_id = workspace_id.to_owned();
+ Box::pin(async move {
+ match user_session.set_current_workspace(&workspace_id).await {
+ Ok(_) => {},
+ Err(e) => {
+ log::error!("Set current workspace error: {:?}", e);
+ },
+ }
+ })
+ }
fn get_current_workspace(&self) -> Result {
let user_detail = self.user_session.user_detail().map_err(|e| {
diff --git a/rust-lib/flowy-user/src/services/user_session/database.rs b/rust-lib/flowy-user/src/services/user_session/database.rs
index 77b621c6d5..6103ec4e1c 100644
--- a/rust-lib/flowy-user/src/services/user_session/database.rs
+++ b/rust-lib/flowy-user/src/services/user_session/database.rs
@@ -28,7 +28,11 @@ impl UserDB {
}
fn open_user_db(&self, user_id: &str) -> Result<(), UserError> {
- set_user_db_init(true, user_id);
+ if user_id.is_empty() {
+ return Err(ErrorBuilder::new(UserErrorCode::DatabaseInitFailed)
+ .msg("user id is empty")
+ .build());
+ }
let dir = format!("{}/{}", self.db_dir, user_id);
let db = flowy_database::init(&dir).map_err(|e| {
@@ -48,21 +52,20 @@ impl UserDB {
}
pub(crate) fn close_user_db(&self, user_id: &str) -> Result<(), UserError> {
- set_user_db_init(false, user_id);
-
let mut db_map = DB_MAP.write().map_err(|e| {
ErrorBuilder::new(UserErrorCode::DatabaseWriteLocked)
.msg(format!("Close user db failed. {:?}", e))
.build()
})?;
-
+ set_user_db_init(false, user_id);
db_map.remove(user_id);
Ok(())
}
pub(crate) fn get_connection(&self, user_id: &str) -> Result {
if !is_user_db_init(user_id) {
- let _ = self.open_user_db(user_id);
+ let _ = self.open_user_db(user_id)?;
+ set_user_db_init(true, user_id);
}
let db_map = DB_MAP.read().map_err(|e| {
@@ -73,7 +76,7 @@ impl UserDB {
match db_map.get(user_id) {
None => Err(ErrorBuilder::new(UserErrorCode::DatabaseInitFailed)
- .msg("Database is not initialization")
+ .msg("Get connection failed. The database is not initialization")
.build()),
Some(database) => Ok(database.get_connection()?),
}
@@ -86,10 +89,8 @@ lazy_static! {
static INIT_FLAG_MAP: Lazy>> = Lazy::new(|| Mutex::new(HashMap::new()));
fn set_user_db_init(is_init: bool, user_id: &str) {
- INIT_FLAG_MAP
- .lock()
- .entry(user_id.to_owned())
- .or_insert_with(|| is_init);
+ let mut flag_map = INIT_FLAG_MAP.lock();
+ flag_map.insert(user_id.to_owned(), is_init);
}
fn is_user_db_init(user_id: &str) -> bool {
diff --git a/rust-lib/flowy-user/src/services/user_session/user_session.rs b/rust-lib/flowy-user/src/services/user_session/user_session.rs
index 07b4898f8a..18f4621e59 100644
--- a/rust-lib/flowy-user/src/services/user_session/user_session.rs
+++ b/rust-lib/flowy-user/src/services/user_session/user_session.rs
@@ -34,6 +34,7 @@ pub struct UserSession {
database: UserDB,
config: UserSessionConfig,
server: Arc,
+ user_id: RwLock