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

Check for firmware updates #45

Merged
merged 20 commits into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Install Dependencies
run: |
apt update
apt install -y libaccountsservice-dev libdbus-1-dev libgranite-dev libgeoclue-2-dev meson valac
apt install -y libaccountsservice-dev libdbus-1-dev libgranite-dev libgeoclue-2-dev libfwupd-dev meson valac
- name: Build
env:
DESTDIR: out
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ You'll need the following dependencies:
* gobject-2.0
* libaccountsservice-dev
* libdbus-1-dev
* libgranite-dev
* libfwupd-dev
* libgeoclue-2-dev
* libgranite-dev
* meson
* valac

Expand Down
1 change: 1 addition & 0 deletions data/autostart.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Type=Application
Name=Elementary Settings Daemon
Comment=Elementary Settings Daemon
Exec=io.elementary.settings-daemon
Icon=preferences-desktop
Terminal=false
Categories=System;Core;
NoDisplay=true
Expand Down
9 changes: 9 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ project('io.elementary.settings-daemon',
license: 'GPL3',
)

fwupd = dependency('fwupd')
gio_dep = dependency ('gio-2.0')
glib_dep = dependency('glib-2.0')
granite_dep = dependency('granite', version: '>= 5.3.0')
i18n = import('i18n')
gettext_name = meson.project_name()

add_project_arguments(
'-DGETTEXT_PACKAGE="@0@"'.format(gettext_name),
language:'c'
)

cc = meson.get_compiler('c')
m_dep = cc.find_library('m', required : false)
Expand All @@ -30,12 +37,14 @@ config_dep = declare_dependency(

prefix = get_option('prefix')
datadir = join_paths(prefix, get_option('datadir'))
libexecdir = join_paths(prefix, get_option('libexecdir'))

symlink = join_paths(meson.current_source_dir (), 'meson', 'create-symlink.sh')

subdir('data')
subdir('po')
subdir('src')
subdir('settings-portal')
subdir('periodic-tasks')

meson.add_install_script('meson/post_install.py')
79 changes: 79 additions & 0 deletions periodic-tasks/check-for-firmware-updates/Application.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2022 elementary, Inc. (https://elementary.io)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
*/

public class CheckForFirmwareUpdates.Application : GLib.Application {
private Application () {}

public uint firmware_updates_number { get; private set; default = 0U; }

construct {
application_id = Build.PROJECT_NAME + ".check-for-firmware-updates";
}

public override void activate () {
bool was_empty = firmware_updates_number == 0U;
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved

var fwupd_client = new Fwupd.Client ();
var num_updates = 0;
try {
var devices = fwupd_client.get_devices ();
for (int i = 0; i < devices.length; i++) {
var device = devices[i];
if (device.has_flag (Fwupd.DEVICE_FLAG_UPDATABLE)) {
Fwupd.Release? release = null;
try {
var upgrades = fwupd_client.get_upgrades (device.get_id ());

if (upgrades != null) {
release = upgrades[0];
}
} catch (Error e) {
warning (e.message);
}

if (release != null && device.get_version () != release.get_version ()) {
num_updates++;
}
}
}
} catch (Error e) {
warning (e.message);
}

if (was_empty && num_updates != 0U) {
string title = ngettext ("Firmware Update Available", "Firmware Updates Available", num_updates);
string body = ngettext ("%u update is available for your hardware", "%u updates are available for your hardware", num_updates).printf (num_updates);

var notification = new Notification (title);
notification.set_body (body);
notification.set_icon (new ThemedIcon ("application-x-firmware"));
notification.set_default_action ("io.elementary.settings-daemon.show-firmware-updates");

send_notification ("io.elementary.settings-daemon.firmware.updates", notification);
} else {
withdraw_notification ("io.elementary.settings-daemon.firmware.updates");
}
}

public static int main (string[] args) {
var application = new Application ();
return application.run (args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
Description=Check for firmware updates daily
ConditionACPower=true
After=network.target network-online.target systemd-networkd.service NetworkManager.service connman.service

[Service]
Type=oneshot
ExecStart=/usr/libexec/io.elementary.settings-daemon.check-for-firmware-updates
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Check for firmware updates daily

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target
26 changes: 26 additions & 0 deletions periodic-tasks/check-for-firmware-updates/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
sources = files(
'Application.vala',
)

executable(
meson.project_name() + '.check-for-firmware-updates',
sources,
dependencies: [
config_dep,
fwupd,
gio_dep,
glib_dep,
],
install: true,
install_dir: libexecdir,
)

install_data(
meson.project_name() + '.check-for-firmware-updates.service',
install_dir: systemd_system_unit_dir
)

install_data(
meson.project_name() + '.check-for-firmware-updates.timer',
install_dir: systemd_system_unit_dir
)
4 changes: 4 additions & 0 deletions periodic-tasks/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
systemd = dependency('systemd')
systemd_system_unit_dir = systemd.get_pkgconfig_variable('systemdsystemunitdir')

subdir('check-for-firmware-updates')
1 change: 1 addition & 0 deletions po/POTFILES
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
data/settings-daemon.appdata.xml.in
src/Backends/Firmware.vala
11 changes: 11 additions & 0 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ public class SettingsDaemon.Application : GLib.Application {
add_main_option_entries (OPTIONS);

housekeeping = new Backends.Housekeeping ();

var show_firmware_updates_action = new SimpleAction ("show-firmware-updates", null);
show_firmware_updates_action.activate.connect (() => {
try {
Gtk.show_uri_on_window (null, "settings://about/firmware", Gdk.CURRENT_TIME);
} catch (Error e) {
critical (e.message);
}
});

add_action (show_firmware_updates_action);
}

public override int handle_local_options (VariantDict options) {
Expand Down