fix, sciter, change_id

Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
dignow 2023-06-25 13:14:21 +08:00
parent 98e87d0c54
commit c468b48619
2 changed files with 21 additions and 3 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

@ -64,6 +64,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 +637,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).to_owned();
}); });
} }
@ -1012,8 +1024,13 @@ 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;
} }