From aaa771b5ceff0cb9188229d1bc2cb850e2a48539 Mon Sep 17 00:00:00 2001 From: Summer Tea <79724236+acuteaangle@users.noreply.github.com> Date: Mon, 3 Mar 2025 22:00:08 -0500 Subject: [PATCH 1/2] feat: ensure at least one stable version is offered Previously, PineFlash would fetch the three latest version of IronOS from GitHub, irrespective of the prerelease status of those versions. This meant that PineFlash would only offer unstable versions if there were three or more prereleases for the upcoming version. As of 2025-03-03, PineFlash only offers: - v2.23-rc3 - v2.23-rc2 - v2.23-rc1 This patch implements the following rules for choosing which versions of IronOS to offer to the user: - Releases marked as 'draft' on GitHub must never be offered - At least one stable version must always be offered - Prereleases of versions that have since been fully released should not be offered With this patch, PineFlash instead offers the following versions on 2025-03-03: - v2.23-rc3 - v2.23-rc2 - v2.22 Resolves: gh-92 --- src/main.rs | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7257be6..9dcba9f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -298,8 +298,46 @@ impl eframe::App for Flasher { .push_str("PineFlash: Invalid json downloaded, could not fetch versions.\n"); self.config.versions_checked = true; } else { - for i in 0..3 { - let version = json.as_ref().unwrap()[i]["tag_name"].as_str().unwrap(); + // Find N (3) versions to display to the user + // The first N-1 slots may include prereleases for an upcoming version. + // The latest stable version should always be included. + // Prereleases for fully released versions should not be included. + // Remaining slots will be filled with old stable versions. + // GitHub Draft releases should never be included. + const DESIRED_VERSIONS: u8 = 3; // How many versions do we want to find + let mut versions_found: u8 = 0; // How many versions have we accepted to display + let mut stable_version_accepted: bool = false; // Have we accepted a stable version yet + let mut index: usize = 0; // Which release are we currently evaluating + while versions_found < DESIRED_VERSIONS { + // Find the release we are evaluating + let release = &json.as_ref().unwrap()[index]; + let version = release["tag_name"].as_str().unwrap(); + // If this release is a draft, skip it + if release["draft"] == true { + index += 1; + continue; + }; + // If this is a prerelease and we are currently trying to fill the last version slot, + // skip this release, as we want to offer at least one stable version + if release["prerelease"] == true && versions_found >= DESIRED_VERSIONS - 1 { + index += 1; + continue; + }; + // If this is a prerelease and we have already accepted a stable version, skip this version, + // as we do not want to offer prereleases of old versions + if release["prerelease"] == true && stable_version_accepted == true { + index += 1; + continue; + }; + // If this is a stable version, record that we have found one, as we don't want + // any (more) prereleases after this + if release["prerelease"] == false { + stable_version_accepted = true; + }; + + // We will offer this version to the user; count it; extract and store the git tag + versions_found += 1; + index += 1; self.config.vers.push(version.to_string()); } self.config.versions_checked = true; From 363fa364cc07b583aab08436d0393b7163ea9cb2 Mon Sep 17 00:00:00 2001 From: Summer Tea <79724236+acuteaangle@users.noreply.github.com> Date: Mon, 3 Mar 2025 20:43:33 -0500 Subject: [PATCH 2/2] feat: add debug logging This patch adds debug logging to PineFlash, to aid with debugging and creating bug reports. This commit is dependant on aaa771b5, as it includes logging specific to that patch. This patch adds `env_logger` as a dependency; however, `log` was already a transitive dependency, and this patch will expose the logging functionality of dependencies automatically. This patch adds some initial debug and trace logging statements to PineFlash itself (specifically building on aaa771b5), and opens the door for future contributions to also include useful diagnostic and informational log messages. It also exposes the logging functionality of dependencies. INFO (or higher) messages from dependencies will be now be printed automatically, and running PineFlash with the environment variable `RUST_LOG=debug` or `RUST_LOG=trace` set will already print many potentially useful diagnostic messages from dependencies. The goal of this patch is to introduce new tools to aid in debugging, and allow contributors to polish hasty println!() debugging into reusable diagnostic messages where useful, rather than simply deleting it to be recreated when needed again. Related-to: gh-92 --- Cargo.lock | 107 +++++++++++++++++++++++++++++++++++++++++++++++++--- Cargo.toml | 2 + src/main.rs | 16 ++++++++ 3 files changed, 119 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 95b88aa..468f430 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "CoreFoundation-sys" @@ -185,6 +185,55 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "arboard" version = "3.3.2" @@ -785,6 +834,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + [[package]] name = "com" version = "0.6.0" @@ -1266,6 +1321,29 @@ dependencies = [ "syn 2.0.58", ] +[[package]] +name = "env_filter" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcaee3d8e3cfc3fd92428d477bc97fc29ec8716d180c0d74c643bb26166660e0" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + [[package]] name = "epaint" version = "0.27.2" @@ -1813,6 +1891,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "icrate" version = "0.0.4" @@ -1894,6 +1978,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itoa" version = "1.0.4" @@ -2072,12 +2162,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.17" +version = "0.4.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] +checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" [[package]] name = "mach" @@ -2550,6 +2637,8 @@ dependencies = [ "egui-notify", "egui_extras", "egui_file", + "env_logger", + "log", "rfd", "rusb", "serde", @@ -3568,6 +3657,12 @@ dependencies = [ "tiny-skia-path", ] +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index 0b0eb10..aa0d391 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,8 @@ confy = "0.5.1" curl = "0.4.44" simple-home-dir = "0.1.2" version-compare = "0.1.1" +log = "0.4.26" +env_logger = "0.11.6" [build-dependencies] winresource = "0.1.15" diff --git a/src/main.rs b/src/main.rs index 9dcba9f..2464a8c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,7 @@ mod submodules; use egui::Context; use egui_file::FileDialog; use egui_notify::{Anchor, Toasts}; +use log::{debug, error, info, log_enabled, trace, warn, Level}; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -308,36 +309,50 @@ impl eframe::App for Flasher { let mut versions_found: u8 = 0; // How many versions have we accepted to display let mut stable_version_accepted: bool = false; // Have we accepted a stable version yet let mut index: usize = 0; // Which release are we currently evaluating + debug!("Choosing versions to display to the user"); while versions_found < DESIRED_VERSIONS { // Find the release we are evaluating let release = &json.as_ref().unwrap()[index]; let version = release["tag_name"].as_str().unwrap(); + debug!("Currently evaluating candidate {}: '{}'", index, version); + trace!("'{}': {:#?}", version, release); // If this release is a draft, skip it if release["draft"] == true { + debug!("'{}' is a draft release; skipping", version); index += 1; continue; }; // If this is a prerelease and we are currently trying to fill the last version slot, // skip this release, as we want to offer at least one stable version if release["prerelease"] == true && versions_found >= DESIRED_VERSIONS - 1 { + debug!( + "'{}' is a prerelease, but we want a stable version; skipping", + version + ); index += 1; continue; }; // If this is a prerelease and we have already accepted a stable version, skip this version, // as we do not want to offer prereleases of old versions if release["prerelease"] == true && stable_version_accepted == true { + debug!("'{}' is a prerelease for an old version; skipping", version); index += 1; continue; }; // If this is a stable version, record that we have found one, as we don't want // any (more) prereleases after this if release["prerelease"] == false { + trace!( + "'{}', is a stable version; no longer accepting prereleases", + version + ); stable_version_accepted = true; }; // We will offer this version to the user; count it; extract and store the git tag versions_found += 1; index += 1; + debug!("'{}' will be offered to the user", version); self.config.vers.push(version.to_string()); } self.config.versions_checked = true; @@ -541,6 +556,7 @@ impl eframe::App for Flasher { } fn main() { + env_logger::init(); let options = eframe::NativeOptions::default(); // let options = eframe::NativeOptions { // decorated: true,