fix(converter): fix double unit in description, broken icon, currency aliases

- 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)
This commit is contained in:
2026-03-28 10:23:49 +01:00
parent b46477ae88
commit c73f57578d
4 changed files with 49 additions and 11 deletions
Generated
+6 -6
View File
@@ -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",
+1 -1
View File
@@ -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
+2 -3
View File
@@ -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<P
format!("printf '%s' '{}' | wl-copy", r.raw_value.replace('\'', "'\\''")),
)
.with_description(format!(
"{} {} = {} {}",
"{} {} = {}",
format_number(parsed.value),
parsed.from_symbol,
r.display_value,
r.target_symbol,
))
.with_icon(PROVIDER_ICON)
})
+40 -1
View File
@@ -101,10 +101,15 @@ pub fn lookup_unit(alias: &str) -> Option<(usize, &UnitDef)> {
}
pub fn convert_to(value: &f64, from: &str, to: &str) -> Option<ConversionResult> {
// 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<ConversionResult>
}
pub fn convert_common(value: &f64, from: &str) -> Vec<ConversionResult> {
// 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);
}
}