Skip to content

Commit

Permalink
Fix version update monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Feb 25, 2024
1 parent bf55c3b commit 735209b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ pub enum Error {

#[error("{0}")]
JsError(workflow_wasm::jserror::JsErrorData),

#[error("ParseInt")]
ParseInt(#[from] std::num::ParseIntError),
}

impl Error {
Expand Down
3 changes: 2 additions & 1 deletion core/src/modules/overview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ impl Overview {
});

if let Some(release) = core.release.as_ref() {
if is_wasm() || release.version == crate::app::VERSION {
let is_greater = is_version_greater(crate::app::VERSION.as_str(), release.version.as_str()).ok().unwrap_or(false);
if is_wasm() || !is_greater {
CollapsingHeader::new(i18n("Redistributables"))
.id_source("redistributables")
.default_open(true)
Expand Down
16 changes: 16 additions & 0 deletions core/src/utils/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,19 @@ pub fn release_link_name(name: impl Into<String>) -> impl Into<WidgetText> {
RichText::new(format!("• {name}"))
}
}

pub fn is_version_greater(current: &str, update: &str) -> Result<bool> {
let current = current
.split('.')
.map(|part| part.parse().map_err(Into::into))
.collect::<Result<Vec<u64>>>()?;
let update = update
.split('.')
.map(|part| part.parse().map_err(Into::into))
.collect::<Result<Vec<u64>>>()?;

let current = current.iter().fold(0, |acc, &x| acc * 1000 + x);
let update = update.iter().fold(0, |acc, &x| acc * 1000 + x);

Ok(current < update)
}

0 comments on commit 735209b

Please sign in to comment.