Merge pull request #4773 from dignow/fix/change_id_sciter

Fix/change id sciter
This commit is contained in:
RustDesk 2023-06-25 17:42:12 +08:00 committed by GitHub
commit 510ce30e5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 7 deletions

View File

@ -542,6 +542,7 @@ impl UI {
} }
fn change_id(&self, id: String) { fn change_id(&self, id: String) {
reset_async_job_status();
let old_id = self.get_id(); let old_id = self.get_id();
change_id_shared(id, old_id); change_id_shared(id, old_id);
} }

View File

@ -6,6 +6,7 @@ use hbb_common::{
directories_next, log, tokio, directories_next, log, tokio,
}; };
use hbb_common::{ use hbb_common::{
bytes::Bytes,
config::{CONNECT_TIMEOUT, RENDEZVOUS_PORT}, config::{CONNECT_TIMEOUT, RENDEZVOUS_PORT},
futures::future::join_all, futures::future::join_all,
rendezvous_proto::*, rendezvous_proto::*,
@ -64,6 +65,8 @@ lazy_static::lazy_static! {
pub static ref SENDER : Mutex<mpsc::UnboundedSender<ipc::Data>> = Mutex::new(check_connect_status(true)); pub static ref SENDER : Mutex<mpsc::UnboundedSender<ipc::Data>> = Mutex::new(check_connect_status(true));
} }
const INIT_ASYNC_JOB_STATUS: &str = " ";
#[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))] #[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))]
#[inline] #[inline]
pub fn get_id() -> String { pub fn get_id() -> String {
@ -635,13 +638,23 @@ pub fn get_uuid() -> String {
crate::encode64(hbb_common::get_uuid()) 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"))] #[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))]
#[inline] #[inline]
pub fn change_id(id: String) { pub fn change_id(id: String) {
*ASYNC_JOB_STATUS.lock().unwrap() = " ".to_owned(); reset_async_job_status();
let old_id = get_id(); let old_id = get_id();
std::thread::spawn(move || { std::thread::spawn(move || {
*ASYNC_JOB_STATUS.lock().unwrap() = change_id_shared(id, old_id).to_owned(); change_id_shared(id, old_id);
}); });
} }
@ -1012,16 +1025,21 @@ pub(crate) async fn send_to_cm(data: &ipc::Data) {
const INVALID_FORMAT: &'static str = "Invalid format"; const INVALID_FORMAT: &'static str = "Invalid format";
const UNKNOWN_ERROR: &'static str = "Unknown error"; const UNKNOWN_ERROR: &'static str = "Unknown error";
#[inline]
#[tokio::main(flavor = "current_thread")] #[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) { if !hbb_common::is_valid_custom_id(&id) {
return INVALID_FORMAT; return INVALID_FORMAT;
} }
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[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"))] #[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() { if uuid.is_empty() {
log::error!("Failed to change id, uuid is_empty"); log::error!("Failed to change id, uuid is_empty");
@ -1065,7 +1083,7 @@ async fn check_id(
rendezvous_server: String, rendezvous_server: String,
old_id: String, old_id: String,
id: String, id: String,
uuid: String, uuid: Bytes,
) -> &'static str { ) -> &'static str {
if let Ok(mut socket) = hbb_common::socket_client::connect_tcp( if let Ok(mut socket) = hbb_common::socket_client::connect_tcp(
crate::check_port(rendezvous_server, RENDEZVOUS_PORT), crate::check_port(rendezvous_server, RENDEZVOUS_PORT),
@ -1077,7 +1095,7 @@ async fn check_id(
msg_out.set_register_pk(RegisterPk { msg_out.set_register_pk(RegisterPk {
old_id, old_id,
id, id,
uuid: uuid.into(), uuid,
..Default::default() ..Default::default()
}); });
let mut ok = false; let mut ok = false;