2022-08-22 21:50:51 +08:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
use crate::ipc::start_pa;
|
2022-09-05 19:41:09 +08:00
|
|
|
use crate::ui_cm_interface::{start_ipc, ConnectionManager, InvokeUiCM};
|
|
|
|
|
|
|
|
use hbb_common::{allow_err, log};
|
|
|
|
use sciter::{make_args, Element, Value, HELEMENT};
|
|
|
|
use std::sync::Mutex;
|
|
|
|
use std::{ops::Deref, sync::Arc};
|
2021-03-29 15:59:14 +08:00
|
|
|
|
2022-09-05 19:41:09 +08:00
|
|
|
#[derive(Clone, Default)]
|
|
|
|
pub struct SciterHandler {
|
|
|
|
pub element: Arc<Mutex<Option<Element>>>,
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-09-05 19:41:09 +08:00
|
|
|
impl InvokeUiCM for SciterHandler {
|
|
|
|
fn add_connection(&self, client: &crate::ui_cm_interface::Client) {
|
2021-03-29 15:59:14 +08:00
|
|
|
self.call(
|
|
|
|
"addConnection",
|
|
|
|
&make_args!(
|
2022-09-05 19:41:09 +08:00
|
|
|
client.id,
|
|
|
|
client.is_file_transfer,
|
|
|
|
client.port_forward.clone(),
|
|
|
|
client.peer_id.clone(),
|
|
|
|
client.name.clone(),
|
|
|
|
client.authorized,
|
|
|
|
client.keyboard,
|
|
|
|
client.clipboard,
|
|
|
|
client.audio,
|
|
|
|
client.file,
|
2022-09-22 09:55:34 +08:00
|
|
|
client.restart,
|
|
|
|
client.recording
|
2021-03-29 15:59:14 +08:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-08 20:15:02 +08:00
|
|
|
fn remove_connection(&self, id: i32, close: bool) {
|
|
|
|
self.call("removeConnection", &make_args!(id, close));
|
2022-09-05 19:41:09 +08:00
|
|
|
if crate::ui_cm_interface::get_clients_length().eq(&0) {
|
2022-05-10 01:08:21 +08:00
|
|
|
crate::platform::quit_gui();
|
2022-05-02 00:02:41 +08:00
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-09-05 19:41:09 +08:00
|
|
|
fn new_message(&self, id: i32, text: String) {
|
|
|
|
self.call("newMessage", &make_args!(id, text));
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2022-09-07 18:57:49 +08:00
|
|
|
|
2022-09-21 23:32:59 +08:00
|
|
|
fn change_theme(&self, _dark: String) {
|
2022-09-07 18:57:49 +08:00
|
|
|
// TODO
|
|
|
|
}
|
2022-09-08 08:52:56 +08:00
|
|
|
|
|
|
|
fn change_language(&self) {
|
|
|
|
// TODO
|
|
|
|
}
|
2022-09-05 19:41:09 +08:00
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
|
2022-09-05 19:41:09 +08:00
|
|
|
impl SciterHandler {
|
|
|
|
#[inline]
|
|
|
|
fn call(&self, func: &str, args: &[Value]) {
|
|
|
|
if let Some(e) = self.element.lock().unwrap().as_ref() {
|
|
|
|
allow_err!(e.call_method(func, &super::value_crash_workaround(args)[..]));
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
}
|
2022-09-05 19:41:09 +08:00
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
|
2022-09-05 19:41:09 +08:00
|
|
|
pub struct SciterConnectionManager(ConnectionManager<SciterHandler>);
|
|
|
|
|
|
|
|
impl Deref for SciterConnectionManager {
|
|
|
|
type Target = ConnectionManager<SciterHandler>;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.0
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2022-09-05 19:41:09 +08:00
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
|
2022-09-05 19:41:09 +08:00
|
|
|
impl SciterConnectionManager {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
std::thread::spawn(start_pa);
|
|
|
|
let cm = ConnectionManager {
|
|
|
|
ui_handler: SciterHandler::default(),
|
|
|
|
};
|
|
|
|
let cloned = cm.clone();
|
|
|
|
std::thread::spawn(move || start_ipc(cloned));
|
|
|
|
SciterConnectionManager(cm)
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-09-05 19:41:09 +08:00
|
|
|
fn get_icon(&mut self) -> String {
|
|
|
|
crate::get_icon()
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-09-05 19:41:09 +08:00
|
|
|
fn check_click_time(&mut self, id: i32) {
|
|
|
|
crate::ui_cm_interface::check_click_time(id);
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-09-05 19:41:09 +08:00
|
|
|
fn get_click_time(&self) -> f64 {
|
|
|
|
crate::ui_cm_interface::get_click_time() as _
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn switch_permission(&self, id: i32, name: String, enabled: bool) {
|
2022-09-05 19:41:09 +08:00
|
|
|
crate::ui_cm_interface::switch_permission(id, name, enabled);
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn close(&self, id: i32) {
|
2022-09-05 19:41:09 +08:00
|
|
|
crate::ui_cm_interface::close(id);
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-10-08 20:15:02 +08:00
|
|
|
fn remove_disconnected_connection(&self, id: i32) {
|
|
|
|
crate::ui_cm_interface::remove(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn quit(&self) {
|
|
|
|
crate::platform::quit_gui();
|
|
|
|
}
|
|
|
|
|
2022-09-05 19:41:09 +08:00
|
|
|
fn authorize(&self, id: i32) {
|
|
|
|
crate::ui_cm_interface::authorize(id);
|
2022-04-25 12:28:28 +08:00
|
|
|
}
|
|
|
|
|
2022-09-05 19:41:09 +08:00
|
|
|
fn send_msg(&self, id: i32, text: String) {
|
|
|
|
crate::ui_cm_interface::send_chat(id, text);
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 16:45:22 +08:00
|
|
|
fn t(&self, name: String) -> String {
|
|
|
|
crate::client::translate(name)
|
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-09-05 19:41:09 +08:00
|
|
|
impl sciter::EventHandler for SciterConnectionManager {
|
2021-03-29 15:59:14 +08:00
|
|
|
fn attached(&mut self, root: HELEMENT) {
|
2022-09-05 19:41:09 +08:00
|
|
|
*self.ui_handler.element.lock().unwrap() = Some(Element::from(root));
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sciter::dispatch_script_call! {
|
2021-12-25 16:45:22 +08:00
|
|
|
fn t(String);
|
2022-05-12 17:35:25 +08:00
|
|
|
fn check_click_time(i32);
|
|
|
|
fn get_click_time();
|
2021-03-29 15:59:14 +08:00
|
|
|
fn get_icon();
|
|
|
|
fn close(i32);
|
2022-10-08 20:15:02 +08:00
|
|
|
fn remove_disconnected_connection(i32);
|
|
|
|
fn quit();
|
2021-03-29 15:59:14 +08:00
|
|
|
fn authorize(i32);
|
|
|
|
fn switch_permission(i32, String, bool);
|
|
|
|
fn send_msg(i32, String);
|
|
|
|
}
|
|
|
|
}
|