Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch firmware from fwupd in advance #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion notify/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
27 changes: 23 additions & 4 deletions src/fwupd.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -18,7 +21,7 @@ pub struct FwupdSignal {
}

/// Scan for supported devices from the fwupd DBus daemon.
pub fn fwupd_scan<F: Fn(FirmwareSignal)>(fwupd: &FwupdClient, sender: F) {
pub fn fwupd_scan<F: Fn(FirmwareSignal)>(fwupd: &FwupdClient, http: &HttpClient, sender: F) {
info!("scanning fwupd devices");

let devices = match fwupd.devices() {
Expand All @@ -36,7 +39,23 @@ pub fn fwupd_scan<F: Fn(FirmwareSignal)>(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::<fn(FlashEvent)>,
) {
error!(
"failed to fetch firmware for {}: {}",
device.name,
crate::format_error(why)
);
upgradeable = false;
}
}

sender(FirmwareSignal::Fwupd(FwupdSignal {
info: FirmwareInfo {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ pub fn event_loop<F: Fn(FirmwareSignal)>(receiver: Receiver<FirmwareEvent>, 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);
}
}

Expand Down