Skip to content

Commit

Permalink
fix(core): Activate fwupd with dbus ping
Browse files Browse the repository at this point in the history
The fwupd service will activate when a method is called on it. We can use the dbus Ping() method to check for the the existence of the service, and to enable it if it has not already been enabled
  • Loading branch information
mmstick committed Aug 13, 2019
1 parent a671383 commit 9ec6efd
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,21 @@ $(PKGCONFIG): tools/src/pkgconfig.rs

install: install-bin install-ffi install-notify

install-bin: install-shared
install-bin:
install -Dm0755 "$(GTKBINARY)" "$(DESTDIR)$(bindir)/$(APPID)"
install -Dm0644 "$(DESKTOP)" "$(DESTDIR)$(prefix)/share/applications/$(APPID).desktop"

install-ffi: install-shared
install-ffi:
install -Dm0644 "$(HEADER)" "$(DESTDIR)$(includedir)/$(PACKAGE).h"
install -Dm0644 "$(LIBRARY)" "$(DESTDIR)$(libdir)/lib$(PACKAGE).so"
install -Dm0644 "$(PKGCONFIG)" "$(DESTDIR)$(libdir)/pkgconfig/$(PACKAGE).pc"

install-notify: install-shared
install-notify:
install -Dm0755 "$(NOTBINARY)" "$(DESTDIR)$(bindir)/$(NOTIFY_APPID)"
install -Dm0644 "$(STARTUP_DESKTOP)" "$(DESTDIR)/etc/xdg/autostart/$(NOTIFY_APPID).desktop"
install -Dm0644 "target/$(NOTIFY_SERVICE)" "$(DESTDIR)$(libdir)/systemd/user/$(NOTIFY_SERVICE)"
install -Dm0644 "target/$(NOTIFY_TIMER)" "$(DESTDIR)$(libdir)/systemd/user/$(NOTIFY_TIMER)"

install-shared:
install -Dm0644 $(APPID).target "$(DESTDIR)/lib/systemd/system/$(APPID).target"

## Uninstall Commands

uninstall: uninstall-bin uninstall-ffi
Expand Down
4 changes: 0 additions & 4 deletions com.system76.FirmwareManager.target

This file was deleted.

7 changes: 0 additions & 7 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@ Build-Depends:
Standards-Version: 4.1.4
Homepage: https://github.com/pop-os/firmware-manager

Package: firmware-manager-shared
Architecture: all
Description: Firmware Manager init service
Ensures that the fwupd service has been activated

Package: firmware-manager
Architecture: amd64
Depends:
dbus,
firmware-manager-notify,
firmware-manager-shared,
libgtk-3-0,
${misc:Depends},
${shlib:Depends}
Expand All @@ -46,7 +40,6 @@ Architecture: amd64
Depends:
dbus,
firmware-manager-notify,
firmware-manager-shared,
libgtk-3-0,
${misc:Depends},
${shlib:Depends}
Expand Down
1 change: 0 additions & 1 deletion debian/firmware-manager-shared.install

This file was deleted.

1 change: 0 additions & 1 deletion debian/firmware-manager-shared.links

This file was deleted.

7 changes: 0 additions & 7 deletions debian/firmware-manager-shared.postinst

This file was deleted.

16 changes: 13 additions & 3 deletions notify/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(feature = "fwupd")]
use firmware_manager::FwupdSignal;
use firmware_manager::{FwupdError, FwupdSignal};
use firmware_manager::{get_client, FirmwareSignal};
use notify_rust::{Notification, Timeout};
use std::{
Expand All @@ -12,16 +12,26 @@ const UPDATES_FOUND: i32 = 3;
const GNOME_CONTROL_CENTER: &str = "/usr/share/applications/gnome-firmware-panel.desktop";

#[cfg(feature = "fwupd")]
use firmware_manager::{fwupd_is_active, fwupd_scan, fwupd_updates, FwupdClient};
use firmware_manager::{fwupd_scan, fwupd_updates, FwupdClient};

#[cfg(feature = "system76")]
use firmware_manager::{s76_firmware_is_active, s76_scan, System76Client};

fn main() {
#[cfg(feature = "system76")]
let s76 = get_client("system76", s76_firmware_is_active, System76Client::new);

#[cfg(feature = "fwupd")]
let fwupd = get_client("fwupd", fwupd_is_active, FwupdClient::new);
let fwupd = get_client::<_, _, FwupdError>(
"fwupd",
|| true,
|| {
let client = FwupdClient::new()?;
client.ping()?;
Ok(client)
},
);

#[cfg(feature = "fwupd")]
let http_client = &reqwest::Client::new();

Expand Down
18 changes: 12 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern crate err_derive;
extern crate shrinkwraprs;

#[cfg(feature = "fwupd")]
pub use fwupd_dbus::{Client as FwupdClient, Device as FwupdDevice, Release as FwupdRelease};
pub use fwupd_dbus::{Client as FwupdClient, Device as FwupdDevice, Error as FwupdError, Release as FwupdRelease};

#[cfg(feature = "system76")]
pub use system76_firmware_daemon::{
Expand Down Expand Up @@ -168,8 +168,18 @@ pub enum FirmwareSignal {
pub fn event_loop<F: Fn(FirmwareSignal)>(receiver: Receiver<FirmwareEvent>, sender: F) {
#[cfg(feature = "system76")]
let s76 = get_client("system76", s76_firmware_is_active, System76Client::new);

#[cfg(feature = "fwupd")]
let fwupd = get_client("fwupd", fwupd_is_active, FwupdClient::new);
let fwupd = get_client::<_, _, fwupd_dbus::Error>(
"fwupd",
|| true,
|| {
let client = FwupdClient::new()?;
client.ping()?;
Ok(client)
},
);

#[cfg(feature = "fwupd")]
let http_client = &reqwest::Client::new();

Expand Down Expand Up @@ -415,10 +425,6 @@ pub fn s76_scan<F: Fn(FirmwareSignal)>(client: &System76Client, sender: F) {
}
}

/// Check if the fwupd service is active.
#[cfg(feature = "fwupd")]
pub fn fwupd_is_active() -> bool { systemd_service_is_active("fwupd") }

/// Check if the system76-firmware-daemon service is active.
#[cfg(feature = "system76")]
pub fn s76_firmware_is_active() -> bool { systemd_service_is_active("system76-firmware-daemon") }
Expand Down

0 comments on commit 9ec6efd

Please sign in to comment.