Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/updater-unknown-fields.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
updater: minor
updater-js: minor
---

The `Update` struct/object will now contain a `other_response_fields`/`otherResponseFields` property that contains all other fields found in the server's json response that are not handled by the plugin.
2 changes: 1 addition & 1 deletion plugins/updater/api-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions plugins/updater/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface UpdateMetadata {
version: string
date?: string
body?: string
otherResponseFields: Record<string, unknown>
}

/** Updater download event */
Expand All @@ -57,6 +58,7 @@ class Update extends Resource {
version: string
date?: string
body?: string
otherResponseFields: Record<string, unknown>
private downloadedBytes?: Resource

constructor(metadata: UpdateMetadata) {
Expand All @@ -66,6 +68,7 @@ class Update extends Resource {
this.version = metadata.version
this.date = metadata.date
this.body = metadata.body
this.otherResponseFields = metadata.otherResponseFields
}

/** Download the updater package */
Expand Down
6 changes: 5 additions & 1 deletion plugins/updater/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use http::{HeaderMap, HeaderName, HeaderValue};
use serde::Serialize;
use tauri::{ipc::Channel, Manager, Resource, ResourceId, Runtime, Webview};

use std::{str::FromStr, time::Duration};
use std::{collections::HashMap, str::FromStr, time::Duration};
use url::Url;

#[derive(Debug, Clone, Serialize)]
Expand All @@ -34,6 +34,7 @@ pub(crate) struct Metadata {
version: String,
date: Option<String>,
body: Option<String>,
other_response_fields: HashMap<String, serde_json::Value>,
}

struct DownloadedBytes(pub Vec<u8>);
Expand Down Expand Up @@ -73,6 +74,9 @@ pub(crate) async fn check<R: Runtime>(
metadata.version.clone_from(&update.version);
metadata.date = update.date.map(|d| d.to_string());
metadata.body.clone_from(&update.body);
metadata
.other_response_fields
.clone_from(&update.other_response_fields);
metadata.rid = Some(webview.resources_table().add(update));
}

Expand Down
13 changes: 13 additions & 0 deletions plugins/updater/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ pub struct RemoteRelease {
pub pub_date: Option<OffsetDateTime>,
/// Release data.
pub data: RemoteReleaseInner,
/// Additional unknown fields found in the server's JSON response.
///
/// Field names should be reasonable unique to not interfere with potential future plugin additions.
pub other_response_fields: HashMap<String, serde_json::Value>,
}

impl RemoteRelease {
Expand Down Expand Up @@ -421,6 +425,7 @@ impl Updater {
download_url: release.download_url(&self.json_target)?.to_owned(),
body: release.notes.clone(),
signature: release.signature(&self.json_target)?.to_owned(),
other_response_fields: release.other_response_fields.clone(),
timeout: self.timeout,
proxy: self.proxy.clone(),
headers: self.headers.clone(),
Expand Down Expand Up @@ -454,6 +459,10 @@ pub struct Update {
pub download_url: Url,
/// Signature announced
pub signature: String,
/// Additional unknown fields found in the server's JSON response.
///
/// Field names should be reasonable unique to not interfere with potential future plugin additions.
pub other_response_fields: HashMap<String, serde_json::Value>,
/// Request timeout
pub timeout: Option<Duration>,
/// Request proxy
Expand Down Expand Up @@ -1153,6 +1162,9 @@ impl<'de> Deserialize<'de> for RemoteRelease {
// dynamic platform response
url: Option<Url>,
signature: Option<String>,
// unknown fields
#[serde(flatten)]
other_response_fields: HashMap<String, serde_json::Value>,
}

let release = InnerRemoteRelease::deserialize(deserializer)?;
Expand Down Expand Up @@ -1182,6 +1194,7 @@ impl<'de> Deserialize<'de> for RemoteRelease {
})?,
})
},
other_response_fields: release.other_response_fields,
})
}
}
Expand Down
Loading