fix(updater): detect stable releases from build metadata versions

This commit is contained in:
Tunglies
2026-09-21 19:11:30 +08:00
parent 81ce247ecc
commit 8982525fd2
3 changed files with 26 additions and 8 deletions
+13 -6
View File
@@ -101,15 +101,22 @@ impl SilentUpdater {
}
}
/// Compares numeric version components after stripping `v` and prerelease suffixes.
pub fn is_build_to_stable(current: &str, remote: &str) -> bool {
let Some((base, build)) = current.trim_start_matches('v').split_once('+') else {
return false;
};
!build.is_empty() && !base.contains('-') && base == remote.trim_start_matches('v')
}
/// Compares numeric version components after stripping version suffixes.
fn version_lte(a: &str, b: &str) -> bool {
let parse = |v: &str| -> Vec<u64> {
v.trim_start_matches('v')
.split(['-', '+'])
.next()
.unwrap_or("0")
.split('.')
.filter_map(|part| {
let numeric = part.split('-').next().unwrap_or("0");
numeric.parse::<u64>().ok()
})
.filter_map(|part| part.parse::<u64>().ok())
.collect()
};
@@ -152,7 +159,7 @@ impl SilentUpdater {
let cached_version = &meta.version;
if version_lte(cached_version, current_version) {
if !is_build_to_stable(current_version, cached_version) && version_lte(cached_version, current_version) {
logging!(
info,
Type::System,
+8 -1
View File
@@ -44,7 +44,14 @@ mod app_init {
let mut builder = builder
.plugin(tauri_plugin_clash_verge_sysinfo::init())
.plugin(tauri_plugin_notification::init())
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(
tauri_plugin_updater::Builder::new()
.default_version_comparator(|current, release| {
release.version > current
|| core::updater::is_build_to_stable(&current.to_string(), &release.version.to_string())
})
.build(),
)
.plugin(tauri_plugin_clipboard_manager::init())
.plugin(tauri_plugin_process::init())
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
+5 -1
View File
@@ -78,7 +78,11 @@ export const checkUpdateSafe = async (
const remoteVersion = resolveRemoteVersion(result)
const comparison = compareVersions(remoteVersion, localVersionNormalized)
if (comparison !== null && comparison <= 0) {
const isBuildToStable =
/^\d+\.\d+\.\d+\+[0-9A-Za-z.-]+$/.test(localVersionNormalized ?? '') &&
remoteVersion === localVersionNormalized?.split('+')[0]
if (comparison !== null && comparison <= 0 && !isBuildToStable) {
try {
await result.close()
} catch (err) {