chore: listen backend notification from Tauri (#1743)

This commit is contained in:
Nathan.fooo
2023-01-27 17:17:51 +08:00
committed by GitHub
parent 243a781b6c
commit 7a750e5255
27 changed files with 237 additions and 58 deletions

View File

@ -5,7 +5,7 @@ use crate::{
entities::workspace::RepeatedWorkspacePB,
errors::FlowyResult,
event_map::{FolderCouldServiceV1, WorkspaceDatabase, WorkspaceUser},
notification::{send_dart_notification, FolderNotification},
notification::{send_notification, FolderNotification},
services::{
folder_editor::FolderEditor, persistence::FolderPersistence, set_current_workspace, AppController,
TrashController, ViewController, WorkspaceController,
@ -249,7 +249,7 @@ impl DefaultFolderBuilder {
let repeated_workspace = RepeatedWorkspacePB {
items: vec![workspace_rev.into()],
};
send_dart_notification(token, FolderNotification::UserCreateWorkspace)
send_notification(token, FolderNotification::UserCreateWorkspace)
.payload(repeated_workspace)
.send();
Ok(())

View File

@ -33,11 +33,11 @@ impl std::convert::From<FolderNotification> for i32 {
}
#[tracing::instrument(level = "trace")]
pub(crate) fn send_dart_notification(id: &str, ty: FolderNotification) -> NotificationBuilder {
pub(crate) fn send_notification(id: &str, ty: FolderNotification) -> NotificationBuilder {
NotificationBuilder::new(id, ty, OBSERVABLE_CATEGORY)
}
#[tracing::instrument(level = "trace")]
pub(crate) fn send_anonymous_dart_notification(ty: FolderNotification) -> NotificationBuilder {
pub(crate) fn send_anonymous_notification(ty: FolderNotification) -> NotificationBuilder {
NotificationBuilder::new("", ty, OBSERVABLE_CATEGORY)
}

View File

@ -91,7 +91,7 @@ impl AppController {
})
.await?
.into();
send_dart_notification(&app_id, FolderNotification::AppUpdated)
send_notification(&app_id, FolderNotification::AppUpdated)
.payload(app)
.send();
self.update_app_on_server(params)?;
@ -163,7 +163,7 @@ impl AppController {
{
Ok(_) => {
let app: AppPB = app_rev.into();
send_dart_notification(&app.id, FolderNotification::AppUpdated)
send_notification(&app.id, FolderNotification::AppUpdated)
.payload(app)
.send();
}
@ -248,7 +248,7 @@ fn notify_apps_changed<'a>(
.map(|app_rev| app_rev.into())
.collect();
let repeated_app = RepeatedAppPB { items };
send_dart_notification(workspace_id, FolderNotification::WorkspaceAppsChanged)
send_notification(workspace_id, FolderNotification::WorkspaceAppsChanged)
.payload(repeated_app)
.send();
Ok(())

View File

@ -2,7 +2,7 @@ use crate::{
entities::trash::{RepeatedTrashIdPB, RepeatedTrashPB, TrashIdPB, TrashPB, TrashType},
errors::{FlowyError, FlowyResult},
event_map::{FolderCouldServiceV1, WorkspaceUser},
notification::{send_anonymous_dart_notification, FolderNotification},
notification::{send_anonymous_notification, FolderNotification},
services::persistence::{FolderPersistence, FolderPersistenceTransaction},
};
@ -283,7 +283,7 @@ impl TrashController {
fn notify_trash_changed<T: Into<RepeatedTrashPB>>(repeated_trash: T) {
let repeated_trash = repeated_trash.into();
tracing::Span::current().record("n_trash", repeated_trash.len());
send_anonymous_dart_notification(FolderNotification::TrashUpdated)
send_anonymous_notification(FolderNotification::TrashUpdated)
.payload(repeated_trash)
.send();
}

View File

@ -8,7 +8,7 @@ use crate::{
},
errors::{FlowyError, FlowyResult},
event_map::{FolderCouldServiceV1, WorkspaceUser},
notification::{send_dart_notification, FolderNotification},
notification::{send_notification, FolderNotification},
services::{
persistence::{FolderPersistence, FolderPersistenceTransaction, ViewChangeset},
TrashController, TrashEvent,
@ -225,7 +225,7 @@ impl ViewController {
})
.await?;
send_dart_notification(&view_id, FolderNotification::ViewMoveToTrash)
send_notification(&view_id, FolderNotification::ViewMoveToTrash)
.payload(deleted_view)
.send();
@ -291,7 +291,7 @@ impl ViewController {
transaction.update_view(changeset)?;
let view_rev = transaction.read_view(&view_id)?;
let view: ViewPB = view_rev.clone().into();
send_dart_notification(&view_id, FolderNotification::ViewUpdated)
send_notification(&view_id, FolderNotification::ViewUpdated)
.payload(view)
.send();
notify_views_changed(&view_rev.app_id, self.trash_controller.clone(), &transaction)?;
@ -356,7 +356,7 @@ impl ViewController {
{
Ok(_) => {
let view: ViewPB = view_rev.into();
send_dart_notification(&view.id, FolderNotification::ViewUpdated)
send_notification(&view.id, FolderNotification::ViewUpdated)
.payload(view)
.send();
}
@ -518,7 +518,7 @@ fn read_local_views_with_transaction<'a>(
}
fn notify_dart(view: ViewPB, notification: FolderNotification) {
send_dart_notification(&view.id, notification).payload(view).send();
send_notification(&view.id, notification).payload(view).send();
}
#[tracing::instrument(
@ -537,7 +537,7 @@ fn notify_views_changed<'a>(
app_rev.belongings.retain(|view| !trash_ids.contains(&view.id));
let app: AppPB = app_rev.into();
send_dart_notification(belong_to_id, FolderNotification::AppUpdated)
send_notification(belong_to_id, FolderNotification::AppUpdated)
.payload(app)
.send();

View File

@ -53,7 +53,7 @@ impl WorkspaceController {
.map(|workspace_rev| workspace_rev.into())
.collect();
let repeated_workspace = RepeatedWorkspacePB { items: workspaces };
send_dart_notification(&token, FolderNotification::UserCreateWorkspace)
send_notification(&token, FolderNotification::UserCreateWorkspace)
.payload(repeated_workspace)
.send();
set_current_workspace(&user_id, &workspace.id);
@ -73,7 +73,7 @@ impl WorkspaceController {
})
.await?;
send_dart_notification(&workspace_id, FolderNotification::WorkspaceUpdated)
send_notification(&workspace_id, FolderNotification::WorkspaceUpdated)
.payload(workspace)
.send();
self.update_workspace_on_server(params)?;
@ -92,7 +92,7 @@ impl WorkspaceController {
self.read_local_workspaces(None, &user_id, &transaction)
})
.await?;
send_dart_notification(&token, FolderNotification::UserDeleteWorkspace)
send_notification(&token, FolderNotification::UserDeleteWorkspace)
.payload(repeated_workspace)
.send();
self.delete_workspace_on_server(workspace_id)?;
@ -236,7 +236,7 @@ pub async fn notify_workspace_setting_did_change(
})
.await?;
send_dart_notification(&token, FolderNotification::WorkspaceSetting)
send_notification(&token, FolderNotification::WorkspaceSetting)
.payload(workspace_setting)
.send();
Ok(())

View File

@ -6,7 +6,7 @@ use crate::entities::{
use crate::{
errors::FlowyError,
manager::FolderManager,
notification::{send_dart_notification, FolderNotification},
notification::{send_notification, FolderNotification},
services::{get_current_workspace, read_local_workspace_apps, WorkspaceController},
};
use lib_dispatch::prelude::{data_result, AFPluginData, AFPluginState, DataResult};
@ -151,7 +151,7 @@ fn read_workspaces_on_server(
.collect(),
};
send_dart_notification(&token, FolderNotification::WorkspaceListUpdated)
send_notification(&token, FolderNotification::WorkspaceListUpdated)
.payload(repeated_workspace)
.send();
Result::<(), FlowyError>::Ok(())