fix(updater): format Update.date to RFC 3339 (#2573)

* fix(updater): format `Update.date` to RFC 3339

* Messed up on argument in #2572

* Format

* Update example

* Avoid extra to_string

* Deprecate `Update.available`
This commit is contained in:
Tony
2025-03-29 08:36:50 +08:00
committed by GitHub
parent 0bc5d58874
commit 2d731f8022
7 changed files with 47 additions and 28 deletions
+23 -16
View File
@@ -28,8 +28,7 @@ pub enum DownloadEvent {
#[derive(Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub(crate) struct Metadata {
rid: Option<ResourceId>,
available: bool,
rid: ResourceId,
current_version: String,
version: String,
date: Option<String>,
@@ -40,8 +39,6 @@ pub(crate) struct Metadata {
struct DownloadedBytes(pub Vec<u8>);
impl Resource for DownloadedBytes {}
// TODO: Align this with the result of `updater.check` to Result<Option<Metadata>>
// and remove `available` instead of handling this in the js side
#[tauri::command]
pub(crate) async fn check<R: Runtime>(
webview: Webview<R>,
@@ -49,7 +46,7 @@ pub(crate) async fn check<R: Runtime>(
timeout: Option<u64>,
proxy: Option<String>,
target: Option<String>,
) -> Result<Metadata> {
) -> Result<Option<Metadata>> {
let mut builder = webview.updater_builder();
if let Some(headers) = headers {
for (k, v) in headers {
@@ -69,18 +66,28 @@ pub(crate) async fn check<R: Runtime>(
let updater = builder.build()?;
let update = updater.check().await?;
let mut metadata = Metadata::default();
if let Some(update) = update {
metadata.available = true;
metadata.current_version.clone_from(&update.current_version);
metadata.version.clone_from(&update.version);
metadata.date = update.date.map(|d| d.to_string());
metadata.body.clone_from(&update.body);
metadata.raw_json.clone_from(&update.raw_json);
metadata.rid = Some(webview.resources_table().add(update));
}
Ok(metadata)
if let Some(update) = update {
let formatted_date = if let Some(date) = update.date {
let formatted_date = date
.format(&time::format_description::well_known::Rfc3339)
.map_err(|_| crate::Error::FormatDate)?;
Some(formatted_date)
} else {
None
};
let metadata = Metadata {
current_version: update.current_version.clone(),
version: update.version.clone(),
date: formatted_date,
body: update.body.clone(),
raw_json: update.raw_json.clone(),
rid: webview.resources_table().add(update),
};
Ok(Some(metadata))
} else {
Ok(None)
}
}
#[tauri::command]
+2
View File
@@ -77,6 +77,8 @@ pub enum Error {
InvalidHeaderValue(#[from] http::header::InvalidHeaderValue),
#[error(transparent)]
InvalidHeaderName(#[from] http::header::InvalidHeaderName),
#[error("Failed to format date")]
FormatDate,
/// The configured updater endpoint must use a secure protocol like `https`
#[error("The configured updater endpoint must use a secure protocol like `https`.")]
InsecureTransportProtocol,
+2 -1
View File
@@ -310,7 +310,8 @@ impl UpdaterBuilder {
I: IntoIterator<Item = S>,
S: Into<OsString>,
{
self.installer_args.extend(args.into_iter().map(Into::into));
self.current_exe_args
.extend(args.into_iter().map(Into::into));
self
}
}