From 9ec6efdc9823a65587bd8b16663fdf897d26a5f4 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Thu, 8 Aug 2019 10:33:06 -0600 Subject: [PATCH] fix(core): Activate fwupd with dbus ping 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 --- Cargo.lock | 2 +- Makefile | 9 +++------ com.system76.FirmwareManager.target | 4 ---- debian/control | 7 ------- debian/firmware-manager-shared.install | 1 - debian/firmware-manager-shared.links | 1 - debian/firmware-manager-shared.postinst | 7 ------- notify/src/main.rs | 16 +++++++++++++--- src/lib.rs | 18 ++++++++++++------ 9 files changed, 29 insertions(+), 36 deletions(-) delete mode 100644 com.system76.FirmwareManager.target delete mode 100644 debian/firmware-manager-shared.install delete mode 100644 debian/firmware-manager-shared.links delete mode 100644 debian/firmware-manager-shared.postinst diff --git a/Cargo.lock b/Cargo.lock index ed4394c..68886f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -746,7 +746,7 @@ dependencies = [ [[package]] name = "fwupd-dbus" version = "0.1.0" -source = "git+https://github.com/pop-os/fwupd-dbus#0bf8da2a57002b4220c5c3abf1c0e83952f2bcc3" +source = "git+https://github.com/pop-os/fwupd-dbus#c8f9e4aa08510e1c6f18c9aea94a32e017d1edeb" dependencies = [ "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "cascade 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Makefile b/Makefile index a717493..7b6d6b1 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/com.system76.FirmwareManager.target b/com.system76.FirmwareManager.target deleted file mode 100644 index ad92323..0000000 --- a/com.system76.FirmwareManager.target +++ /dev/null @@ -1,4 +0,0 @@ -[Unit] -Description=Ensures that the fwupd service has been started -Requires=network-online.target -Wants=fwupd.service diff --git a/debian/control b/debian/control index 77b95c4..1344e7d 100644 --- a/debian/control +++ b/debian/control @@ -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} @@ -46,7 +40,6 @@ Architecture: amd64 Depends: dbus, firmware-manager-notify, - firmware-manager-shared, libgtk-3-0, ${misc:Depends}, ${shlib:Depends} diff --git a/debian/firmware-manager-shared.install b/debian/firmware-manager-shared.install deleted file mode 100644 index e6d3df5..0000000 --- a/debian/firmware-manager-shared.install +++ /dev/null @@ -1 +0,0 @@ -/lib/systemd/system/com.system76.FirmwareManager.target diff --git a/debian/firmware-manager-shared.links b/debian/firmware-manager-shared.links deleted file mode 100644 index d83d80e..0000000 --- a/debian/firmware-manager-shared.links +++ /dev/null @@ -1 +0,0 @@ -lib/systemd/system/com.system76.FirmwareManager.target lib/systemd/system/multi-user.target.wants/com.system76.FirmwareManager.target diff --git a/debian/firmware-manager-shared.postinst b/debian/firmware-manager-shared.postinst deleted file mode 100644 index 2995634..0000000 --- a/debian/firmware-manager-shared.postinst +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh -set -x -systemctl start fwupd.service - -#DEBHELPER# - -exit 0 \ No newline at end of file diff --git a/notify/src/main.rs b/notify/src/main.rs index 9f0dc56..257b62f 100644 --- a/notify/src/main.rs +++ b/notify/src/main.rs @@ -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::{ @@ -12,7 +12,7 @@ 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}; @@ -20,8 +20,18 @@ 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(); diff --git a/src/lib.rs b/src/lib.rs index bbd741c..fd69aea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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::{ @@ -168,8 +168,18 @@ pub enum FirmwareSignal { pub fn event_loop(receiver: Receiver, 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(); @@ -415,10 +425,6 @@ pub fn s76_scan(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") }