diff --git a/.changes/add-allow-downgrades.md b/.changes/add-allow-downgrades.md new file mode 100644 index 00000000..dd888671 --- /dev/null +++ b/.changes/add-allow-downgrades.md @@ -0,0 +1,8 @@ +--- +"updater": minor +"updater-js": minor +--- + +Add allowDowngrades parameter to check command + +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. diff --git a/plugins/updater/guest-js/index.ts b/plugins/updater/guest-js/index.ts index 87f7929a..c33033ec 100644 --- a/plugins/updater/guest-js/index.ts +++ b/plugins/updater/guest-js/index.ts @@ -22,6 +22,10 @@ interface CheckOptions { * Target identifier for the running application. This is sent to the backend. */ target?: string + /** + * Allow downgrades to previous versions by not checking if the current version is greater than the available version. + */ + allowDowngrades?: boolean } /** Options used when downloading an update */ diff --git a/plugins/updater/src/commands.rs b/plugins/updater/src/commands.rs index ae84294f..129c413c 100644 --- a/plugins/updater/src/commands.rs +++ b/plugins/updater/src/commands.rs @@ -46,6 +46,7 @@ pub(crate) async fn check( timeout: Option, proxy: Option, target: Option, + allow_downgrades: Option, ) -> Result> { let mut builder = webview.updater_builder(); if let Some(headers) = headers { @@ -63,6 +64,9 @@ pub(crate) async fn check( if let Some(target) = target { builder = builder.target(target); } + if allow_downgrades.unwrap_or(false) { + builder = builder.version_comparator(|current, update| update.version != current); + } let updater = builder.build()?; let update = updater.check().await?;