Skip to content

Commit e9e4c78

Browse files
FabianLarsgezihuzi
authored andcommitted
feat(updater): Collect unknown response fields (tauri-apps#2325)
1 parent fef82d8 commit e9e4c78

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

.changes/updater-unknown-fields.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
updater: minor
3+
updater-js: minor
4+
---
5+
6+
The `Update` struct/object will now contain a `raw_json`/`rawJson` property to be able to read parts of server's json response that are not handled by the plugin.

plugins/updater/api-iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/updater/guest-js/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ interface UpdateMetadata {
4343
version: string
4444
date?: string
4545
body?: string
46+
rawJson: Record<string, unknown>
4647
}
4748

4849
/** Updater download event */
@@ -57,6 +58,7 @@ class Update extends Resource {
5758
version: string
5859
date?: string
5960
body?: string
61+
rawJson: Record<string, unknown>
6062
private downloadedBytes?: Resource
6163

6264
constructor(metadata: UpdateMetadata) {
@@ -66,6 +68,7 @@ class Update extends Resource {
6668
this.version = metadata.version
6769
this.date = metadata.date
6870
this.body = metadata.body
71+
this.rawJson = metadata.rawJson
6972
}
7073

7174
/** Download the updater package */

plugins/updater/src/commands.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub(crate) struct Metadata {
3434
version: String,
3535
date: Option<String>,
3636
body: Option<String>,
37+
raw_json: serde_json::Value,
3738
}
3839

3940
struct DownloadedBytes(pub Vec<u8>);
@@ -73,6 +74,7 @@ pub(crate) async fn check<R: Runtime>(
7374
metadata.version.clone_from(&update.version);
7475
metadata.date = update.date.map(|d| d.to_string());
7576
metadata.body.clone_from(&update.body);
77+
metadata.raw_json.clone_from(&update.raw_json);
7678
metadata.rid = Some(webview.resources_table().add(update));
7779
}
7880

plugins/updater/src/updater.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ impl Updater {
330330
}
331331

332332
let mut remote_release: Option<RemoteRelease> = None;
333+
let mut raw_json: Option<serde_json::Value> = None;
333334
let mut last_error: Option<Error> = None;
334335
for url in &self.endpoints {
335336
// replace {{current_version}}, {{target}} and {{arch}} in the provided URL
@@ -379,7 +380,8 @@ impl Updater {
379380
return Ok(None);
380381
};
381382

382-
match serde_json::from_value::<RemoteRelease>(res.json().await?)
383+
raw_json = Some(res.json().await?);
384+
match serde_json::from_value::<RemoteRelease>(raw_json.clone().unwrap())
383385
.map_err(Into::into)
384386
{
385387
Ok(release) => {
@@ -421,6 +423,7 @@ impl Updater {
421423
download_url: release.download_url(&self.json_target)?.to_owned(),
422424
body: release.notes.clone(),
423425
signature: release.signature(&self.json_target)?.to_owned(),
426+
raw_json: raw_json.unwrap(),
424427
timeout: self.timeout,
425428
proxy: self.proxy.clone(),
426429
headers: self.headers.clone(),
@@ -454,6 +457,8 @@ pub struct Update {
454457
pub download_url: Url,
455458
/// Signature announced
456459
pub signature: String,
460+
/// The raw version of server's JSON response. Useful if the response contains additional fields that the updater doesn't handle.
461+
pub raw_json: serde_json::Value,
457462
/// Request timeout
458463
pub timeout: Option<Duration>,
459464
/// Request proxy

0 commit comments

Comments
 (0)