feat: add hooks for session
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::{
|
||||
api::SessionHook,
|
||||
client::*,
|
||||
flutter_ffi::EventToUI,
|
||||
ui_session_interface::{io_loop, InvokeUiSession, Session},
|
||||
@@ -40,9 +41,9 @@ pub(super) const APP_TYPE_DESKTOP_FILE_TRANSFER: &str = "file transfer";
|
||||
pub(super) const APP_TYPE_DESKTOP_PORT_FORWARD: &str = "port forward";
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref CUR_SESSION_ID: RwLock<String> = Default::default();
|
||||
pub static ref SESSIONS: RwLock<HashMap<String, Session<FlutterHandler>>> = Default::default();
|
||||
pub static ref GLOBAL_EVENT_STREAM: RwLock<HashMap<String, StreamSink<String>>> = Default::default(); // rust to dart event channel
|
||||
pub(crate) static ref CUR_SESSION_ID: RwLock<String> = Default::default();
|
||||
pub(crate) static ref SESSIONS: RwLock<HashMap<String, Session<FlutterHandler>>> = Default::default();
|
||||
pub(crate) static ref GLOBAL_EVENT_STREAM: RwLock<HashMap<String, StreamSink<String>>> = Default::default(); // rust to dart event channel
|
||||
}
|
||||
|
||||
#[cfg(all(target_os = "windows", feature = "flutter_texture_render"))]
|
||||
@@ -146,6 +147,7 @@ pub struct FlutterHandler {
|
||||
notify_rendered: Arc<RwLock<bool>>,
|
||||
renderer: Arc<RwLock<VideoRenderer>>,
|
||||
peer_info: Arc<RwLock<PeerInfo>>,
|
||||
hooks: Arc<RwLock<HashMap<String, SessionHook>>>,
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "flutter_texture_render"))]
|
||||
@@ -157,6 +159,7 @@ pub struct FlutterHandler {
|
||||
pub rgba: Arc<RwLock<Vec<u8>>>,
|
||||
pub rgba_valid: Arc<AtomicBool>,
|
||||
peer_info: Arc<RwLock<PeerInfo>>,
|
||||
hooks: Arc<RwLock<HashMap<String, SessionHook>>>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "flutter_texture_render")]
|
||||
@@ -255,7 +258,7 @@ impl FlutterHandler {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn close_event_stream(&mut self) {
|
||||
pub(crate) fn close_event_stream(&mut self) {
|
||||
let mut stream_lock = self.event_stream.write().unwrap();
|
||||
if let Some(stream) = &*stream_lock {
|
||||
stream.add(EventToUI::Event("close".to_owned()));
|
||||
@@ -277,6 +280,26 @@ impl FlutterHandler {
|
||||
serde_json::ser::to_string(&msg_vec).unwrap_or("".to_owned())
|
||||
}
|
||||
|
||||
pub(crate) fn add_session_hook(&self, key: String, hook: crate::api::SessionHook) -> bool {
|
||||
let mut hooks = self.hooks.write().unwrap();
|
||||
if hooks.contains_key(&key) {
|
||||
// Already has the hook with this key.
|
||||
return false;
|
||||
}
|
||||
let _ = hooks.insert(key, hook);
|
||||
true
|
||||
}
|
||||
|
||||
pub(crate) fn remove_session_hook(&self, key: &String) -> bool {
|
||||
let mut hooks = self.hooks.write().unwrap();
|
||||
if !hooks.contains_key(key) {
|
||||
// The hook with this key does not found.
|
||||
return false;
|
||||
}
|
||||
let _ = hooks.remove(key);
|
||||
true
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(feature = "flutter_texture_render")]
|
||||
pub fn register_texture(&mut self, ptr: usize) {
|
||||
|
||||
Reference in New Issue
Block a user