348 lines
12 KiB
Rust
Raw Normal View History

mod deps_resolve;
2021-06-30 23:11:27 +08:00
pub mod module;
pub use flowy_net::get_client_server_configuration;
2022-01-10 23:45:59 +08:00
use crate::deps_resolve::*;
2022-10-22 21:57:44 +08:00
2023-01-30 11:11:19 +08:00
use flowy_client_ws::{listen_on_websocket, FlowyWebSocketConnect, NetworkType};
use flowy_database::manager::DatabaseManager;
2022-10-22 21:57:44 +08:00
use flowy_document::entities::DocumentVersionPB;
use flowy_document::{DocumentConfig, DocumentManager};
2022-10-22 21:57:44 +08:00
use flowy_folder::entities::ViewDataFormatPB;
use flowy_folder::{errors::FlowyError, manager::FolderManager};
2023-01-30 11:11:19 +08:00
use flowy_net::local_server::LocalServer;
use flowy_net::ClientServerConfiguration;
use flowy_task::{TaskDispatcher, TaskRunner};
2022-01-11 13:34:45 +08:00
use flowy_user::services::{notifier::UserStatus, UserSession, UserSessionConfig};
use lib_dispatch::prelude::*;
2022-06-27 23:15:43 +08:00
use lib_dispatch::runtime::tokio_default_runtime;
use module::make_plugins;
pub use module::*;
use std::time::Duration;
2022-01-07 17:37:11 +08:00
use std::{
fmt,
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
2021-09-04 15:12:53 +08:00
};
use tokio::sync::{broadcast, RwLock};
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-05 13:50:23 +08:00
2022-01-07 17:37:11 +08:00
#[derive(Clone)]
2021-09-05 13:50:23 +08:00
pub struct FlowySDKConfig {
feat: Customize the storage folder path (#1538) * feat: support customize folder path * feat: add l10n and optimize the logic * chore: code refactor * feat: add file read/write permission for macOS * fix: add toast for restoring path * feat: fetch apps and show them * feat: fetch apps and show them * feat: implement select document logic * feat: l10n and add select item callback * feat: add space between tile * chore: move file exporter to settings * chore: update UI * feat: support customizing folder when launching the app * feat: auto register after customizing folder * feat: l10n * feat: l10n * chore: reinitialize flowy sdk when calling init_sdk * chore: remove flowysdk const keyword to make sure it can be rebuild * chore: clear kv values when user logout * chore: replace current workspace id key in kv.db * feat: add config.name as a part of seesion_cache_key * feat: support open folder when launching * chore: fix some bugs * chore: dart fix & flutter analyze * chore: wrap 'sign up with ramdom user' as interface * feat: dismiss settings view after changing the folder * fix: read kv value after initializaing with new path * chore: remove user_id prefix from current workspace key * fix: move open latest view action to bloc * test: add test utils for integration tests * chore: move integration_test to its parent directory * test: add integration_test ci * test: switch to B from A, then switch to A again * chore: fix warings and format code and fix tests * chore: remove comment out codes * chore: rename some properties name and optimize the logic * chore: abstract logic of settings file exporter widget to cubit * chore: abstract location customizer view from file system view * chore: abstract settings page index to enum type * chore: remove the redundant underscore * test: fix integration test error * chore: enable integration test for windows and ubuntu * feat: abstract file picker as service and mock it under integration test * chore: fix bloc test Co-authored-by: nathan <nathan@appflowy.io>
2022-12-20 11:14:42 +08:00
/// Different `FlowySDK` instance should have different name
2021-11-09 17:50:32 +08:00
name: String,
feat: Customize the storage folder path (#1538) * feat: support customize folder path * feat: add l10n and optimize the logic * chore: code refactor * feat: add file read/write permission for macOS * fix: add toast for restoring path * feat: fetch apps and show them * feat: fetch apps and show them * feat: implement select document logic * feat: l10n and add select item callback * feat: add space between tile * chore: move file exporter to settings * chore: update UI * feat: support customizing folder when launching the app * feat: auto register after customizing folder * feat: l10n * feat: l10n * chore: reinitialize flowy sdk when calling init_sdk * chore: remove flowysdk const keyword to make sure it can be rebuild * chore: clear kv values when user logout * chore: replace current workspace id key in kv.db * feat: add config.name as a part of seesion_cache_key * feat: support open folder when launching * chore: fix some bugs * chore: dart fix & flutter analyze * chore: wrap 'sign up with ramdom user' as interface * feat: dismiss settings view after changing the folder * fix: read kv value after initializaing with new path * chore: remove user_id prefix from current workspace key * fix: move open latest view action to bloc * test: add test utils for integration tests * chore: move integration_test to its parent directory * test: add integration_test ci * test: switch to B from A, then switch to A again * chore: fix warings and format code and fix tests * chore: remove comment out codes * chore: rename some properties name and optimize the logic * chore: abstract logic of settings file exporter widget to cubit * chore: abstract location customizer view from file system view * chore: abstract settings page index to enum type * chore: remove the redundant underscore * test: fix integration test error * chore: enable integration test for windows and ubuntu * feat: abstract file picker as service and mock it under integration test * chore: fix bloc test Co-authored-by: nathan <nathan@appflowy.io>
2022-12-20 11:14:42 +08:00
/// Panics if the `root` path is not existing
2021-09-05 13:50:23 +08:00
root: String,
log_filter: String,
2021-12-05 16:39:41 +08:00
server_config: ClientServerConfiguration,
2022-10-22 21:57:44 +08:00
pub document: DocumentConfig,
2022-01-07 17:37:11 +08:00
}
impl fmt::Debug for FlowySDKConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("FlowySDKConfig")
.field("root", &self.root)
.field("server-config", &self.server_config)
2022-10-22 21:57:44 +08:00
.field("document-config", &self.document)
2022-01-07 17:37:11 +08:00
.finish()
}
2021-09-05 13:50:23 +08:00
}
impl FlowySDKConfig {
feat: Customize the storage folder path (#1538) * feat: support customize folder path * feat: add l10n and optimize the logic * chore: code refactor * feat: add file read/write permission for macOS * fix: add toast for restoring path * feat: fetch apps and show them * feat: fetch apps and show them * feat: implement select document logic * feat: l10n and add select item callback * feat: add space between tile * chore: move file exporter to settings * chore: update UI * feat: support customizing folder when launching the app * feat: auto register after customizing folder * feat: l10n * feat: l10n * chore: reinitialize flowy sdk when calling init_sdk * chore: remove flowysdk const keyword to make sure it can be rebuild * chore: clear kv values when user logout * chore: replace current workspace id key in kv.db * feat: add config.name as a part of seesion_cache_key * feat: support open folder when launching * chore: fix some bugs * chore: dart fix & flutter analyze * chore: wrap 'sign up with ramdom user' as interface * feat: dismiss settings view after changing the folder * fix: read kv value after initializaing with new path * chore: remove user_id prefix from current workspace key * fix: move open latest view action to bloc * test: add test utils for integration tests * chore: move integration_test to its parent directory * test: add integration_test ci * test: switch to B from A, then switch to A again * chore: fix warings and format code and fix tests * chore: remove comment out codes * chore: rename some properties name and optimize the logic * chore: abstract logic of settings file exporter widget to cubit * chore: abstract location customizer view from file system view * chore: abstract settings page index to enum type * chore: remove the redundant underscore * test: fix integration test error * chore: enable integration test for windows and ubuntu * feat: abstract file picker as service and mock it under integration test * chore: fix bloc test Co-authored-by: nathan <nathan@appflowy.io>
2022-12-20 11:14:42 +08:00
pub fn new(root: &str, name: String, server_config: ClientServerConfiguration) -> Self {
2021-09-05 13:50:23 +08:00
FlowySDKConfig {
feat: Customize the storage folder path (#1538) * feat: support customize folder path * feat: add l10n and optimize the logic * chore: code refactor * feat: add file read/write permission for macOS * fix: add toast for restoring path * feat: fetch apps and show them * feat: fetch apps and show them * feat: implement select document logic * feat: l10n and add select item callback * feat: add space between tile * chore: move file exporter to settings * chore: update UI * feat: support customizing folder when launching the app * feat: auto register after customizing folder * feat: l10n * feat: l10n * chore: reinitialize flowy sdk when calling init_sdk * chore: remove flowysdk const keyword to make sure it can be rebuild * chore: clear kv values when user logout * chore: replace current workspace id key in kv.db * feat: add config.name as a part of seesion_cache_key * feat: support open folder when launching * chore: fix some bugs * chore: dart fix & flutter analyze * chore: wrap 'sign up with ramdom user' as interface * feat: dismiss settings view after changing the folder * fix: read kv value after initializaing with new path * chore: remove user_id prefix from current workspace key * fix: move open latest view action to bloc * test: add test utils for integration tests * chore: move integration_test to its parent directory * test: add integration_test ci * test: switch to B from A, then switch to A again * chore: fix warings and format code and fix tests * chore: remove comment out codes * chore: rename some properties name and optimize the logic * chore: abstract logic of settings file exporter widget to cubit * chore: abstract location customizer view from file system view * chore: abstract settings page index to enum type * chore: remove the redundant underscore * test: fix integration test error * chore: enable integration test for windows and ubuntu * feat: abstract file picker as service and mock it under integration test * chore: fix bloc test Co-authored-by: nathan <nathan@appflowy.io>
2022-12-20 11:14:42 +08:00
name,
2021-09-05 13:50:23 +08:00
root: root.to_owned(),
log_filter: create_log_filter("info".to_owned(), vec![]),
2021-09-27 23:23:23 +08:00
server_config,
2022-10-22 21:57:44 +08:00
document: DocumentConfig::default(),
2021-09-05 13:50:23 +08:00
}
}
2022-10-22 21:57:44 +08:00
pub fn with_document_version(mut self, version: DocumentVersionPB) -> Self {
self.document.version = version;
self
}
pub fn log_filter(mut self, level: &str, with_crates: Vec<String>) -> Self {
self.log_filter = create_log_filter(level.to_owned(), with_crates);
2021-09-05 13:50:23 +08:00
self
}
}
fn create_log_filter(level: String, with_crates: Vec<String>) -> String {
2022-01-09 15:13:45 +08:00
let level = std::env::var("RUST_LOG").unwrap_or(level);
let mut filters = with_crates
.into_iter()
.map(|crate_name| format!("{}={}", crate_name, level))
.collect::<Vec<String>>();
filters.push(format!("flowy_core={}", level));
filters.push(format!("flowy_folder={}", level));
2021-09-07 17:12:03 +08:00
filters.push(format!("flowy_user={}", level));
2022-10-13 23:29:37 +08:00
filters.push(format!("flowy_document={}", level));
2022-03-06 11:28:24 +08:00
filters.push(format!("flowy_grid={}", level));
2022-04-12 11:13:35 +08:00
filters.push(format!("flowy_collaboration={}", "info"));
filters.push(format!("flowy_notification={}", level));
2021-11-19 13:13:50 +08:00
filters.push(format!("lib_ot={}", level));
filters.push(format!("lib_ws={}", level));
filters.push(format!("lib_infra={}", level));
filters.push(format!("flowy_sync={}", level));
filters.push(format!("flowy_revision={}", level));
filters.push(format!("flowy_revision_persistence={}", level));
filters.push(format!("flowy_task={}", level));
2022-04-27 07:58:40 +08:00
// filters.push(format!("lib_dispatch={}", level));
2022-02-07 15:51:19 +08:00
filters.push(format!("dart_ffi={}", "info"));
filters.push(format!("flowy_sqlite={}", "info"));
2022-02-07 15:51:19 +08:00
filters.push(format!("flowy_net={}", "info"));
2021-09-07 17:12:03 +08:00
filters.join(",")
}
2021-09-04 15:12:53 +08:00
#[derive(Clone)]
pub struct FlowySDK {
2021-11-23 17:45:18 +08:00
#[allow(dead_code)]
2022-10-22 21:57:44 +08:00
pub config: FlowySDKConfig,
2021-09-27 23:23:23 +08:00
pub user_session: Arc<UserSession>,
pub document_manager: Arc<DocumentManager>,
2022-01-22 18:48:43 +08:00
pub folder_manager: Arc<FolderManager>,
pub grid_manager: Arc<DatabaseManager>,
pub event_dispatcher: Arc<AFPluginDispatcher>,
2022-01-07 17:37:11 +08:00
pub ws_conn: Arc<FlowyWebSocketConnect>,
2022-01-13 10:53:30 +08:00
pub local_server: Option<Arc<LocalServer>>,
pub task_dispatcher: Arc<RwLock<TaskDispatcher>>,
}
2021-06-28 23:58:43 +08:00
impl FlowySDK {
2021-09-05 13:50:23 +08:00
pub fn new(config: FlowySDKConfig) -> Self {
init_log(&config);
init_kv(&config.root);
tracing::debug!("🔥 {:?}", config);
2022-01-23 22:33:47 +08:00
let runtime = tokio_default_runtime().unwrap();
let task_scheduler = TaskDispatcher::new(Duration::from_secs(2));
let task_dispatcher = Arc::new(RwLock::new(task_scheduler));
runtime.spawn(TaskRunner::run(task_dispatcher.clone()));
2022-01-24 16:27:40 +08:00
let (local_server, ws_conn) = mk_local_server(&config.server_config);
2022-10-22 21:57:44 +08:00
let (user_session, document_manager, folder_manager, local_server, grid_manager) = runtime.block_on(async {
2022-01-24 16:27:40 +08:00
let user_session = mk_user_session(&config, &local_server, &config.server_config);
let document_manager = DocumentDepsResolver::resolve(
2022-01-24 16:27:40 +08:00
local_server.clone(),
ws_conn.clone(),
user_session.clone(),
&config.server_config,
2022-10-22 21:57:44 +08:00
&config.document,
2022-01-24 16:27:40 +08:00
);
2021-11-08 23:15:29 +08:00
let grid_manager =
GridDepsResolver::resolve(ws_conn.clone(), user_session.clone(), task_dispatcher.clone()).await;
2022-03-05 22:30:42 +08:00
2022-01-24 16:27:40 +08:00
let folder_manager = FolderDepsResolver::resolve(
local_server.clone(),
user_session.clone(),
&config.server_config,
2022-03-05 22:30:42 +08:00
&ws_conn,
&document_manager,
2022-03-05 22:30:42 +08:00
&grid_manager,
2022-01-24 16:27:40 +08:00
)
.await;
2021-12-04 23:54:14 +08:00
2022-01-24 16:27:40 +08:00
if let Some(local_server) = local_server.as_ref() {
local_server.run();
}
ws_conn.init().await;
2022-03-10 17:14:10 +08:00
(
user_session,
document_manager,
2022-03-10 17:14:10 +08:00
folder_manager,
local_server,
grid_manager,
)
2022-01-24 16:27:40 +08:00
});
2021-12-04 23:54:14 +08:00
let event_dispatcher = Arc::new(AFPluginDispatcher::construct(runtime, || {
make_plugins(
2022-03-10 17:14:10 +08:00
&ws_conn,
&folder_manager,
&grid_manager,
&user_session,
2022-10-22 21:57:44 +08:00
&document_manager,
2022-03-10 17:14:10 +08:00
)
2022-01-23 22:33:47 +08:00
}));
2022-01-24 16:27:40 +08:00
2022-10-22 21:57:44 +08:00
_start_listening(
&config,
&event_dispatcher,
2022-10-22 21:57:44 +08:00
&ws_conn,
&user_session,
&document_manager,
&folder_manager,
&grid_manager,
);
2021-11-08 23:15:29 +08:00
2021-09-27 23:23:23 +08:00
Self {
config,
user_session,
2022-10-22 21:57:44 +08:00
document_manager,
2022-01-22 18:48:43 +08:00
folder_manager,
2022-03-04 22:09:16 +08:00
grid_manager,
event_dispatcher,
2022-01-07 17:37:11 +08:00
ws_conn,
2022-01-13 10:53:30 +08:00
local_server,
task_dispatcher,
2021-09-27 23:23:23 +08:00
}
2021-09-04 15:12:53 +08:00
}
pub fn dispatcher(&self) -> Arc<AFPluginDispatcher> {
self.event_dispatcher.clone()
2022-01-23 12:14:00 +08:00
}
2021-09-04 15:12:53 +08:00
}
2021-07-17 10:26:05 +08:00
2022-01-24 16:27:40 +08:00
fn _start_listening(
2022-10-22 21:57:44 +08:00
config: &FlowySDKConfig,
event_dispatcher: &AFPluginDispatcher,
2022-01-07 17:37:11 +08:00
ws_conn: &Arc<FlowyWebSocketConnect>,
user_session: &Arc<UserSession>,
2022-10-22 21:57:44 +08:00
document_manager: &Arc<DocumentManager>,
2022-01-14 20:52:03 +08:00
folder_manager: &Arc<FolderManager>,
grid_manager: &Arc<DatabaseManager>,
2021-12-14 15:31:44 +08:00
) {
let subscribe_user_status = user_session.notifier.subscribe_user_status();
2022-01-07 17:37:11 +08:00
let subscribe_network_type = ws_conn.subscribe_network_ty();
2022-01-14 20:52:03 +08:00
let folder_manager = folder_manager.clone();
2022-07-20 18:27:12 +08:00
let grid_manager = grid_manager.clone();
2022-01-14 20:52:03 +08:00
let cloned_folder_manager = folder_manager.clone();
2022-01-07 17:37:11 +08:00
let ws_conn = ws_conn.clone();
2022-01-24 16:27:40 +08:00
let user_session = user_session.clone();
2022-10-22 21:57:44 +08:00
let document_manager = document_manager.clone();
let config = config.clone();
2021-12-05 09:29:42 +08:00
event_dispatcher.spawn(async move {
user_session.init();
2022-01-07 17:37:11 +08:00
listen_on_websocket(ws_conn.clone());
2022-07-20 18:27:12 +08:00
_listen_user_status(
2022-10-22 21:57:44 +08:00
config,
2022-07-20 18:27:12 +08:00
ws_conn.clone(),
subscribe_user_status,
2022-10-22 21:57:44 +08:00
document_manager,
folder_manager,
grid_manager,
2022-07-20 18:27:12 +08:00
)
.await;
2021-12-05 09:29:42 +08:00
});
2021-12-20 12:06:17 +08:00
event_dispatcher.spawn(async move {
2022-01-14 20:52:03 +08:00
_listen_network_status(subscribe_network_type, cloned_folder_manager).await;
});
}
2022-01-24 16:27:40 +08:00
fn mk_local_server(
server_config: &ClientServerConfiguration,
) -> (Option<Arc<LocalServer>>, Arc<FlowyWebSocketConnect>) {
let ws_addr = server_config.ws_addr();
2022-04-14 21:57:00 +08:00
if cfg!(feature = "http_sync") {
2022-01-24 16:27:40 +08:00
let ws_conn = Arc::new(FlowyWebSocketConnect::new(ws_addr));
(None, ws_conn)
} else {
let context = flowy_net::local_server::build_server(server_config);
let local_ws = Arc::new(context.local_ws);
let ws_conn = Arc::new(FlowyWebSocketConnect::from_local(ws_addr, local_ws));
(Some(Arc::new(context.local_server)), ws_conn)
}
}
2021-12-14 15:31:44 +08:00
async fn _listen_user_status(
2022-10-22 21:57:44 +08:00
config: FlowySDKConfig,
2022-01-07 17:37:11 +08:00
ws_conn: Arc<FlowyWebSocketConnect>,
2021-12-14 15:31:44 +08:00
mut subscribe: broadcast::Receiver<UserStatus>,
2022-10-22 21:57:44 +08:00
document_manager: Arc<DocumentManager>,
2022-01-14 20:52:03 +08:00
folder_manager: Arc<FolderManager>,
grid_manager: Arc<DatabaseManager>,
2021-12-14 15:31:44 +08:00
) {
2021-12-04 23:54:14 +08:00
while let Ok(status) = subscribe.recv().await {
let result = || async {
match status {
2022-01-07 23:00:23 +08:00
UserStatus::Login { token, user_id } => {
2022-01-18 22:56:57 +08:00
tracing::trace!("User did login");
folder_manager.initialize(&user_id, &token).await?;
document_manager.initialize(&user_id).await?;
grid_manager.initialize(&user_id, &token).await?;
ws_conn.start(token, user_id).await?;
2022-01-23 12:14:00 +08:00
}
feat: Customize the storage folder path (#1538) * feat: support customize folder path * feat: add l10n and optimize the logic * chore: code refactor * feat: add file read/write permission for macOS * fix: add toast for restoring path * feat: fetch apps and show them * feat: fetch apps and show them * feat: implement select document logic * feat: l10n and add select item callback * feat: add space between tile * chore: move file exporter to settings * chore: update UI * feat: support customizing folder when launching the app * feat: auto register after customizing folder * feat: l10n * feat: l10n * chore: reinitialize flowy sdk when calling init_sdk * chore: remove flowysdk const keyword to make sure it can be rebuild * chore: clear kv values when user logout * chore: replace current workspace id key in kv.db * feat: add config.name as a part of seesion_cache_key * feat: support open folder when launching * chore: fix some bugs * chore: dart fix & flutter analyze * chore: wrap 'sign up with ramdom user' as interface * feat: dismiss settings view after changing the folder * fix: read kv value after initializaing with new path * chore: remove user_id prefix from current workspace key * fix: move open latest view action to bloc * test: add test utils for integration tests * chore: move integration_test to its parent directory * test: add integration_test ci * test: switch to B from A, then switch to A again * chore: fix warings and format code and fix tests * chore: remove comment out codes * chore: rename some properties name and optimize the logic * chore: abstract logic of settings file exporter widget to cubit * chore: abstract location customizer view from file system view * chore: abstract settings page index to enum type * chore: remove the redundant underscore * test: fix integration test error * chore: enable integration test for windows and ubuntu * feat: abstract file picker as service and mock it under integration test * chore: fix bloc test Co-authored-by: nathan <nathan@appflowy.io>
2022-12-20 11:14:42 +08:00
UserStatus::Logout { token: _, user_id } => {
2022-01-18 22:56:57 +08:00
tracing::trace!("User did logout");
feat: Customize the storage folder path (#1538) * feat: support customize folder path * feat: add l10n and optimize the logic * chore: code refactor * feat: add file read/write permission for macOS * fix: add toast for restoring path * feat: fetch apps and show them * feat: fetch apps and show them * feat: implement select document logic * feat: l10n and add select item callback * feat: add space between tile * chore: move file exporter to settings * chore: update UI * feat: support customizing folder when launching the app * feat: auto register after customizing folder * feat: l10n * feat: l10n * chore: reinitialize flowy sdk when calling init_sdk * chore: remove flowysdk const keyword to make sure it can be rebuild * chore: clear kv values when user logout * chore: replace current workspace id key in kv.db * feat: add config.name as a part of seesion_cache_key * feat: support open folder when launching * chore: fix some bugs * chore: dart fix & flutter analyze * chore: wrap 'sign up with ramdom user' as interface * feat: dismiss settings view after changing the folder * fix: read kv value after initializaing with new path * chore: remove user_id prefix from current workspace key * fix: move open latest view action to bloc * test: add test utils for integration tests * chore: move integration_test to its parent directory * test: add integration_test ci * test: switch to B from A, then switch to A again * chore: fix warings and format code and fix tests * chore: remove comment out codes * chore: rename some properties name and optimize the logic * chore: abstract logic of settings file exporter widget to cubit * chore: abstract location customizer view from file system view * chore: abstract settings page index to enum type * chore: remove the redundant underscore * test: fix integration test error * chore: enable integration test for windows and ubuntu * feat: abstract file picker as service and mock it under integration test * chore: fix bloc test Co-authored-by: nathan <nathan@appflowy.io>
2022-12-20 11:14:42 +08:00
folder_manager.clear(&user_id).await;
ws_conn.stop().await;
2022-01-23 12:14:00 +08:00
}
feat: Customize the storage folder path (#1538) * feat: support customize folder path * feat: add l10n and optimize the logic * chore: code refactor * feat: add file read/write permission for macOS * fix: add toast for restoring path * feat: fetch apps and show them * feat: fetch apps and show them * feat: implement select document logic * feat: l10n and add select item callback * feat: add space between tile * chore: move file exporter to settings * chore: update UI * feat: support customizing folder when launching the app * feat: auto register after customizing folder * feat: l10n * feat: l10n * chore: reinitialize flowy sdk when calling init_sdk * chore: remove flowysdk const keyword to make sure it can be rebuild * chore: clear kv values when user logout * chore: replace current workspace id key in kv.db * feat: add config.name as a part of seesion_cache_key * feat: support open folder when launching * chore: fix some bugs * chore: dart fix & flutter analyze * chore: wrap 'sign up with ramdom user' as interface * feat: dismiss settings view after changing the folder * fix: read kv value after initializaing with new path * chore: remove user_id prefix from current workspace key * fix: move open latest view action to bloc * test: add test utils for integration tests * chore: move integration_test to its parent directory * test: add integration_test ci * test: switch to B from A, then switch to A again * chore: fix warings and format code and fix tests * chore: remove comment out codes * chore: rename some properties name and optimize the logic * chore: abstract logic of settings file exporter widget to cubit * chore: abstract location customizer view from file system view * chore: abstract settings page index to enum type * chore: remove the redundant underscore * test: fix integration test error * chore: enable integration test for windows and ubuntu * feat: abstract file picker as service and mock it under integration test * chore: fix bloc test Co-authored-by: nathan <nathan@appflowy.io>
2022-12-20 11:14:42 +08:00
UserStatus::Expired { token: _, user_id } => {
2022-01-18 22:56:57 +08:00
tracing::trace!("User session has been expired");
feat: Customize the storage folder path (#1538) * feat: support customize folder path * feat: add l10n and optimize the logic * chore: code refactor * feat: add file read/write permission for macOS * fix: add toast for restoring path * feat: fetch apps and show them * feat: fetch apps and show them * feat: implement select document logic * feat: l10n and add select item callback * feat: add space between tile * chore: move file exporter to settings * chore: update UI * feat: support customizing folder when launching the app * feat: auto register after customizing folder * feat: l10n * feat: l10n * chore: reinitialize flowy sdk when calling init_sdk * chore: remove flowysdk const keyword to make sure it can be rebuild * chore: clear kv values when user logout * chore: replace current workspace id key in kv.db * feat: add config.name as a part of seesion_cache_key * feat: support open folder when launching * chore: fix some bugs * chore: dart fix & flutter analyze * chore: wrap 'sign up with ramdom user' as interface * feat: dismiss settings view after changing the folder * fix: read kv value after initializaing with new path * chore: remove user_id prefix from current workspace key * fix: move open latest view action to bloc * test: add test utils for integration tests * chore: move integration_test to its parent directory * test: add integration_test ci * test: switch to B from A, then switch to A again * chore: fix warings and format code and fix tests * chore: remove comment out codes * chore: rename some properties name and optimize the logic * chore: abstract logic of settings file exporter widget to cubit * chore: abstract location customizer view from file system view * chore: abstract settings page index to enum type * chore: remove the redundant underscore * test: fix integration test error * chore: enable integration test for windows and ubuntu * feat: abstract file picker as service and mock it under integration test * chore: fix bloc test Co-authored-by: nathan <nathan@appflowy.io>
2022-12-20 11:14:42 +08:00
folder_manager.clear(&user_id).await;
ws_conn.stop().await;
2022-01-23 12:14:00 +08:00
}
2021-12-04 23:54:14 +08:00
UserStatus::SignUp { profile, ret } => {
2022-01-18 22:56:57 +08:00
tracing::trace!("User did sign up");
2022-10-22 21:57:44 +08:00
let view_data_type = match config.document.version {
DocumentVersionPB::V0 => ViewDataFormatPB::DeltaFormat,
DocumentVersionPB::V1 => ViewDataFormatPB::TreeFormat,
};
folder_manager
2022-10-22 21:57:44 +08:00
.initialize_with_new_user(&profile.id, &profile.token, view_data_type)
.await?;
document_manager
.initialize_with_new_user(&profile.id, &profile.token)
.await?;
2022-07-20 18:27:12 +08:00
grid_manager
2022-07-20 18:27:12 +08:00
.initialize_with_new_user(&profile.id, &profile.token)
.await?;
ws_conn.start(profile.token.clone(), profile.id.clone()).await?;
2021-12-04 23:54:14 +08:00
let _ = ret.send(());
2022-01-23 12:14:00 +08:00
}
2021-12-04 23:54:14 +08:00
}
2021-12-14 18:04:51 +08:00
Ok::<(), FlowyError>(())
2021-12-04 23:54:14 +08:00
};
match result().await {
2022-01-23 12:14:00 +08:00
Ok(_) => {}
Err(e) => tracing::error!("{}", e),
2021-12-04 23:54:14 +08:00
}
}
}
2022-01-14 20:52:03 +08:00
async fn _listen_network_status(mut subscribe: broadcast::Receiver<NetworkType>, _core: Arc<FolderManager>) {
2022-01-10 23:45:59 +08:00
while let Ok(_new_type) = subscribe.recv().await {
// core.network_state_changed(new_type);
}
2021-11-08 23:15:29 +08:00
}
2021-09-04 15:12:53 +08:00
fn init_kv(root: &str) {
match flowy_sqlite::kv::KV::init(root) {
2022-01-23 12:14:00 +08:00
Ok(_) => {}
Err(e) => tracing::error!("Init kv store failed: {}", e),
}
2021-09-04 15:12:53 +08:00
}
2021-09-05 13:50:23 +08:00
fn init_log(config: &FlowySDKConfig) {
2021-09-04 15:12:53 +08:00
if !INIT_LOG.load(Ordering::SeqCst) {
INIT_LOG.store(true, Ordering::SeqCst);
2021-08-19 14:08:24 +08:00
let _ = lib_log::Builder::new("AppFlowy-Client", &config.root)
2021-09-05 13:50:23 +08:00
.env_filter(&config.log_filter)
.build();
2021-07-13 13:14:49 +08:00
}
2021-09-04 15:12:53 +08:00
}
2021-10-05 14:37:45 +08:00
2022-01-13 10:53:30 +08:00
fn mk_user_session(
config: &FlowySDKConfig,
local_server: &Option<Arc<LocalServer>>,
2021-12-14 15:31:44 +08:00
server_config: &ClientServerConfiguration,
2022-01-13 10:53:30 +08:00
) -> Arc<UserSession> {
feat: Customize the storage folder path (#1538) * feat: support customize folder path * feat: add l10n and optimize the logic * chore: code refactor * feat: add file read/write permission for macOS * fix: add toast for restoring path * feat: fetch apps and show them * feat: fetch apps and show them * feat: implement select document logic * feat: l10n and add select item callback * feat: add space between tile * chore: move file exporter to settings * chore: update UI * feat: support customizing folder when launching the app * feat: auto register after customizing folder * feat: l10n * feat: l10n * chore: reinitialize flowy sdk when calling init_sdk * chore: remove flowysdk const keyword to make sure it can be rebuild * chore: clear kv values when user logout * chore: replace current workspace id key in kv.db * feat: add config.name as a part of seesion_cache_key * feat: support open folder when launching * chore: fix some bugs * chore: dart fix & flutter analyze * chore: wrap 'sign up with ramdom user' as interface * feat: dismiss settings view after changing the folder * fix: read kv value after initializaing with new path * chore: remove user_id prefix from current workspace key * fix: move open latest view action to bloc * test: add test utils for integration tests * chore: move integration_test to its parent directory * test: add integration_test ci * test: switch to B from A, then switch to A again * chore: fix warings and format code and fix tests * chore: remove comment out codes * chore: rename some properties name and optimize the logic * chore: abstract logic of settings file exporter widget to cubit * chore: abstract location customizer view from file system view * chore: abstract settings page index to enum type * chore: remove the redundant underscore * test: fix integration test error * chore: enable integration test for windows and ubuntu * feat: abstract file picker as service and mock it under integration test * chore: fix bloc test Co-authored-by: nathan <nathan@appflowy.io>
2022-12-20 11:14:42 +08:00
let user_config = UserSessionConfig::new(&config.name, &config.root);
2022-01-13 10:53:30 +08:00
let cloud_service = UserDepsResolver::resolve(local_server, server_config);
2022-01-10 23:45:59 +08:00
Arc::new(UserSession::new(user_config, cloud_service))
2021-12-14 15:31:44 +08:00
}