Skip to content

Commit

Permalink
Bump to 2.0.0-alpha.1 & fix version checks
Browse files Browse the repository at this point in the history
  • Loading branch information
encounter committed May 21, 2024
1 parent f5b5a61 commit 94f1f07
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 31 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion objdiff-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "objdiff-cli"
version = "0.1.0"
version = "2.0.0-alpha.1"
edition = "2021"
rust-version = "1.70"
authors = ["Luke Street <luke@street.dev>"]
Expand Down
2 changes: 1 addition & 1 deletion objdiff-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "objdiff-core"
version = "1.0.0"
version = "2.0.0-alpha.1"
edition = "2021"
rust-version = "1.70"
authors = ["Luke Street <luke@street.dev>"]
Expand Down
9 changes: 5 additions & 4 deletions objdiff-core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,11 @@ fn validate_min_version(config: &ProjectConfig) -> Result<()> {
let Some(min_version) = &config.min_version else { return Ok(()) };
let version = semver::Version::parse(env!("CARGO_PKG_VERSION"))
.context("Failed to parse package version")?;
match semver::VersionReq::parse(&format!(">={min_version}")) {
Ok(version_req) if version_req.matches(&version) => Ok(()),
Ok(_) => Err(anyhow!("Project requires objdiff version {min_version} or higher")),
Err(e) => Err(anyhow::Error::new(e).context("Failed to parse min_version")),
let min_version = semver::Version::parse(min_version).context("Failed to parse min_version")?;
if version >= min_version {
Ok(())
} else {
Err(anyhow!("Project requires objdiff version {min_version} or higher"))
}
}

Expand Down
2 changes: 1 addition & 1 deletion objdiff-gui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "objdiff-gui"
version = "1.0.0"
version = "2.0.0-alpha.1"
edition = "2021"
rust-version = "1.70"
authors = ["Luke Street <luke@street.dev>"]
Expand Down
12 changes: 9 additions & 3 deletions objdiff-gui/src/jobs/check_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use self_update::{cargo_crate_version, update::Release};

use crate::{
jobs::{start_job, update_status, Job, JobContext, JobResult, JobState},
update::{build_updater, BIN_NAME},
update::{build_updater, BIN_NAME_NEW, BIN_NAME_OLD},
};

pub struct CheckUpdateResult {
pub update_available: bool,
pub latest_release: Release,
pub found_binary: bool,
pub found_binary: Option<String>,
}

fn run_check_update(context: &JobContext, cancel: Receiver<()>) -> Result<Box<CheckUpdateResult>> {
Expand All @@ -20,7 +20,13 @@ fn run_check_update(context: &JobContext, cancel: Receiver<()>) -> Result<Box<Ch
let latest_release = updater.get_latest_release()?;
let update_available =
self_update::version::bump_is_greater(cargo_crate_version!(), &latest_release.version)?;
let found_binary = latest_release.assets.iter().any(|a| a.name == BIN_NAME);
// Find the binary name in the release assets
let found_binary = latest_release
.assets
.iter()
.find(|a| a.name == BIN_NAME_NEW)
.or_else(|| latest_release.assets.iter().find(|a| a.name == BIN_NAME_OLD))
.map(|a| a.name.clone());

update_status(context, "Complete".to_string(), 1, 1, &cancel)?;
Ok(Box::new(CheckUpdateResult { update_available, latest_release, found_binary }))
Expand Down
17 changes: 10 additions & 7 deletions objdiff-gui/src/jobs/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,29 @@ use std::{
};

use anyhow::{Context, Result};
use const_format::formatcp;

use crate::{
jobs::{start_job, update_status, Job, JobContext, JobResult, JobState},
update::{build_updater, BIN_NAME},
update::build_updater,
};

pub struct UpdateResult {
pub exe_path: PathBuf,
}

fn run_update(status: &JobContext, cancel: Receiver<()>) -> Result<Box<UpdateResult>> {
fn run_update(
status: &JobContext,
cancel: Receiver<()>,
bin_name: String,
) -> Result<Box<UpdateResult>> {
update_status(status, "Fetching latest release".to_string(), 0, 3, &cancel)?;
let updater = build_updater().context("Failed to create release updater")?;
let latest_release = updater.get_latest_release()?;
let asset = latest_release
.assets
.iter()
.find(|a| a.name == BIN_NAME)
.ok_or_else(|| anyhow::Error::msg(formatcp!("No release asset for {}", BIN_NAME)))?;
.find(|a| a.name == bin_name)
.ok_or_else(|| anyhow::Error::msg(format!("No release asset for {bin_name}")))?;

update_status(status, "Downloading release".to_string(), 1, 3, &cancel)?;
let tmp_dir = tempfile::Builder::new().prefix("update").tempdir_in(current_dir()?)?;
Expand Down Expand Up @@ -53,8 +56,8 @@ fn run_update(status: &JobContext, cancel: Receiver<()>) -> Result<Box<UpdateRes
Ok(Box::from(UpdateResult { exe_path: target_file }))
}

pub fn start_update(ctx: &egui::Context) -> JobState {
pub fn start_update(ctx: &egui::Context, bin_name: String) -> JobState {
start_job(ctx, "Update app", Job::Update, move |context, cancel| {
run_update(&context, cancel).map(JobResult::Update)
run_update(&context, cancel, bin_name).map(JobResult::Update)
})
}
8 changes: 5 additions & 3 deletions objdiff-gui/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ cfg_if! {
}
pub const GITHUB_USER: &str = "encounter";
pub const GITHUB_REPO: &str = "objdiff";
pub const BIN_NAME: &str =
formatcp!("{}-{}-{}{}", GITHUB_REPO, OS, ARCH, std::env::consts::EXE_SUFFIX);
pub const BIN_NAME_NEW: &str =
formatcp!("objdiff-gui-{}-{}{}", OS, ARCH, std::env::consts::EXE_SUFFIX);
pub const BIN_NAME_OLD: &str = formatcp!("objdiff-{}-{}{}", OS, ARCH, std::env::consts::EXE_SUFFIX);
pub const RELEASE_URL: &str =
formatcp!("https://github.com/{}/{}/releases/latest", GITHUB_USER, GITHUB_REPO);

pub fn build_updater() -> self_update::errors::Result<Box<dyn ReleaseUpdate>> {
self_update::backends::github::Update::configure()
.repo_owner(GITHUB_USER)
.repo_name(GITHUB_REPO)
.bin_name(BIN_NAME)
// bin_name is required, but unused?
.bin_name(BIN_NAME_NEW)
.no_confirm(true)
.show_output(false)
.current_version(cargo_crate_version!())
Expand Down
16 changes: 8 additions & 8 deletions objdiff-gui/src/views/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct ConfigViewState {
pub check_update_running: bool,
pub queue_check_update: bool,
pub update_running: bool,
pub queue_update: bool,
pub queue_update: Option<String>,
pub build_running: bool,
pub queue_build: bool,
pub watch_pattern_text: String,
Expand Down Expand Up @@ -127,9 +127,8 @@ impl ConfigViewState {
jobs.push_once(Job::CheckUpdate, || start_check_update(ctx));
}

if self.queue_update {
self.queue_update = false;
jobs.push_once(Job::Update, || start_update(ctx));
if let Some(bin_name) = self.queue_update.take() {
jobs.push_once(Job::Update, || start_update(ctx, bin_name));
}
}
}
Expand Down Expand Up @@ -201,15 +200,16 @@ pub fn config_ui(
if result.update_available {
ui.colored_label(appearance.insert_color, "Update available");
ui.horizontal(|ui| {
if result.found_binary
&& ui
if let Some(bin_name) = &result.found_binary {
if ui
.add_enabled(!state.update_running, egui::Button::new("Automatic"))
.on_hover_text_at_pointer(
"Automatically download and replace the current build",
)
.clicked()
{
state.queue_update = true;
{
state.queue_update = Some(bin_name.clone());
}
}
if ui
.button("Manual")
Expand Down

0 comments on commit 94f1f07

Please sign in to comment.