From c73f57578dc293852afd8aec8c643255a32b3d92 Mon Sep 17 00:00:00 2001 From: vikingowl Date: Sat, 28 Mar 2026 10:23:49 +0100 Subject: [PATCH] fix(converter): fix double unit in description, broken icon, currency aliases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Description showed "20 m = 0.02 km km" — display_value already includes the unit symbol, removed redundant r.target_symbol - Icon changed from "edit-find-replace" to "edit-find-replace-symbolic" which exists in Adwaita - Currency aliases (dollar, euro, etc.) now resolve in convert_to and convert_common — they were only handled by find_unit (parser validation) but not by lookup_unit (actual conversion) --- Cargo.lock | 12 +++---- crates/owlry-plugin-converter/Cargo.toml | 2 +- crates/owlry-plugin-converter/src/lib.rs | 5 ++- crates/owlry-plugin-converter/src/units.rs | 41 +++++++++++++++++++++- 4 files changed, 49 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 67b5705..3173eb0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -879,7 +879,7 @@ dependencies = [ [[package]] name = "owlry-plugin-bookmarks" -version = "1.0.0" +version = "1.0.1" dependencies = [ "abi_stable", "dirs", @@ -891,7 +891,7 @@ dependencies = [ [[package]] name = "owlry-plugin-calculator" -version = "1.0.0" +version = "1.0.1" dependencies = [ "abi_stable", "meval", @@ -908,7 +908,7 @@ dependencies = [ [[package]] name = "owlry-plugin-converter" -version = "1.0.0" +version = "1.0.1" dependencies = [ "abi_stable", "dirs", @@ -920,7 +920,7 @@ dependencies = [ [[package]] name = "owlry-plugin-emoji" -version = "1.0.0" +version = "1.0.1" dependencies = [ "abi_stable", "owlry-plugin-api", @@ -966,7 +966,7 @@ dependencies = [ [[package]] name = "owlry-plugin-ssh" -version = "1.0.0" +version = "1.0.1" dependencies = [ "abi_stable", "dirs", @@ -1005,7 +1005,7 @@ dependencies = [ [[package]] name = "owlry-plugin-websearch" -version = "1.0.0" +version = "1.0.1" dependencies = [ "abi_stable", "dirs", diff --git a/crates/owlry-plugin-converter/Cargo.toml b/crates/owlry-plugin-converter/Cargo.toml index 9d05dd3..1fdadbe 100644 --- a/crates/owlry-plugin-converter/Cargo.toml +++ b/crates/owlry-plugin-converter/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "owlry-plugin-converter" -version = "1.0.1" +version = "1.0.2" edition.workspace = true rust-version.workspace = true license.workspace = true diff --git a/crates/owlry-plugin-converter/src/lib.rs b/crates/owlry-plugin-converter/src/lib.rs index e7df754..554f896 100644 --- a/crates/owlry-plugin-converter/src/lib.rs +++ b/crates/owlry-plugin-converter/src/lib.rs @@ -26,7 +26,7 @@ const PLUGIN_DESCRIPTION: &str = "Convert between units and currencies"; const PROVIDER_ID: &str = "converter"; const PROVIDER_NAME: &str = "Converter"; const PROVIDER_PREFIX: &str = ">"; -const PROVIDER_ICON: &str = "edit-find-replace"; +const PROVIDER_ICON: &str = "edit-find-replace-symbolic"; const PROVIDER_TYPE_ID: &str = "conv"; struct ConverterState; @@ -95,11 +95,10 @@ extern "C" fn provider_query(_handle: ProviderHandle, query: RStr<'_>) -> RVec

Option<(usize, &UnitDef)> { } pub fn convert_to(value: &f64, from: &str, to: &str) -> Option { + // Try currency first — currency aliases (dollar, euro, etc.) aren't in the UNITS table + if currency::is_currency_alias(from) || currency::is_currency_alias(to) { + return convert_currency(*value, from, to); + } + let (_, from_def) = lookup_unit(from)?; let (_, to_def) = lookup_unit(to)?; - // Currency needs special handling + // Currency via UNITS table (shouldn't reach here, but just in case) if from_def.category == Category::Currency || to_def.category == Category::Currency { return convert_currency(*value, from, to); } @@ -121,6 +126,11 @@ pub fn convert_to(value: &f64, from: &str, to: &str) -> Option } pub fn convert_common(value: &f64, from: &str) -> Vec { + // Try currency first — currency aliases (dollar, euro, etc.) aren't in the UNITS table + if currency::is_currency_alias(from) { + return convert_currency_common(*value, from); + } + let (_, from_def) = match lookup_unit(from) { Some(u) => u, None => return vec![], @@ -902,4 +912,33 @@ mod tests { // display_value should have reasonable formatting assert!(!r.display_value.is_empty()); } + + #[test] + fn test_currency_alias_convert_to() { + // "dollar" and "euro" are aliases, not in the UNITS table + let r = convert_to(&20.0, "dollar", "euro"); + // May return None if ECB rates unavailable (network), but should not panic + // In a network-available environment, this should return Some + if let Some(r) = r { + assert!(r.value > 0.0); + assert_eq!(r.target_symbol, "EUR"); + } + } + + #[test] + fn test_currency_alias_convert_common() { + let results = convert_common(&20.0, "dollar"); + // May be empty if ECB rates unavailable, but should not panic + for r in &results { + assert!(r.value > 0.0); + } + } + + #[test] + fn test_display_value_no_double_unit() { + let r = convert_to(&100.0, "km", "mi").unwrap(); + // display_value should contain the symbol exactly once + let count = r.display_value.matches(&r.target_symbol).count(); + assert_eq!(count, 1, "display_value '{}' should contain '{}' exactly once", r.display_value, r.target_symbol); + } }