Skip to content

Commit 87afa23

Browse files
feat(updater): add allowDowngrades option (#2726)
* feat(updater): add allowDowngrades option * Add change file for allow_downgrades feature * Update .changes/add-allow-downgrades.md
1 parent d401907 commit 87afa23

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

.changes/add-allow-downgrades.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"updater": minor
3+
"updater-js": minor
4+
---
5+
6+
Add allowDowngrades parameter to check command
7+
8+
Added a new optional `allowDowngrades` parameter to the JavaScript check command that allows the updater to consider versions that are lower than the current version as valid updates. When enabled, the version comparator will accept any version that is different from the current version, effectively allowing downgrades.

plugins/updater/guest-js/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ interface CheckOptions {
2222
* Target identifier for the running application. This is sent to the backend.
2323
*/
2424
target?: string
25+
/**
26+
* Allow downgrades to previous versions by not checking if the current version is greater than the available version.
27+
*/
28+
allowDowngrades?: boolean
2529
}
2630

2731
/** Options used when downloading an update */

plugins/updater/src/commands.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub(crate) async fn check<R: Runtime>(
4646
timeout: Option<u64>,
4747
proxy: Option<String>,
4848
target: Option<String>,
49+
allow_downgrades: Option<bool>,
4950
) -> Result<Option<Metadata>> {
5051
let mut builder = webview.updater_builder();
5152
if let Some(headers) = headers {
@@ -63,6 +64,9 @@ pub(crate) async fn check<R: Runtime>(
6364
if let Some(target) = target {
6465
builder = builder.target(target);
6566
}
67+
if allow_downgrades.unwrap_or(false) {
68+
builder = builder.version_comparator(|current, update| update.version != current);
69+
}
6670

6771
let updater = builder.build()?;
6872
let update = updater.check().await?;

0 commit comments

Comments
 (0)