feat, update, win, macos (#11618)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2025-05-04 07:32:47 +08:00
committed by GitHub
parent 62276b4f4f
commit ca00706a38
72 changed files with 2128 additions and 69 deletions

View File

@@ -21,11 +21,12 @@ use hbb_common::{
};
use std::{
collections::HashMap,
path::PathBuf,
sync::{
atomic::{AtomicI32, Ordering},
Arc,
},
time::SystemTime,
time::{Duration, SystemTime},
};
pub type SessionID = uuid::Uuid;
@@ -2428,7 +2429,42 @@ pub fn main_get_common(key: String) -> String {
} else if key == "transfer-job-id" {
return hbb_common::fs::get_next_job_id().to_string();
} else {
"".to_owned()
if key.starts_with("download-data-") {
let id = key.replace("download-data-", "");
match crate::hbbs_http::downloader::get_download_data(&id) {
Ok(data) => serde_json::to_string(&data).unwrap_or_default(),
Err(e) => {
format!("error:{}", e)
}
}
} else if key.starts_with("download-file-") {
let _version = key.replace("download-file-", "");
#[cfg(target_os = "windows")]
return match crate::platform::windows::is_msi_installed() {
Ok(true) => format!("rustdesk-{_version}-x86_64.msi"),
Ok(false) => format!("rustdesk-{_version}-x86_64.exe"),
Err(e) => {
log::error!("Failed to check if is msi: {}", e);
format!("error:update-failed-check-msi-tip")
}
};
#[cfg(target_os = "macos")]
{
return if cfg!(target_arch = "x86_64") {
format!("rustdesk-{_version}-x86_64.dmg")
} else if cfg!(target_arch = "aarch64") {
format!("rustdesk-{_version}-aarch64.dmg")
} else {
"error:unsupported".to_owned()
};
}
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
{
"error:unsupported".to_owned()
}
} else {
"".to_owned()
}
}
}
@@ -2469,6 +2505,72 @@ pub fn main_set_common(_key: String, _value: String) {
);
});
}
#[cfg(any(target_os = "windows", target_os = "macos"))]
{
use crate::updater::get_download_file_from_url;
if _key == "download-new-version" {
let download_url = _value.clone();
let event_key = "download-new-version".to_owned();
let data = if let Some(download_file) = get_download_file_from_url(&download_url) {
std::fs::remove_file(&download_file).ok();
match crate::hbbs_http::downloader::download_file(
download_url,
Some(PathBuf::from(download_file)),
Some(Duration::from_secs(3)),
) {
Ok(id) => HashMap::from([("name", event_key), ("id", id)]),
Err(e) => HashMap::from([("name", event_key), ("error", e.to_string())]),
}
} else {
HashMap::from([
("name", event_key),
("error", "Invalid download url".to_string()),
])
};
let _res = flutter::push_global_event(
flutter::APP_TYPE_MAIN,
serde_json::ser::to_string(&data).unwrap_or("".to_owned()),
);
} else if _key == "update-me" {
if let Some(new_version_file) = get_download_file_from_url(&_value) {
log::debug!("New version file is downloaed, update begin, {:?}", new_version_file.to_str());
if let Some(f) = new_version_file.to_str() {
// 1.4.0 does not support "--update"
// But we can assume that the new version supports it.
#[cfg(target_os = "windows")]
if f.ends_with(".exe") {
if let Err(e) =
crate::platform::run_exe_in_cur_session(f, vec!["--update"], false)
{
log::error!("Failed to run the update exe: {}", e);
}
} else if f.ends_with(".msi") {
if let Err(e) = crate::platform::update_me_msi(f, false) {
log::error!("Failed to run the update msi: {}", e);
}
} else {
// unreachable!()
}
#[cfg(target_os = "macos")]
match crate::platform::update_to(f) {
Ok(_) => {
log::info!("Update successfully!");
}
Err(e) => {
log::error!("Failed to update to new version, {}", e);
}
}
fs::remove_file(f).ok();
}
}
}
}
if _key == "remove-downloader" {
crate::hbbs_http::downloader::remove(&_value);
} else if _key == "cancel-downloader" {
crate::hbbs_http::downloader::cancel(&_value);
}
}
pub fn session_get_common_sync(