diff --git a/notify/src/main.rs b/notify/src/main.rs index e63fc37..c2f00d4 100644 --- a/notify/src/main.rs +++ b/notify/src/main.rs @@ -67,7 +67,7 @@ fn main() { eprintln!("failed to update fwupd remotes: {}", why); } - fwupd_scan(client, &event_handler); + fwupd_scan(client, http_client, &event_handler); } } } diff --git a/src/fwupd.rs b/src/fwupd.rs index 92de1ef..d3b26c0 100644 --- a/src/fwupd.rs +++ b/src/fwupd.rs @@ -1,8 +1,11 @@ //! Functions specific to working with fwupd firmware. use crate::{FirmwareInfo, FirmwareSignal}; -use fwupd_dbus::{Client as FwupdClient, Device as FwupdDevice, Release as FwupdRelease}; -use std::{cmp::Ordering, error::Error as _, io, process::Command}; +use fwupd_dbus::{ + Client as FwupdClient, Device as FwupdDevice, FlashEvent, Release as FwupdRelease, +}; +use reqwest::Client as HttpClient; +use std::cmp::Ordering; /// A signal sent when a fwupd-compatible device has been discovered. #[derive(Debug)] @@ -18,7 +21,7 @@ pub struct FwupdSignal { } /// Scan for supported devices from the fwupd DBus daemon. -pub fn fwupd_scan(fwupd: &FwupdClient, sender: F) { +pub fn fwupd_scan(fwupd: &FwupdClient, http: &HttpClient, sender: F) { info!("scanning fwupd devices"); let devices = match fwupd.devices() { @@ -36,7 +39,23 @@ pub fn fwupd_scan(fwupd: &FwupdClient, sender: F) { crate::sort_versions(&mut releases); let latest = releases.iter().last().expect("no releases"); - let upgradeable = is_newer(&device.version, &latest.version); + let mut upgradeable = is_newer(&device.version, &latest.version); + + if upgradeable { + if let Err(why) = fwupd.fetch_firmware_from_release( + http, + &device, + latest, + None::, + ) { + error!( + "failed to fetch firmware for {}: {}", + device.name, + crate::format_error(why) + ); + upgradeable = false; + } + } sender(FirmwareSignal::Fwupd(FwupdSignal { info: FirmwareInfo { diff --git a/src/lib.rs b/src/lib.rs index 0ec75c6..594c23d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -232,7 +232,7 @@ pub fn event_loop(receiver: Receiver, send if let Err(why) = fwupd_updates(client, http_client) { eprintln!("failed to update fwupd remotes: {}", why); } - fwupd_scan(client, sender); + fwupd_scan(client, http_client, sender); } }