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:
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))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user