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:
Nathan.fooo
2023-01-26 15:40:23 +08:00
committed by GitHub
parent 67f07463f0
commit 347245aaa1
80 changed files with 269 additions and 231 deletions

View File

@ -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
}

View File

@ -0,0 +1,3 @@
mod sender;
pub use sender::*;

View 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(())
}
}