opt: fetch rgba positively for sessions on flutter

This commit is contained in:
Kingtous
2023-02-11 09:57:27 +08:00
parent d416d7d965
commit 491932cda1
5 changed files with 31 additions and 3 deletions

View File

@@ -110,6 +110,7 @@ pub unsafe extern "C" fn free_c_args(ptr: *mut *mut c_char, len: c_int) {
#[derive(Default, Clone)]
pub struct FlutterHandler {
pub event_stream: Arc<RwLock<Option<StreamSink<EventToUI>>>>,
pub rgba: Arc<RwLock<Option<Vec<u8>>>>
}
impl FlutterHandler {
@@ -290,7 +291,8 @@ impl InvokeUiSession for FlutterHandler {
fn on_rgba(&self, data: &[u8]) {
if let Some(stream) = &*self.event_stream.read().unwrap() {
stream.add(EventToUI::Rgba(ZeroCopyBuffer(data.to_owned())));
drop(self.rgba.write().unwrap().replace(data.to_owned()));
stream.add(EventToUI::Rgba);
}
}
@@ -409,6 +411,10 @@ impl InvokeUiSession for FlutterHandler {
fn on_voice_call_incoming(&self) {
self.push_event("on_voice_call_incoming", [].into());
}
fn get_rgba(&self) -> Option<Vec<u8>> {
self.rgba.write().unwrap().take()
}
}
/// Create a new remote session with the given id.

View File

@@ -20,6 +20,7 @@ use std::{
os::raw::c_char,
str::FromStr,
};
use crate::ui_session_interface::InvokeUiSession;
// use crate::hbbs_http::account::AuthResult;
@@ -47,7 +48,7 @@ fn initialize(app_dir: &str) {
pub enum EventToUI {
Event(String),
Rgba(ZeroCopyBuffer<Vec<u8>>),
Rgba,
}
pub fn start_global_event_stream(s: StreamSink<String>, app_type: String) -> ResultType<()> {
@@ -103,6 +104,16 @@ pub fn session_get_remember(id: String) -> Option<bool> {
}
}
pub fn session_get_rgba(id: String) -> Option<ZeroCopyBuffer<Vec<u8>>> {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
return match session.get_rgba() {
Some(buf) => Some(ZeroCopyBuffer(buf)),
_ => None
};
}
None
}
pub fn session_get_toggle_option(id: String, arg: String) -> Option<bool> {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
Some(session.get_toggle_option(arg))

View File

@@ -282,6 +282,11 @@ impl InvokeUiSession for SciterHandler {
fn on_voice_call_incoming(&self) {
self.call("onVoiceCallIncoming", &make_args!());
}
/// RGBA is directly rendered by [on_rgba]. No need to store the rgba for the sciter ui.
fn get_rgba(&self) -> Option<Vec<u8>> {
None
}
}
pub struct SciterSession(Session<SciterHandler>);

View File

@@ -722,6 +722,7 @@ pub trait InvokeUiSession: Send + Sync + Clone + 'static + Sized + Default {
fn on_voice_call_closed(&self, reason: &str);
fn on_voice_call_waiting(&self);
fn on_voice_call_incoming(&self);
fn get_rgba(&self) -> Option<Vec<u8>>;
}
impl<T: InvokeUiSession> Deref for Session<T> {