From c468b486197d9366817282fd96c63bd81f8e20d7 Mon Sep 17 00:00:00 2001 From: dignow Date: Sun, 25 Jun 2023 13:14:21 +0800 Subject: [PATCH 1/2] fix, sciter, change_id Signed-off-by: dignow --- src/ui.rs | 1 + src/ui_interface.rs | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index 10eab22cb..baa7fef4c 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -542,6 +542,7 @@ impl UI { } fn change_id(&self, id: String) { + reset_async_job_status(); let old_id = self.get_id(); change_id_shared(id, old_id); } diff --git a/src/ui_interface.rs b/src/ui_interface.rs index ec9fcaad1..c42615ed1 100644 --- a/src/ui_interface.rs +++ b/src/ui_interface.rs @@ -64,6 +64,8 @@ lazy_static::lazy_static! { pub static ref SENDER : Mutex> = Mutex::new(check_connect_status(true)); } +const INIT_ASYNC_JOB_STATUS: &str = " "; + #[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))] #[inline] pub fn get_id() -> String { @@ -635,13 +637,23 @@ pub fn get_uuid() -> String { crate::encode64(hbb_common::get_uuid()) } +#[inline] +pub fn get_init_async_job_status() -> String { + INIT_ASYNC_JOB_STATUS.to_string() +} + +#[inline] +pub fn reset_async_job_status() { + *ASYNC_JOB_STATUS.lock().unwrap() = get_init_async_job_status(); +} + #[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))] #[inline] pub fn change_id(id: String) { - *ASYNC_JOB_STATUS.lock().unwrap() = " ".to_owned(); + reset_async_job_status(); let old_id = get_id(); std::thread::spawn(move || { - *ASYNC_JOB_STATUS.lock().unwrap() = change_id_shared(id, old_id).to_owned(); + change_id_shared(id, old_id).to_owned(); }); } @@ -1012,8 +1024,13 @@ pub(crate) async fn send_to_cm(data: &ipc::Data) { const INVALID_FORMAT: &'static str = "Invalid format"; const UNKNOWN_ERROR: &'static str = "Unknown error"; +#[inline] #[tokio::main(flavor = "current_thread")] -pub async fn change_id_shared(id: String, old_id: String) -> &'static str { +pub async fn change_id_shared(id: String, old_id: String) { + *ASYNC_JOB_STATUS.lock().unwrap() = change_id_shared_(id, old_id).await.to_owned(); +} + +pub async fn change_id_shared_(id: String, old_id: String) -> &'static str { if !hbb_common::is_valid_custom_id(&id) { return INVALID_FORMAT; } From 31ade3372cff625e48da637cf562fd6680b9a58e Mon Sep 17 00:00:00 2001 From: dignow Date: Sun, 25 Jun 2023 15:37:39 +0800 Subject: [PATCH 2/2] fix change id Signed-off-by: dignow --- src/ui_interface.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ui_interface.rs b/src/ui_interface.rs index c42615ed1..2232f3c42 100644 --- a/src/ui_interface.rs +++ b/src/ui_interface.rs @@ -6,6 +6,7 @@ use hbb_common::{ directories_next, log, tokio, }; use hbb_common::{ + bytes::Bytes, config::{CONNECT_TIMEOUT, RENDEZVOUS_PORT}, futures::future::join_all, rendezvous_proto::*, @@ -653,7 +654,7 @@ pub fn change_id(id: String) { reset_async_job_status(); let old_id = get_id(); std::thread::spawn(move || { - change_id_shared(id, old_id).to_owned(); + change_id_shared(id, old_id); }); } @@ -1036,9 +1037,9 @@ pub async fn change_id_shared_(id: String, old_id: String) -> &'static str { } #[cfg(not(any(target_os = "android", target_os = "ios")))] - let uuid = machine_uid::get().unwrap_or("".to_owned()); + let uuid = Bytes::from(machine_uid::get().unwrap_or("".to_owned()).as_bytes().to_vec()); #[cfg(any(target_os = "android", target_os = "ios"))] - let uuid = crate::encode64(hbb_common::get_uuid()); + let uuid = Bytes::from(hbb_common::get_uuid()); if uuid.is_empty() { log::error!("Failed to change id, uuid is_empty"); @@ -1082,7 +1083,7 @@ async fn check_id( rendezvous_server: String, old_id: String, id: String, - uuid: String, + uuid: Bytes, ) -> &'static str { if let Ok(mut socket) = hbb_common::socket_client::connect_tcp( crate::check_port(rendezvous_server, RENDEZVOUS_PORT), @@ -1094,7 +1095,7 @@ async fn check_id( msg_out.set_register_pk(RegisterPk { old_id, id, - uuid: uuid.into(), + uuid, ..Default::default() }); let mut ok = false;