Using github latest release url to check for software update

Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com>
This commit is contained in:
Sahil Yeole 2023-08-23 00:13:23 +05:30
parent 6666dece5d
commit 8427b03a39

View File

@ -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(())
}