mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
Refactor/dart notification (#1740)
* refactor: notification send * refactor: rename dart-notify to flowy-notification * ci: fix clippy wanrings * ci: fix rust code converage
This commit is contained in:
parent
67f07463f0
commit
347245aaa1
4
frontend/.vscode/tasks.json
vendored
4
frontend/.vscode/tasks.json
vendored
@ -166,9 +166,9 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "AF: Dart Clean",
|
||||
"label": "AF: Flutter Clean",
|
||||
"type": "shell",
|
||||
"command": "cargo make dart_clean",
|
||||
"command": "cargo make flutter_clean",
|
||||
"group": "build",
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
|
@ -1,9 +1,9 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
import 'package:appflowy_backend/protobuf/dart-notify/protobuf.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-notification/protobuf.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/dart_notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/notification.pb.dart';
|
||||
import 'package:appflowy_backend/rust_stream.dart';
|
||||
|
||||
import 'notification_helper.dart';
|
||||
|
@ -1,9 +1,9 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
import 'package:appflowy_backend/protobuf/dart-notify/protobuf.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-notification/protobuf.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/dart_notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/notification.pb.dart';
|
||||
import 'package:appflowy_backend/rust_stream.dart';
|
||||
|
||||
import 'notification_helper.dart';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import 'dart:typed_data';
|
||||
import 'package:appflowy_backend/protobuf/dart-notify/protobuf.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-notification/protobuf.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
|
||||
class NotificationParser<T, E> {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
import 'package:appflowy_backend/protobuf/dart-notify/protobuf.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-notification/protobuf.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
|
@ -3,7 +3,7 @@ import 'dart:typed_data';
|
||||
import 'package:app_flowy/core/grid_notification.dart';
|
||||
import 'package:flowy_infra/notifier.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/dart_notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/notification.pb.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/group.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/group_changeset.pb.dart';
|
||||
|
@ -3,7 +3,7 @@ import 'dart:typed_data';
|
||||
import 'package:app_flowy/core/grid_notification.dart';
|
||||
import 'package:flowy_infra/notifier.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/dart_notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/group.pb.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/group_changeset.pb.dart';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:app_flowy/core/grid_notification.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/dart_notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/notification.pb.dart';
|
||||
import 'package:flowy_infra/notifier.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:app_flowy/core/grid_notification.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/dart_notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/notification.pb.dart';
|
||||
import 'package:flowy_infra/notifier.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:app_flowy/core/grid_notification.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/dart_notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/notification.pb.dart';
|
||||
import 'package:flowy_infra/notifier.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
@ -3,7 +3,7 @@ import 'dart:typed_data';
|
||||
import 'package:app_flowy/core/grid_notification.dart';
|
||||
import 'package:flowy_infra/notifier.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/dart_notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/filter_changeset.pb.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/util.pb.dart';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:app_flowy/core/grid_notification.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/dart_notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/notification.pb.dart';
|
||||
import 'package:flowy_infra/notifier.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
@ -4,7 +4,7 @@ import 'package:app_flowy/core/grid_notification.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flowy_infra/notifier.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/dart_notification.pbserver.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/setting_entities.pb.dart';
|
||||
|
||||
typedef UpdateSettingNotifiedValue = Either<GridSettingPB, FlowyError>;
|
||||
|
@ -4,7 +4,7 @@ import 'package:app_flowy/core/grid_notification.dart';
|
||||
import 'package:flowy_infra/notifier.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/dart_notification.pbenum.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/sort_entities.pb.dart';
|
||||
|
||||
typedef SortNotifiedValue = Either<SortChangesetNotificationPB, FlowyError>;
|
||||
|
@ -5,7 +5,7 @@ import 'package:appflowy_backend/protobuf/flowy-grid/sort_entities.pb.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flowy_infra/notifier.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/dart_notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-grid/view_entities.pb.dart';
|
||||
|
||||
typedef GridRowsVisibilityNotifierValue
|
||||
|
@ -2,8 +2,8 @@ import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
import 'package:app_flowy/core/folder_notification.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:appflowy_backend/protobuf/dart-notify/subject.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/dart_notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-notification/subject.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/trash.pb.dart';
|
||||
import 'package:appflowy_backend/rust_stream.dart';
|
||||
|
@ -7,10 +7,10 @@ import 'package:appflowy_backend/protobuf/flowy-folder/workspace.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'dart:typed_data';
|
||||
import 'package:flowy_infra/notifier.dart';
|
||||
import 'package:appflowy_backend/protobuf/dart-notify/protobuf.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/dart_notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-notification/protobuf.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-user/dart_notification.pb.dart'
|
||||
import 'package:appflowy_backend/protobuf/flowy-user/notification.pb.dart'
|
||||
as user;
|
||||
import 'package:appflowy_backend/rust_stream.dart';
|
||||
|
||||
|
@ -3,11 +3,11 @@ import 'dart:typed_data';
|
||||
import 'package:app_flowy/core/folder_notification.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:appflowy_backend/log.dart';
|
||||
import 'package:appflowy_backend/protobuf/dart-notify/subject.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-notification/subject.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/app.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/dart_notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/notification.pb.dart';
|
||||
import 'package:appflowy_backend/rust_stream.dart';
|
||||
|
||||
typedef AppDidUpdateCallback = void Function(AppPB app);
|
||||
|
@ -2,10 +2,10 @@ import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
import 'package:app_flowy/core/folder_notification.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:appflowy_backend/protobuf/dart-notify/subject.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-notification/subject.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/dart_notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/notification.pb.dart';
|
||||
import 'package:appflowy_backend/rust_stream.dart';
|
||||
import 'package:flowy_infra/notifier.dart';
|
||||
|
||||
|
@ -8,7 +8,7 @@ import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/app.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/workspace.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/dart_notification.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/notification.pb.dart';
|
||||
|
||||
typedef AppListNotifyValue = Either<List<AppPB>, FlowyError>;
|
||||
typedef WorkspaceNotifyValue = Either<WorkspacePB, FlowyError>;
|
||||
|
@ -3,7 +3,7 @@ import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ffi';
|
||||
import 'package:appflowy_backend/log.dart';
|
||||
import 'protobuf/dart-notify/subject.pb.dart';
|
||||
import 'protobuf/flowy-notification/subject.pb.dart';
|
||||
|
||||
typedef ObserverCallback = void Function(SubscribeObject observable);
|
||||
|
||||
|
@ -1431,4 +1431,4 @@ packages:
|
||||
version: "3.1.1"
|
||||
sdks:
|
||||
dart: ">=2.18.0 <3.0.0"
|
||||
flutter: ">=3.3.0"
|
||||
flutter: ">=3.3.0"
|
||||
|
38
frontend/appflowy_tauri/src-tauri/Cargo.lock
generated
38
frontend/appflowy_tauri/src-tauri/Cargo.lock
generated
@ -92,6 +92,7 @@ version = "0.0.0"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"flowy-core",
|
||||
"flowy-notification",
|
||||
"lib-dispatch",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@ -871,20 +872,6 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dart-notify"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"allo-isolate",
|
||||
"bytes",
|
||||
"flowy-codegen",
|
||||
"flowy-derive",
|
||||
"lazy_static",
|
||||
"lib-dispatch",
|
||||
"log",
|
||||
"protobuf",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dashmap"
|
||||
version = "5.4.0"
|
||||
@ -1245,7 +1232,6 @@ dependencies = [
|
||||
"async-stream",
|
||||
"bytes",
|
||||
"chrono",
|
||||
"dart-notify",
|
||||
"dashmap",
|
||||
"diesel",
|
||||
"diesel_derives",
|
||||
@ -1254,6 +1240,7 @@ dependencies = [
|
||||
"flowy-derive",
|
||||
"flowy-error",
|
||||
"flowy-http-model",
|
||||
"flowy-notification",
|
||||
"flowy-revision",
|
||||
"flowy-revision-persistence",
|
||||
"flowy-sync",
|
||||
@ -1300,7 +1287,6 @@ name = "flowy-folder"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"dart-notify",
|
||||
"diesel",
|
||||
"diesel_derives",
|
||||
"flowy-codegen",
|
||||
@ -1309,6 +1295,7 @@ dependencies = [
|
||||
"flowy-document",
|
||||
"flowy-error",
|
||||
"flowy-http-model",
|
||||
"flowy-notification",
|
||||
"flowy-revision",
|
||||
"flowy-revision-persistence",
|
||||
"flowy-sync",
|
||||
@ -1341,7 +1328,6 @@ dependencies = [
|
||||
"bytes",
|
||||
"chrono",
|
||||
"crossbeam-utils",
|
||||
"dart-notify",
|
||||
"dashmap",
|
||||
"diesel",
|
||||
"fancy-regex",
|
||||
@ -1350,6 +1336,7 @@ dependencies = [
|
||||
"flowy-derive",
|
||||
"flowy-error",
|
||||
"flowy-http-model",
|
||||
"flowy-notification",
|
||||
"flowy-revision",
|
||||
"flowy-revision-persistence",
|
||||
"flowy-sync",
|
||||
@ -1428,6 +1415,21 @@ dependencies = [
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flowy-notification"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"allo-isolate",
|
||||
"bytes",
|
||||
"flowy-codegen",
|
||||
"flowy-derive",
|
||||
"lazy_static",
|
||||
"lib-dispatch",
|
||||
"protobuf",
|
||||
"serde",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flowy-revision"
|
||||
version = "0.1.0"
|
||||
@ -1502,7 +1504,6 @@ name = "flowy-user"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"dart-notify",
|
||||
"diesel",
|
||||
"diesel_derives",
|
||||
"fancy-regex",
|
||||
@ -1510,6 +1511,7 @@ dependencies = [
|
||||
"flowy-database",
|
||||
"flowy-derive",
|
||||
"flowy-error",
|
||||
"flowy-notification",
|
||||
"lazy_static",
|
||||
"lib-dispatch",
|
||||
"lib-infra",
|
||||
|
@ -21,6 +21,7 @@ bytes = { version = "1.0" }
|
||||
tracing = { version = "0.1", features = ["log"] }
|
||||
lib-dispatch = { path = "../../rust-lib/lib-dispatch", features = ["use_serde"] }
|
||||
flowy-core = { path = "../../rust-lib/flowy-core", features = ["rev-sqlite","ts"] }
|
||||
flowy-notification = { path = "../../rust-lib/flowy-notification", features = ["ts"] }
|
||||
|
||||
[features]
|
||||
# by default Tauri runs in production mode
|
||||
|
@ -1,15 +0,0 @@
|
||||
use serde::Serialize;
|
||||
use tauri::{AppHandle, Event, Manager, Wry};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub const AF_EVENT: &str = "af-event";
|
||||
#[allow(dead_code)]
|
||||
pub const AF_NOTIFICATION: &str = "af-notification";
|
||||
|
||||
#[tracing::instrument(level = "trace")]
|
||||
pub fn on_event(app_handler: AppHandle<Wry>, event: Event) {}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn send_notification<P: Serialize + Clone>(app_handler: AppHandle<Wry>, payload: P) {
|
||||
app_handler.emit_all(AF_NOTIFICATION, payload).unwrap();
|
||||
}
|
@ -3,12 +3,13 @@
|
||||
windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
mod event;
|
||||
mod init;
|
||||
mod notification;
|
||||
mod request;
|
||||
|
||||
use event::*;
|
||||
use flowy_notification::register_notification_sender;
|
||||
use init::*;
|
||||
use notification::*;
|
||||
use request::*;
|
||||
use tauri::Manager;
|
||||
|
||||
@ -21,6 +22,7 @@ fn main() {
|
||||
.on_menu_event(|_menu| {})
|
||||
.on_page_load(|window, _payload| {
|
||||
let app_handler = window.app_handle();
|
||||
register_notification_sender(TSNotificationSender::new(app_handler.clone()));
|
||||
// tauri::async_runtime::spawn(async move {});
|
||||
window.listen_global(AF_EVENT, move |event| {
|
||||
on_event(app_handler.clone(), event);
|
||||
|
35
frontend/appflowy_tauri/src-tauri/src/notification.rs
Normal file
35
frontend/appflowy_tauri/src-tauri/src/notification.rs
Normal file
@ -0,0 +1,35 @@
|
||||
use flowy_notification::entities::SubscribeObject;
|
||||
use flowy_notification::NotificationSender;
|
||||
use serde::Serialize;
|
||||
use tauri::{AppHandle, Event, Manager, Wry};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub const AF_EVENT: &str = "af-event";
|
||||
#[allow(dead_code)]
|
||||
pub const AF_NOTIFICATION: &str = "af-notification";
|
||||
|
||||
#[tracing::instrument(level = "trace")]
|
||||
pub fn on_event(app_handler: AppHandle<Wry>, event: Event) {}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn send_notification<P: Serialize + Clone>(app_handler: AppHandle<Wry>, payload: P) {
|
||||
app_handler.emit_all(AF_NOTIFICATION, payload).unwrap();
|
||||
}
|
||||
|
||||
pub struct TSNotificationSender {
|
||||
handler: AppHandle<Wry>,
|
||||
}
|
||||
|
||||
impl TSNotificationSender {
|
||||
pub fn new(handler: AppHandle<Wry>) -> Self {
|
||||
Self { handler }
|
||||
}
|
||||
}
|
||||
|
||||
impl NotificationSender for TSNotificationSender {
|
||||
fn send_subject(&self, subject: SubscribeObject) -> Result<(), String> {
|
||||
self.handler
|
||||
.emit_all(AF_NOTIFICATION, subject)
|
||||
.map_err(|e| format!("{:?}", e))
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ import "./App.css";
|
||||
import {
|
||||
UserEventSignIn,
|
||||
SignInPayloadPB,
|
||||
} from "../services/backend/events/flowy-user";
|
||||
} from "../services/backend/events/flowy-user/index";
|
||||
import { nanoid } from "nanoid";
|
||||
|
||||
|
||||
|
39
frontend/rust-lib/Cargo.lock
generated
39
frontend/rust-lib/Cargo.lock
generated
@ -719,11 +719,11 @@ dependencies = [
|
||||
"byteorder",
|
||||
"bytes",
|
||||
"crossbeam-utils",
|
||||
"dart-notify",
|
||||
"ffi-support",
|
||||
"flowy-codegen",
|
||||
"flowy-core",
|
||||
"flowy-derive",
|
||||
"flowy-notification",
|
||||
"lazy_static",
|
||||
"lib-dispatch",
|
||||
"log",
|
||||
@ -734,20 +734,6 @@ dependencies = [
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dart-notify"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"allo-isolate",
|
||||
"bytes",
|
||||
"flowy-codegen",
|
||||
"flowy-derive",
|
||||
"lazy_static",
|
||||
"lib-dispatch",
|
||||
"log",
|
||||
"protobuf",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dashmap"
|
||||
version = "5.2.0"
|
||||
@ -1056,7 +1042,6 @@ dependencies = [
|
||||
"chrono",
|
||||
"color-eyre",
|
||||
"criterion",
|
||||
"dart-notify",
|
||||
"dashmap",
|
||||
"derive_more",
|
||||
"diesel",
|
||||
@ -1067,6 +1052,7 @@ dependencies = [
|
||||
"flowy-document",
|
||||
"flowy-error",
|
||||
"flowy-http-model",
|
||||
"flowy-notification",
|
||||
"flowy-revision",
|
||||
"flowy-revision-persistence",
|
||||
"flowy-sync",
|
||||
@ -1116,7 +1102,6 @@ name = "flowy-folder"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"dart-notify",
|
||||
"diesel",
|
||||
"diesel_derives",
|
||||
"flowy-codegen",
|
||||
@ -1126,6 +1111,7 @@ dependencies = [
|
||||
"flowy-error",
|
||||
"flowy-folder",
|
||||
"flowy-http-model",
|
||||
"flowy-notification",
|
||||
"flowy-revision",
|
||||
"flowy-revision-persistence",
|
||||
"flowy-sync",
|
||||
@ -1159,7 +1145,6 @@ dependencies = [
|
||||
"bytes",
|
||||
"chrono",
|
||||
"crossbeam-utils",
|
||||
"dart-notify",
|
||||
"dashmap",
|
||||
"diesel",
|
||||
"fancy-regex",
|
||||
@ -1169,6 +1154,7 @@ dependencies = [
|
||||
"flowy-error",
|
||||
"flowy-grid",
|
||||
"flowy-http-model",
|
||||
"flowy-notification",
|
||||
"flowy-revision",
|
||||
"flowy-revision-persistence",
|
||||
"flowy-sync",
|
||||
@ -1248,6 +1234,21 @@ dependencies = [
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flowy-notification"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"allo-isolate",
|
||||
"bytes",
|
||||
"flowy-codegen",
|
||||
"flowy-derive",
|
||||
"lazy_static",
|
||||
"lib-dispatch",
|
||||
"protobuf",
|
||||
"serde",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flowy-revision"
|
||||
version = "0.1.0"
|
||||
@ -1360,7 +1361,6 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"claim 0.4.0",
|
||||
"dart-notify",
|
||||
"diesel",
|
||||
"diesel_derives",
|
||||
"fake",
|
||||
@ -1369,6 +1369,7 @@ dependencies = [
|
||||
"flowy-database",
|
||||
"flowy-derive",
|
||||
"flowy-error",
|
||||
"flowy-notification",
|
||||
"flowy-test",
|
||||
"futures",
|
||||
"lazy_static",
|
||||
|
@ -9,7 +9,7 @@ members = [
|
||||
"flowy-test",
|
||||
"flowy-database",
|
||||
"flowy-folder",
|
||||
"dart-notify",
|
||||
"flowy-notification",
|
||||
"flowy-document",
|
||||
"flowy-error",
|
||||
"flowy-revision",
|
||||
|
@ -27,7 +27,7 @@ parking_lot = "0.12.1"
|
||||
|
||||
lib-dispatch = { path = "../lib-dispatch" }
|
||||
flowy-core = { path = "../flowy-core" }
|
||||
dart-notify = { path = "../dart-notify" }
|
||||
flowy-notification = { path = "../flowy-notification" }
|
||||
flowy-derive = { path = "../flowy-derive" }
|
||||
|
||||
[features]
|
||||
|
@ -1,15 +1,18 @@
|
||||
#![allow(clippy::not_unsafe_ptr_arg_deref)]
|
||||
mod c;
|
||||
mod model;
|
||||
mod notification;
|
||||
mod protobuf;
|
||||
mod util;
|
||||
|
||||
use crate::notification::DartNotificationSender;
|
||||
use crate::{
|
||||
c::{extend_front_four_bytes_into_bytes, forget_rust},
|
||||
model::{FFIRequest, FFIResponse},
|
||||
};
|
||||
use flowy_core::get_client_server_configuration;
|
||||
use flowy_core::*;
|
||||
use flowy_notification::register_notification_sender;
|
||||
use lazy_static::lazy_static;
|
||||
use lib_dispatch::prelude::ToBytes;
|
||||
use lib_dispatch::prelude::*;
|
||||
@ -78,7 +81,7 @@ pub extern "C" fn sync_event(input: *const u8, len: usize) -> *const u8 {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn set_stream_port(port: i64) -> i32 {
|
||||
dart_notify::dart::DartStreamSender::set_port(port);
|
||||
register_notification_sender(DartNotificationSender::new(port));
|
||||
0
|
||||
}
|
||||
|
||||
|
3
frontend/rust-lib/dart-ffi/src/notification/mod.rs
Normal file
3
frontend/rust-lib/dart-ffi/src/notification/mod.rs
Normal file
@ -0,0 +1,3 @@
|
||||
mod sender;
|
||||
|
||||
pub use sender::*;
|
25
frontend/rust-lib/dart-ffi/src/notification/sender.rs
Normal file
25
frontend/rust-lib/dart-ffi/src/notification/sender.rs
Normal file
@ -0,0 +1,25 @@
|
||||
use allo_isolate::Isolate;
|
||||
use bytes::Bytes;
|
||||
use flowy_notification::entities::SubscribeObject;
|
||||
use flowy_notification::NotificationSender;
|
||||
use std::convert::TryInto;
|
||||
|
||||
pub struct DartNotificationSender {
|
||||
isolate: Isolate,
|
||||
}
|
||||
|
||||
impl DartNotificationSender {
|
||||
pub fn new(port: i64) -> Self {
|
||||
Self {
|
||||
isolate: Isolate::new(port),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NotificationSender for DartNotificationSender {
|
||||
fn send_subject(&self, subject: SubscribeObject) -> Result<(), String> {
|
||||
let bytes: Bytes = subject.try_into().unwrap();
|
||||
self.isolate.post(bytes.to_vec());
|
||||
Ok(())
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
mod stream_sender;
|
||||
|
||||
pub use stream_sender::*;
|
@ -1,57 +0,0 @@
|
||||
use crate::entities::SubscribeObject;
|
||||
use bytes::Bytes;
|
||||
use lazy_static::lazy_static;
|
||||
use std::{convert::TryInto, sync::RwLock};
|
||||
|
||||
lazy_static! {
|
||||
static ref DART_STREAM_SENDER: RwLock<DartStreamSender> = RwLock::new(DartStreamSender::new());
|
||||
}
|
||||
|
||||
pub struct DartStreamSender {
|
||||
#[allow(dead_code)]
|
||||
isolate: Option<allo_isolate::Isolate>,
|
||||
}
|
||||
|
||||
impl DartStreamSender {
|
||||
fn new() -> Self {
|
||||
Self { isolate: None }
|
||||
}
|
||||
|
||||
fn inner_set_port(&mut self, port: i64) {
|
||||
log::info!("Setup rust to flutter stream with port {}", port);
|
||||
self.isolate = Some(allo_isolate::Isolate::new(port));
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn inner_post(&self, observable_subject: SubscribeObject) -> Result<(), String> {
|
||||
match self.isolate {
|
||||
Some(ref isolate) => {
|
||||
let bytes: Bytes = observable_subject.try_into().unwrap();
|
||||
isolate.post(bytes.to_vec());
|
||||
Ok(())
|
||||
}
|
||||
None => Err("Isolate is not set".to_owned()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_port(port: i64) {
|
||||
match DART_STREAM_SENDER.write() {
|
||||
Ok(mut stream) => stream.inner_set_port(port),
|
||||
Err(e) => {
|
||||
let msg = format!("Get rust to flutter stream lock fail. {:?}", e);
|
||||
log::error!("{:?}", msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn post(_observable_subject: SubscribeObject) -> Result<(), String> {
|
||||
#[cfg(feature = "dart")]
|
||||
match DART_STREAM_SENDER.read() {
|
||||
Ok(stream) => stream.inner_post(_observable_subject),
|
||||
Err(e) => Err(format!("Get rust to flutter stream lock fail. {:?}", e)),
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "dart"))]
|
||||
Ok(())
|
||||
}
|
||||
}
|
@ -88,7 +88,7 @@ fn create_log_filter(level: String, with_crates: Vec<String>) -> String {
|
||||
filters.push(format!("flowy_document={}", level));
|
||||
filters.push(format!("flowy_grid={}", level));
|
||||
filters.push(format!("flowy_collaboration={}", "info"));
|
||||
filters.push(format!("dart_notify={}", level));
|
||||
filters.push(format!("flowy_notification={}", level));
|
||||
filters.push(format!("lib_ot={}", level));
|
||||
filters.push(format!("lib_ws={}", level));
|
||||
filters.push(format!("lib_infra={}", level));
|
||||
|
@ -19,7 +19,7 @@ flowy-database = { path = "../flowy-database", optional = true }
|
||||
flowy-revision = { path = "../flowy-revision" }
|
||||
flowy-revision-persistence = { path = "../flowy-revision-persistence" }
|
||||
flowy-error = { path = "../flowy-error", features = ["collaboration", "ot", "http_server", "serde", "db"] }
|
||||
dart-notify = { path = "../dart-notify" }
|
||||
flowy-notification = { path = "../flowy-notification" }
|
||||
|
||||
diesel = {version = "1.4.8", features = ["sqlite"]}
|
||||
diesel_derives = {version = "1.4.1", features = ["sqlite"]}
|
||||
@ -61,5 +61,5 @@ sync = []
|
||||
cloud_sync = ["sync"]
|
||||
rev-sqlite = ["flowy-database"]
|
||||
flowy_unit_test = ["lib-ot/flowy_unit_test", "flowy-revision/flowy_unit_test"]
|
||||
dart = ["flowy-codegen/dart", "dart-notify/dart"]
|
||||
ts = ["flowy-codegen/ts"]
|
||||
dart = ["flowy-codegen/dart", "flowy-notification/dart"]
|
||||
ts = ["flowy-codegen/ts", "flowy-notification/ts"]
|
||||
|
@ -127,14 +127,14 @@ impl DocumentManager {
|
||||
document_id: T,
|
||||
) -> Result<Arc<dyn DocumentEditor>, FlowyError> {
|
||||
let document_id = document_id.as_ref();
|
||||
tracing::Span::current().record("document_id", &document_id);
|
||||
tracing::Span::current().record("document_id", document_id);
|
||||
self.init_document_editor(document_id).await
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(self, editor_id), fields(editor_id), err)]
|
||||
pub async fn close_document_editor<T: AsRef<str>>(&self, editor_id: T) -> Result<(), FlowyError> {
|
||||
let editor_id = editor_id.as_ref();
|
||||
tracing::Span::current().record("editor_id", &editor_id);
|
||||
tracing::Span::current().record("editor_id", editor_id);
|
||||
self.editor_map.write().await.remove(editor_id).await;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ lib-infra = { path = "../../../shared-lib/lib-infra" }
|
||||
flowy-document = { path = "../flowy-document" }
|
||||
flowy-database = { path = "../flowy-database", optional = true }
|
||||
flowy-error = { path = "../flowy-error", features = ["db", "http_server"]}
|
||||
dart-notify = { path = "../dart-notify" }
|
||||
flowy-notification = { path = "../flowy-notification" }
|
||||
lib-dispatch = { path = "../lib-dispatch" }
|
||||
flowy-revision = { path = "../flowy-revision" }
|
||||
flowy-revision-persistence = { path = "../flowy-revision-persistence" }
|
||||
@ -52,5 +52,5 @@ sync = []
|
||||
cloud_sync = ["sync"]
|
||||
rev-sqlite = ["flowy-database", "flowy-folder/rev-sqlite"]
|
||||
flowy_unit_test = ["lib-ot/flowy_unit_test", "flowy-revision/flowy_unit_test"]
|
||||
dart = ["flowy-codegen/dart", "dart-notify/dart"]
|
||||
ts = ["flowy-codegen/ts"]
|
||||
dart = ["flowy-codegen/dart", "flowy-notification/dart"]
|
||||
ts = ["flowy-codegen/ts", "flowy-notification/ts"]
|
||||
|
@ -1,3 +1,3 @@
|
||||
# Check out the FlowyConfig (located in flowy_toml.rs) for more details.
|
||||
proto_input = ["src/entities", "src/event_map.rs", "src/dart_notification.rs"]
|
||||
proto_input = ["src/entities", "src/event_map.rs", "src/notification.rs"]
|
||||
event_files = ["src/event_map.rs"]
|
@ -8,8 +8,8 @@ mod macros;
|
||||
#[macro_use]
|
||||
extern crate flowy_database;
|
||||
|
||||
mod dart_notification;
|
||||
pub mod manager;
|
||||
mod notification;
|
||||
pub mod protobuf;
|
||||
mod util;
|
||||
|
||||
|
@ -2,10 +2,10 @@ use crate::entities::view::ViewDataFormatPB;
|
||||
use crate::entities::{ViewLayoutTypePB, ViewPB};
|
||||
use crate::services::folder_editor::FolderRevisionMergeable;
|
||||
use crate::{
|
||||
dart_notification::{send_dart_notification, FolderNotification},
|
||||
entities::workspace::RepeatedWorkspacePB,
|
||||
errors::FlowyResult,
|
||||
event_map::{FolderCouldServiceV1, WorkspaceDatabase, WorkspaceUser},
|
||||
notification::{send_dart_notification, FolderNotification},
|
||||
services::{
|
||||
folder_editor::FolderEditor, persistence::FolderPersistence, set_current_workspace, AppController,
|
||||
TrashController, ViewController, WorkspaceController,
|
||||
|
@ -1,5 +1,5 @@
|
||||
use dart_notify::DartNotifyBuilder;
|
||||
use flowy_derive::ProtoBuf_Enum;
|
||||
use flowy_notification::NotificationBuilder;
|
||||
const OBSERVABLE_CATEGORY: &str = "Workspace";
|
||||
|
||||
#[derive(ProtoBuf_Enum, Debug)]
|
||||
@ -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) -> DartNotifyBuilder {
|
||||
DartNotifyBuilder::new(id, ty, OBSERVABLE_CATEGORY)
|
||||
pub(crate) fn send_dart_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) -> DartNotifyBuilder {
|
||||
DartNotifyBuilder::new("", ty, OBSERVABLE_CATEGORY)
|
||||
pub(crate) fn send_anonymous_dart_notification(ty: FolderNotification) -> NotificationBuilder {
|
||||
NotificationBuilder::new("", ty, OBSERVABLE_CATEGORY)
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
use crate::{
|
||||
dart_notification::*,
|
||||
entities::{
|
||||
app::{AppPB, CreateAppParams, *},
|
||||
trash::TrashType,
|
||||
},
|
||||
errors::*,
|
||||
event_map::{FolderCouldServiceV1, WorkspaceUser},
|
||||
notification::*,
|
||||
services::{
|
||||
persistence::{AppChangeset, FolderPersistence, FolderPersistenceTransaction},
|
||||
TrashController, TrashEvent,
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::{
|
||||
dart_notification::{send_anonymous_dart_notification, FolderNotification},
|
||||
entities::trash::{RepeatedTrashIdPB, RepeatedTrashPB, TrashIdPB, TrashPB, TrashType},
|
||||
errors::{FlowyError, FlowyResult},
|
||||
event_map::{FolderCouldServiceV1, WorkspaceUser},
|
||||
notification::{send_anonymous_dart_notification, FolderNotification},
|
||||
services::persistence::{FolderPersistence, FolderPersistenceTransaction},
|
||||
};
|
||||
|
||||
@ -59,7 +59,7 @@ impl TrashController {
|
||||
delete_all: false,
|
||||
})?;
|
||||
|
||||
tracing::Span::current().record("putback", &format!("{:?}", &identifier).as_str());
|
||||
tracing::Span::current().record("putback", format!("{:?}", &identifier).as_str());
|
||||
let _ = self.notify.send(TrashEvent::Putback(vec![identifier].into(), tx));
|
||||
rx.recv().await.unwrap()?;
|
||||
Ok(())
|
||||
@ -118,7 +118,7 @@ impl TrashController {
|
||||
#[tracing::instrument(level = "debug", skip(self), fields(delete_trash_ids), err)]
|
||||
pub async fn delete_with_identifiers(&self, trash_identifiers: RepeatedTrashIdPB) -> FlowyResult<()> {
|
||||
let (tx, mut rx) = mpsc::channel::<FlowyResult<()>>(1);
|
||||
tracing::Span::current().record("delete_trash_ids", &format!("{}", trash_identifiers).as_str());
|
||||
tracing::Span::current().record("delete_trash_ids", format!("{}", trash_identifiers).as_str());
|
||||
let _ = self.notify.send(TrashEvent::Delete(trash_identifiers.clone(), tx));
|
||||
|
||||
match rx.recv().await {
|
||||
@ -156,7 +156,7 @@ impl TrashController {
|
||||
|
||||
tracing::Span::current().record(
|
||||
"trash_ids",
|
||||
&format!(
|
||||
format!(
|
||||
"{:?}",
|
||||
identifiers
|
||||
.iter()
|
||||
@ -282,7 +282,7 @@ impl TrashController {
|
||||
#[tracing::instrument(level = "debug", skip(repeated_trash), fields(n_trash))]
|
||||
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());
|
||||
tracing::Span::current().record("n_trash", repeated_trash.len());
|
||||
send_anonymous_dart_notification(FolderNotification::TrashUpdated)
|
||||
.payload(repeated_trash)
|
||||
.send();
|
||||
|
@ -2,13 +2,13 @@ pub use crate::entities::view::ViewDataFormatPB;
|
||||
use crate::entities::{AppPB, DeletedViewPB, ViewInfoPB, ViewLayoutTypePB};
|
||||
use crate::manager::{ViewDataProcessor, ViewDataProcessorMap};
|
||||
use crate::{
|
||||
dart_notification::{send_dart_notification, FolderNotification},
|
||||
entities::{
|
||||
trash::{RepeatedTrashIdPB, TrashType},
|
||||
view::{CreateViewParams, RepeatedViewPB, UpdateViewParams, ViewIdPB, ViewPB},
|
||||
},
|
||||
errors::{FlowyError, FlowyResult},
|
||||
event_map::{FolderCouldServiceV1, WorkspaceUser},
|
||||
notification::{send_dart_notification, FolderNotification},
|
||||
services::{
|
||||
persistence::{FolderPersistence, FolderPersistenceTransaction, ViewChangeset},
|
||||
TrashController, TrashEvent,
|
||||
|
@ -1,9 +1,9 @@
|
||||
use crate::entities::workspace::*;
|
||||
use crate::manager::FolderManager;
|
||||
use crate::{
|
||||
dart_notification::*,
|
||||
errors::*,
|
||||
event_map::{FolderCouldServiceV1, WorkspaceUser},
|
||||
notification::*,
|
||||
services::{
|
||||
persistence::{FolderPersistence, FolderPersistenceTransaction, WorkspaceChangeset},
|
||||
read_local_workspace_apps, TrashController,
|
||||
|
@ -4,9 +4,9 @@ use crate::entities::{
|
||||
workspace::{RepeatedWorkspacePB, WorkspaceIdPB, WorkspaceSettingPB, *},
|
||||
};
|
||||
use crate::{
|
||||
dart_notification::{send_dart_notification, FolderNotification},
|
||||
errors::FlowyError,
|
||||
manager::FolderManager,
|
||||
notification::{send_dart_notification, FolderNotification},
|
||||
services::{get_current_workspace, read_local_workspace_apps, WorkspaceController},
|
||||
};
|
||||
use lib_dispatch::prelude::{data_result, AFPluginData, AFPluginState, DataResult};
|
||||
|
@ -7,7 +7,7 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
lib-dispatch = { path = "../lib-dispatch" }
|
||||
dart-notify = { path = "../dart-notify" }
|
||||
flowy-notification = { path = "../flowy-notification" }
|
||||
flowy-revision = { path = "../flowy-revision" }
|
||||
flowy-revision-persistence = { path = "../flowy-revision-persistence" }
|
||||
flowy-task= { path = "../flowy-task" }
|
||||
@ -58,6 +58,6 @@ flowy-codegen = { path = "../flowy-codegen"}
|
||||
[features]
|
||||
default = []
|
||||
rev-sqlite = ["flowy-database"]
|
||||
dart = ["flowy-codegen/dart", "dart-notify/dart"]
|
||||
ts = ["flowy-codegen/ts"]
|
||||
dart = ["flowy-codegen/dart", "flowy-notification/dart"]
|
||||
ts = ["flowy-codegen/ts", "flowy-notification/ts"]
|
||||
flowy_unit_test = ["flowy-revision/flowy_unit_test"]
|
@ -3,6 +3,6 @@ proto_input = [
|
||||
"src/event_map.rs",
|
||||
"src/services/field/type_options",
|
||||
"src/entities",
|
||||
"src/dart_notification.rs"
|
||||
"src/notification.rs"
|
||||
]
|
||||
event_files = ["src/event_map.rs"]
|
@ -7,8 +7,8 @@ mod event_handler;
|
||||
pub mod event_map;
|
||||
pub mod manager;
|
||||
|
||||
mod dart_notification;
|
||||
pub mod entities;
|
||||
mod notification;
|
||||
mod protobuf;
|
||||
pub mod services;
|
||||
pub mod util;
|
||||
|
@ -101,7 +101,7 @@ impl GridManager {
|
||||
#[tracing::instrument(level = "debug", skip_all, fields(grid_id), err)]
|
||||
pub async fn close_grid<T: AsRef<str>>(&self, grid_id: T) -> FlowyResult<()> {
|
||||
let grid_id = grid_id.as_ref();
|
||||
tracing::Span::current().record("grid_id", &grid_id);
|
||||
tracing::Span::current().record("grid_id", grid_id);
|
||||
self.grid_editors.write().await.remove(grid_id).await;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use dart_notify::DartNotifyBuilder;
|
||||
use flowy_derive::ProtoBuf_Enum;
|
||||
use flowy_notification::NotificationBuilder;
|
||||
const OBSERVABLE_CATEGORY: &str = "Grid";
|
||||
|
||||
#[derive(ProtoBuf_Enum, Debug)]
|
||||
@ -35,6 +35,6 @@ impl std::convert::From<GridDartNotification> for i32 {
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace")]
|
||||
pub fn send_dart_notification(id: &str, ty: GridDartNotification) -> DartNotifyBuilder {
|
||||
DartNotifyBuilder::new(id, ty, OBSERVABLE_CATEGORY)
|
||||
pub fn send_dart_notification(id: &str, ty: GridDartNotification) -> NotificationBuilder {
|
||||
NotificationBuilder::new(id, ty, OBSERVABLE_CATEGORY)
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
use crate::dart_notification::{send_dart_notification, GridDartNotification};
|
||||
use crate::entities::{CellChangesetPB, InsertedRowPB, UpdatedRowPB};
|
||||
use crate::manager::GridUser;
|
||||
use crate::notification::{send_dart_notification, GridDartNotification};
|
||||
use crate::services::block_editor::{GridBlockRevisionEditor, GridBlockRevisionMergeable};
|
||||
use crate::services::persistence::block_index::BlockIndexCache;
|
||||
use crate::services::persistence::rev_sqlite::{
|
||||
|
@ -133,7 +133,7 @@ mod tests {
|
||||
assert_eq!(native_time_str, utc_time_str);
|
||||
|
||||
// Mon Mar 14 2022 17:56:02 GMT+0800 (China Standard Time)
|
||||
let gmt_8_offset = FixedOffset::east(8 * 3600);
|
||||
let gmt_8_offset = FixedOffset::east_opt(8 * 3600).unwrap();
|
||||
let china_local = chrono::DateTime::<chrono::Local>::from_utc(native, gmt_8_offset);
|
||||
let china_local_time = format!("{}", china_local.format_with_items(StrftimeItems::new(&format)));
|
||||
|
||||
|
@ -183,7 +183,7 @@ impl FilterController {
|
||||
invisible_rows,
|
||||
visible_rows,
|
||||
};
|
||||
tracing::Span::current().record("filter_result", &format!("{:?}", ¬ification).as_str());
|
||||
tracing::Span::current().record("filter_result", format!("{:?}", ¬ification).as_str());
|
||||
let _ = self.notifier.send(GridViewChanged::FilterNotification(notification));
|
||||
}
|
||||
Ok(())
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::dart_notification::{send_dart_notification, GridDartNotification};
|
||||
use crate::entities::CellPathParams;
|
||||
use crate::entities::*;
|
||||
use crate::manager::GridUser;
|
||||
use crate::notification::{send_dart_notification, GridDartNotification};
|
||||
use crate::services::block_manager::GridBlockManager;
|
||||
use crate::services::cell::{
|
||||
apply_cell_data_changeset, decode_type_cell_data, stringify_cell_data, AnyTypeCache, AtomicCellDataCache,
|
||||
|
@ -210,7 +210,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
tracing::Span::current().record("group_result", &format!("{},", self.group_ctx,).as_str());
|
||||
tracing::Span::current().record("group_result", format!("{},", self.group_ctx,).as_str());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ impl GroupGenerator for URLGroupGenerator {
|
||||
let group_name = cell.content.clone();
|
||||
GeneratedGroupConfig {
|
||||
group_rev: GroupRevision::new(group_id, group_name),
|
||||
filter_content: cell.content.clone(),
|
||||
filter_content: cell.content,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::dart_notification::{send_dart_notification, GridDartNotification};
|
||||
use crate::entities::{GridRowsVisibilityChangesetPB, ReorderAllRowsPB, ReorderSingleRowPB};
|
||||
use crate::notification::{send_dart_notification, GridDartNotification};
|
||||
use crate::services::filter::FilterResultNotification;
|
||||
use crate::services::sort::{ReorderAllRowsResult, ReorderSingleRowResult};
|
||||
use async_stream::stream;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::dart_notification::{send_dart_notification, GridDartNotification};
|
||||
use crate::entities::*;
|
||||
use crate::notification::{send_dart_notification, GridDartNotification};
|
||||
use crate::services::block_manager::GridBlockEvent;
|
||||
use crate::services::cell::{AtomicCellDataCache, TypeCellData};
|
||||
use crate::services::field::{RowSingleCellData, TypeOptionCellDataHandler};
|
||||
|
@ -94,9 +94,8 @@ async fn url_cell_date_test() {
|
||||
|
||||
for (i, cell) in cells.into_iter().enumerate() {
|
||||
let url_cell_data = cell.into_url_field_cell_data().unwrap();
|
||||
match i {
|
||||
0 => assert_eq!(url_cell_data.url.as_str(), "https://www.appflowy.io/"),
|
||||
_ => {}
|
||||
if i == 0 {
|
||||
assert_eq!(url_cell_data.url.as_str(), "https://www.appflowy.io/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "dart-notify"
|
||||
name = "flowy-notification"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
@ -9,8 +9,9 @@ edition = "2018"
|
||||
lazy_static = { version = "1.4.0" }
|
||||
protobuf = { version = "2.20.0" }
|
||||
allo-isolate = { version = "^0.1", features = ["catch-unwind"] }
|
||||
log = "0.4.14"
|
||||
tracing = { version = "0.1", features = ["log"] }
|
||||
bytes = { version = "1.0" }
|
||||
serde = "1.0"
|
||||
|
||||
flowy-derive = { path = "../flowy-derive" }
|
||||
lib-dispatch = { path = "../lib-dispatch" }
|
||||
@ -20,3 +21,4 @@ flowy-codegen = { path = "../flowy-codegen" }
|
||||
|
||||
[features]
|
||||
dart = ["flowy-codegen/dart"]
|
||||
ts = ["flowy-codegen/ts"]
|
@ -1,7 +1,7 @@
|
||||
use flowy_derive::ProtoBuf;
|
||||
use std::{fmt, fmt::Formatter};
|
||||
|
||||
#[derive(Debug, Clone, ProtoBuf)]
|
||||
#[derive(Debug, Clone, ProtoBuf, serde::Serialize)]
|
||||
pub struct SubscribeObject {
|
||||
#[pb(index = 1)]
|
||||
pub source: String,
|
@ -1,13 +1,29 @@
|
||||
use bytes::Bytes;
|
||||
|
||||
pub mod dart;
|
||||
pub mod entities;
|
||||
mod protobuf;
|
||||
|
||||
use crate::{dart::DartStreamSender, entities::SubscribeObject};
|
||||
use crate::entities::SubscribeObject;
|
||||
use bytes::Bytes;
|
||||
use lazy_static::lazy_static;
|
||||
use lib_dispatch::prelude::ToBytes;
|
||||
use std::sync::RwLock;
|
||||
|
||||
pub struct DartNotifyBuilder {
|
||||
lazy_static! {
|
||||
static ref NOTIFICATION_SENDER: RwLock<Vec<Box<dyn NotificationSender>>> = RwLock::new(vec![]);
|
||||
}
|
||||
|
||||
pub fn register_notification_sender<T: NotificationSender>(sender: T) {
|
||||
let box_sender = Box::new(sender);
|
||||
match NOTIFICATION_SENDER.write() {
|
||||
Ok(mut write_guard) => write_guard.push(box_sender),
|
||||
Err(err) => tracing::error!("Failed to push notification sender: {:?}", err),
|
||||
}
|
||||
}
|
||||
|
||||
pub trait NotificationSender: Send + Sync + 'static {
|
||||
fn send_subject(&self, subject: SubscribeObject) -> Result<(), String>;
|
||||
}
|
||||
|
||||
pub struct NotificationBuilder {
|
||||
id: String,
|
||||
payload: Option<Bytes>,
|
||||
error: Option<Bytes>,
|
||||
@ -15,7 +31,7 @@ pub struct DartNotifyBuilder {
|
||||
ty: i32,
|
||||
}
|
||||
|
||||
impl DartNotifyBuilder {
|
||||
impl NotificationBuilder {
|
||||
pub fn new<T: Into<i32>>(id: &str, ty: T, source: &str) -> Self {
|
||||
Self {
|
||||
id: id.to_owned(),
|
||||
@ -33,7 +49,7 @@ impl DartNotifyBuilder {
|
||||
match payload.into_bytes() {
|
||||
Ok(bytes) => self.payload = Some(bytes),
|
||||
Err(e) => {
|
||||
log::error!("Set observable payload failed: {:?}", e);
|
||||
tracing::error!("Set observable payload failed: {:?}", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,7 +63,7 @@ impl DartNotifyBuilder {
|
||||
match error.into_bytes() {
|
||||
Ok(bytes) => self.error = Some(bytes),
|
||||
Err(e) => {
|
||||
log::error!("Set observable error failed: {:?}", e);
|
||||
tracing::error!("Set observable error failed: {:?}", e);
|
||||
}
|
||||
}
|
||||
self
|
||||
@ -55,9 +71,7 @@ impl DartNotifyBuilder {
|
||||
|
||||
pub fn send(self) {
|
||||
let payload = self.payload.map(|bytes| bytes.to_vec());
|
||||
|
||||
let error = self.error.map(|bytes| bytes.to_vec());
|
||||
|
||||
let subject = SubscribeObject {
|
||||
source: self.source,
|
||||
ty: self.ty,
|
||||
@ -66,9 +80,15 @@ impl DartNotifyBuilder {
|
||||
error,
|
||||
};
|
||||
|
||||
match DartStreamSender::post(subject) {
|
||||
Ok(_) => {}
|
||||
Err(error) => log::error!("Send observable subject failed: {}", error),
|
||||
match NOTIFICATION_SENDER.read() {
|
||||
Ok(read_guard) => read_guard.iter().for_each(|sender| {
|
||||
if let Err(e) = sender.send_subject(subject.clone()) {
|
||||
tracing::error!("Post notification failed: {}", e);
|
||||
}
|
||||
}),
|
||||
Err(err) => {
|
||||
tracing::error!("Read notification sender failed: {}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -133,10 +133,10 @@ impl<Connection: 'static> RevisionManager<Connection> {
|
||||
B: RevisionObjectDeserializer,
|
||||
{
|
||||
let revision_records = self.rev_persistence.load_all_records(&self.object_id)?;
|
||||
tracing::Span::current().record("object_id", &self.object_id.as_str());
|
||||
tracing::Span::current().record("deserializer", &std::any::type_name::<B>());
|
||||
tracing::Span::current().record("object_id", self.object_id.as_str());
|
||||
tracing::Span::current().record("deserializer", std::any::type_name::<B>());
|
||||
let revisions: Vec<Revision> = revision_records.iter().map(|record| record.revision.clone()).collect();
|
||||
tracing::Span::current().record("deserialize_revisions", &revisions.len());
|
||||
tracing::Span::current().record("deserialize_revisions", revisions.len());
|
||||
let current_rev_id = revisions.last().as_ref().map(|revision| revision.rev_id).unwrap_or(0);
|
||||
match B::deserialize_revisions(&self.object_id, revisions.clone()) {
|
||||
Ok(object) => {
|
||||
|
@ -101,7 +101,7 @@ where
|
||||
/// Save the revision that comes from remote to disk.
|
||||
#[tracing::instrument(level = "trace", skip(self, revision), fields(rev_id, object_id=%self.object_id), err)]
|
||||
pub(crate) async fn add_ack_revision(&self, revision: &Revision) -> FlowyResult<()> {
|
||||
tracing::Span::current().record("rev_id", &revision.rev_id);
|
||||
tracing::Span::current().record("rev_id", revision.rev_id);
|
||||
self.add(revision.clone(), RevisionState::Ack, true).await
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ where
|
||||
debug_assert_eq!(range.len() as usize, revisions.len());
|
||||
// compact multiple revisions into one
|
||||
let merged_revision = rev_compress.merge_revisions(&self.user_id, &self.object_id, revisions)?;
|
||||
tracing::Span::current().record("rev_id", &merged_revision.rev_id);
|
||||
tracing::Span::current().record("rev_id", merged_revision.rev_id);
|
||||
|
||||
let record = SyncRecord {
|
||||
revision: merged_revision,
|
||||
@ -178,7 +178,7 @@ where
|
||||
end: *compact_seq.back().unwrap(),
|
||||
};
|
||||
|
||||
tracing::Span::current().record("compact_range", &format!("{}", range).as_str());
|
||||
tracing::Span::current().record("compact_range", format!("{}", range).as_str());
|
||||
let mut revisions = self.revisions_in_range(&range).await?;
|
||||
debug_assert_eq!(range.len() as usize, revisions.len());
|
||||
// append the new revision
|
||||
@ -187,7 +187,7 @@ where
|
||||
// compact multiple revisions into one
|
||||
let merged_revision = rev_compress.merge_revisions(&self.user_id, &self.object_id, revisions)?;
|
||||
let rev_id = merged_revision.rev_id;
|
||||
tracing::Span::current().record("rev_id", &merged_revision.rev_id);
|
||||
tracing::Span::current().record("rev_id", merged_revision.rev_id);
|
||||
sync_seq.recv(merged_revision.rev_id)?;
|
||||
|
||||
// replace the revisions in range with compact revision
|
||||
@ -195,7 +195,7 @@ where
|
||||
Ok(rev_id)
|
||||
} else {
|
||||
let rev_id = new_revision.rev_id;
|
||||
tracing::Span::current().record("rev_id", &rev_id);
|
||||
tracing::Span::current().record("rev_id", rev_id);
|
||||
self.add(new_revision, RevisionState::Sync, true).await?;
|
||||
sync_seq.merge_recv(rev_id)?;
|
||||
Ok(rev_id)
|
||||
@ -347,7 +347,7 @@ impl<C> RevisionMemoryCacheDelegate for Arc<dyn RevisionDiskCache<C, Error = Flo
|
||||
if !records.is_empty() {
|
||||
tracing::Span::current().record(
|
||||
"checkpoint_result",
|
||||
&format!("{} records were saved", records.len()).as_str(),
|
||||
format!("{} records were saved", records.len()).as_str(),
|
||||
);
|
||||
self.create_revision_records(records)?;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ flowy-database = { path = "../flowy-database", optional = true }
|
||||
flowy-error = { path = "../flowy-error", features = ["db", "http_server"] }
|
||||
|
||||
lib-infra = { path = "../../../shared-lib/lib-infra" }
|
||||
dart-notify = { path = "../dart-notify" }
|
||||
flowy-notification = { path = "../flowy-notification" }
|
||||
lib-dispatch = { path = "../lib-dispatch" }
|
||||
|
||||
tracing = { version = "0.1", features = ["log"] }
|
||||
@ -46,8 +46,8 @@ rand = "0.8.5"
|
||||
|
||||
[features]
|
||||
rev-sqlite = ["flowy-database"]
|
||||
dart = ["flowy-codegen/dart", "dart-notify/dart"]
|
||||
ts = ["flowy-codegen/ts"]
|
||||
dart = ["flowy-codegen/dart", "flowy-notification/dart"]
|
||||
ts = ["flowy-codegen/ts", "flowy-notification/ts"]
|
||||
|
||||
[build-dependencies]
|
||||
flowy-codegen = { path = "../flowy-codegen"}
|
||||
|
@ -1,3 +1,3 @@
|
||||
# Check out the FlowyConfig (located in flowy_toml.rs) for more details.
|
||||
proto_input = ["src/entities", "src/event_map.rs", "src/dart_notification.rs"]
|
||||
proto_input = ["src/entities", "src/event_map.rs", "src/notification.rs"]
|
||||
event_files = ["src/event_map.rs"]
|
@ -1,7 +1,7 @@
|
||||
mod dart_notification;
|
||||
pub mod entities;
|
||||
pub mod event_map;
|
||||
mod handlers;
|
||||
mod notification;
|
||||
pub mod protobuf;
|
||||
pub mod services;
|
||||
// mod sql_tables;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use dart_notify::DartNotifyBuilder;
|
||||
use flowy_derive::ProtoBuf_Enum;
|
||||
use flowy_notification::NotificationBuilder;
|
||||
const OBSERVABLE_CATEGORY: &str = "User";
|
||||
|
||||
#[derive(ProtoBuf_Enum, Debug)]
|
||||
@ -23,6 +23,6 @@ impl std::convert::From<UserNotification> for i32 {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn dart_notify(id: &str, ty: UserNotification) -> DartNotifyBuilder {
|
||||
DartNotifyBuilder::new(id, ty, OBSERVABLE_CATEGORY)
|
||||
pub(crate) fn dart_notify(id: &str, ty: UserNotification) -> NotificationBuilder {
|
||||
NotificationBuilder::new(id, ty, OBSERVABLE_CATEGORY)
|
||||
}
|
@ -2,9 +2,9 @@ use crate::entities::{
|
||||
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB, UserSettingPB,
|
||||
};
|
||||
use crate::{
|
||||
dart_notification::*,
|
||||
errors::{ErrorCode, FlowyError},
|
||||
event_map::UserCloudService,
|
||||
notification::*,
|
||||
services::{
|
||||
database::{UserDB, UserTable, UserTableChangeset},
|
||||
notifier::UserNotifier,
|
||||
|
@ -190,4 +190,24 @@ script = [
|
||||
exec cmd.exe /c flutter packages pub run easy_localization:generate -S assets/translations/ -f keys -o locale_keys.g.dart -S assets/translations -s en.json
|
||||
exec cmd.exe /c flutter packages pub run build_runner build --delete-conflicting-outputs
|
||||
"""
|
||||
]
|
||||
]
|
||||
|
||||
[tasks.dry_code_generation]
|
||||
script_runner = "@shell"
|
||||
script = [
|
||||
"""
|
||||
cd app_flowy
|
||||
flutter packages pub run easy_localization:generate -S assets/translations/ -f keys -o locale_keys.g.dart -S assets/translations -s en.json
|
||||
flutter packages pub run build_runner build --delete-conflicting-outputs
|
||||
"""
|
||||
]
|
||||
|
||||
[tasks.dry_code_generation.windows]
|
||||
script_runner = "@duckscript"
|
||||
script = [
|
||||
"""
|
||||
cd ./app_flowy/
|
||||
exec cmd.exe /c flutter packages pub run easy_localization:generate -S assets/translations/ -f keys -o locale_keys.g.dart -S assets/translations -s en.json
|
||||
exec cmd.exe /c flutter packages pub run build_runner build --delete-conflicting-outputs
|
||||
"""
|
||||
]
|
||||
|
@ -90,7 +90,7 @@ script = [
|
||||
CARGO_INCREMENTAL=0 \
|
||||
RUSTFLAGS='-C instrument-coverage' \
|
||||
LLVM_PROFILE_FILE='prof-%p-%m.profraw' \
|
||||
cargo test --no-default-features --features="sync"
|
||||
cargo test --no-default-features --features="sync,rev-sqlite"
|
||||
"""
|
||||
]
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
[tasks.dart_clean]
|
||||
[tasks.flutter_clean]
|
||||
run_task = { name = [
|
||||
"rust_lib_clean",
|
||||
"rm_macro_build_cache",
|
||||
|
Loading…
Reference in New Issue
Block a user