diff --git a/crates/openlogi-agent-core/src/orchestrator.rs b/crates/openlogi-agent-core/src/orchestrator.rs index c3aac3218e..58f3d8668f 100644 --- a/crates/openlogi-agent-core/src/orchestrator.rs +++ b/crates/openlogi-agent-core/src/orchestrator.rs @@ -1819,10 +1819,19 @@ impl Orchestrator { ) { continue; } + // The same precedence the tray and the GUI use: a user-assigned + // name, then the product name the settings app persisted, then the + // firmware codename. let name = self .config .device_custom_name(&device.config_key) .map(str::to_owned) + .or_else(|| { + self.config + .device_identity(&device.config_key) + .map(|identity| identity.display_name.trim().to_owned()) + .filter(|name| !name.is_empty()) + }) .or_else(|| device.codename.as_deref().map(prettify_codename)); info!(device = %device.config_key, ?battery, "announcing a low battery"); self.observable.notices().post( diff --git a/crates/openlogi-agent-core/src/orchestrator/tests/low_battery.rs b/crates/openlogi-agent-core/src/orchestrator/tests/low_battery.rs index fcaa2b4ff0..4f2e23ca6a 100644 --- a/crates/openlogi-agent-core/src/orchestrator/tests/low_battery.rs +++ b/crates/openlogi-agent-core/src/orchestrator/tests/low_battery.rs @@ -86,6 +86,41 @@ async fn the_notice_names_the_device_as_the_user_does() { ); } +#[tokio::test] +async fn the_notice_prefers_the_persisted_product_name() { + let mut config = Config::default(); + config.set_device_identity( + KEY, + openlogi_core::config::DeviceIdentity { + display_name: "MX Master 3S".to_owned(), + model_info: None, + codename: Some("Synthetic Performance Mouse".to_owned()), + kind: DeviceKind::Mouse, + capabilities: openlogi_core::device::Capabilities::default(), + light_capabilities: None, + driver_id: None, + registry_model_id: None, + }, + ); + let (mut orch, observable) = wired(config); + refresh( + &mut orch, + discharging(10), + true, + "Synthetic Performance Mouse", + ); + let posted = notices(&observable).await; + assert_eq!(posted.len(), 1); + assert_eq!( + posted[0].kind, + NoticeKind::LowBattery { + name: Some("MX Master 3S".to_owned()), + kind: DeviceKind::Mouse, + battery: discharging(10), + } + ); +} + #[tokio::test] async fn a_shouted_device_name_is_tidied() { let (mut orch, observable) = wired(Config::default());