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