From 8427b03a394ff5f9f372ee224b10d697052c6737 Mon Sep 17 00:00:00 2001 From: Sahil Yeole Date: Wed, 23 Aug 2023 00:13:23 +0530 Subject: [PATCH] Using github latest release url to check for software update Signed-off-by: Sahil Yeole --- src/common.rs | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/src/common.rs b/src/common.rs index 011ca0524..5ad92d914 100644 --- a/src/common.rs +++ b/src/common.rs @@ -831,30 +831,19 @@ pub fn check_software_update() { #[tokio::main(flavor = "current_thread")] async fn check_software_update_() -> hbb_common::ResultType<()> { - sleep(3.).await; + let url = "https://github.com/rustdesk/rustdesk/releases/latest"; + let latest_release_response = reqwest::get(url).await?; + let latest_release_version = latest_release_response + .url() + .path() + .rsplit('/') + .next() + .unwrap(); - let rendezvous_server = format!("rs-sg.rustdesk.com:{}", config::RENDEZVOUS_PORT); - let (mut socket, rendezvous_server) = - socket_client::new_udp_for(&rendezvous_server, CONNECT_TIMEOUT).await?; + let response_url = latest_release_response.url().to_string(); - let mut msg_out = RendezvousMessage::new(); - msg_out.set_software_update(SoftwareUpdate { - url: crate::VERSION.to_owned(), - ..Default::default() - }); - socket.send(&msg_out, rendezvous_server).await?; - use hbb_common::protobuf::Message; - for _ in 0..2 { - if let Some(Ok((bytes, _))) = socket.next_timeout(READ_TIMEOUT).await { - if let Ok(msg_in) = RendezvousMessage::parse_from_bytes(&bytes) { - if let Some(rendezvous_message::Union::SoftwareUpdate(su)) = msg_in.union { - let version = hbb_common::get_version_from_url(&su.url); - if get_version_number(&version) > get_version_number(crate::VERSION) { - *SOFTWARE_UPDATE_URL.lock().unwrap() = su.url; - } - } - } - } + if get_version_number(&latest_release_version) > get_version_number(crate::VERSION) { + *SOFTWARE_UPDATE_URL.lock().unwrap() = response_url; } Ok(()) }