[gnome-software/1935-firmware-updates-are-hidden-if-they-require-the-laptop-lid-to-be-open] fwupd: Show hidden updates and provide a problem information for them
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/1935-firmware-updates-are-hidden-if-they-require-the-laptop-lid-to-be-open] fwupd: Show hidden updates and provide a problem information for them
- Date: Wed, 12 Oct 2022 10:32:27 +0000 (UTC)
commit 1cede30458161820ed0371794debed1105873004
Author: Milan Crha <mcrha redhat com>
Date: Wed Oct 12 12:28:12 2022 +0200
fwupd: Show hidden updates and provide a problem information for them
An update can be hidden due to a problem the user can do something about it,
like when the update cannot be applied, because a lid is closed. Check for
these states and set them on the GsApp for further processing on the UI side.
plugins/fwupd/gs-fwupd-app.c | 90 +++++++++++++++++++++++++++++++++++++++--
plugins/fwupd/gs-fwupd-app.h | 1 +
plugins/fwupd/gs-plugin-fwupd.c | 6 ++-
3 files changed, 93 insertions(+), 4 deletions(-)
---
diff --git a/plugins/fwupd/gs-fwupd-app.c b/plugins/fwupd/gs-fwupd-app.c
index 7fcbdadab..e72f318e7 100644
--- a/plugins/fwupd/gs-fwupd-app.c
+++ b/plugins/fwupd/gs-fwupd-app.c
@@ -53,13 +53,68 @@ gs_fwupd_app_set_is_locked (GsApp *app, gboolean is_locked)
gs_app_set_metadata_variant (app, "fwupd::IsLocked", tmp);
}
+#if FWUPD_CHECK_VERSION(1, 8, 1)
+static gchar * /* (transfer full) */
+gs_fwupd_problem_to_string (FwupdClient *client,
+ FwupdDevice *dev,
+ FwupdDeviceProblem problem)
+{
+ if (problem == FWUPD_DEVICE_PROBLEM_SYSTEM_POWER_TOO_LOW) {
+ if (fwupd_client_get_battery_level (client) == FWUPD_BATTERY_LEVEL_INVALID ||
+ fwupd_client_get_battery_threshold (client) == FWUPD_BATTERY_LEVEL_INVALID) {
+ /* TRANSLATORS: as in laptop battery power */
+ return g_strdup (_("System power is too low to perform the update"));
+ }
+ return g_strdup_printf (
+ /* TRANSLATORS: as in laptop battery power */
+ _("System power is too low to perform the update (%u%%, requires %u%%)"),
+ fwupd_client_get_battery_level (client),
+ fwupd_client_get_battery_threshold (client));
+ }
+ if (problem == FWUPD_DEVICE_PROBLEM_UNREACHABLE) {
+ /* TRANSLATORS: for example, a Bluetooth mouse that is in powersave mode */
+ return g_strdup (_("Device is unreachable, or out of wireless range"));
+ }
+ if (problem == FWUPD_DEVICE_PROBLEM_POWER_TOO_LOW) {
+ if (fwupd_device_get_battery_level (dev) == FWUPD_BATTERY_LEVEL_INVALID ||
+ fwupd_device_get_battery_threshold (dev) == FWUPD_BATTERY_LEVEL_INVALID) {
+ /* TRANSLATORS: for example the batteries *inside* the Bluetooth mouse */
+ return g_strdup_printf (_("Device battery power is too low"));
+ }
+ /* TRANSLATORS: for example the batteries *inside* the Bluetooth mouse */
+ return g_strdup_printf (_("Device battery power is too low (%u%%, requires %u%%)"),
+ fwupd_device_get_battery_level (dev),
+ fwupd_device_get_battery_threshold (dev));
+ }
+ if (problem == FWUPD_DEVICE_PROBLEM_UPDATE_PENDING) {
+ /* TRANSLATORS: usually this is when we're waiting for a reboot */
+ return g_strdup (_("Device is waiting for the update to be applied"));
+ }
+ if (problem == FWUPD_DEVICE_PROBLEM_REQUIRE_AC_POWER) {
+ /* TRANSLATORS: as in, wired mains power for a laptop */
+ return g_strdup (_("Device requires AC power to be connected"));
+ }
+ if (problem == FWUPD_DEVICE_PROBLEM_LID_IS_CLOSED) {
+ /* TRANSLATORS: lid means "laptop top cover" */
+ return g_strdup (_("Device cannot be used while the lid is closed"));
+ }
+ return NULL;
+}
+#endif
+
void
-gs_fwupd_app_set_from_device (GsApp *app, FwupdDevice *dev)
+gs_fwupd_app_set_from_device (GsApp *app,
+ FwupdClient *client,
+ FwupdDevice *dev)
{
GPtrArray *guids;
/* something can be done */
- if (fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_UPDATABLE))
+ if (fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_UPDATABLE)
+#if FWUPD_CHECK_VERSION(1, 8, 1)
+ || fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_UPDATABLE_HIDDEN)
+#endif
+ )
gs_app_set_state (app, GS_APP_STATE_UPDATABLE_LIVE);
/* only can be applied in systemd-offline */
@@ -113,8 +168,37 @@ gs_fwupd_app_set_from_device (GsApp *app, FwupdDevice *dev)
gs_app_set_description (app, GS_APP_QUALITY_NORMAL, tmp);
}
+#if FWUPD_CHECK_VERSION(1, 8, 1)
+ if (fwupd_device_get_problems (dev) != FWUPD_DEVICE_PROBLEM_NONE) {
+ g_autoptr(GString) problems = g_string_new (NULL);
+ for (guint i = 0; i < 64; i++) {
+ FwupdDeviceProblem problem = 1ull << i;
+ g_autofree gchar *tmp = NULL;
+ if (!fwupd_device_has_problem (dev, problem))
+ continue;
+ tmp = gs_fwupd_problem_to_string (client, dev, problem);
+ if (tmp == NULL)
+ continue;
+ if (problems->len)
+ g_string_append_c (problems, '\n');
+ g_string_append (problems, tmp);
+ }
+ if (problems->len)
+ gs_app_set_metadata (app, "GnomeSoftware::problems", problems->str);
+ else
+ gs_app_set_metadata (app, "GnomeSoftware::problems", NULL);
+ } else {
+ gs_app_set_metadata (app, "GnomeSoftware::problems", NULL);
+ }
+#endif
+
/* needs action */
- if (fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_NEEDS_BOOTLOADER))
+ if (fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_NEEDS_BOOTLOADER)
+#if FWUPD_CHECK_VERSION(1, 8, 1)
+ || fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_UPDATABLE_HIDDEN)
+ || fwupd_device_get_problems (dev) != FWUPD_DEVICE_PROBLEM_NONE
+#endif
+ )
gs_app_add_quirk (app, GS_APP_QUIRK_NEEDS_USER_ACTION);
else
gs_app_remove_quirk (app, GS_APP_QUIRK_NEEDS_USER_ACTION);
diff --git a/plugins/fwupd/gs-fwupd-app.h b/plugins/fwupd/gs-fwupd-app.h
index 5a3e9f23f..7296bbe86 100644
--- a/plugins/fwupd/gs-fwupd-app.h
+++ b/plugins/fwupd/gs-fwupd-app.h
@@ -24,6 +24,7 @@ void gs_fwupd_app_set_update_uri (GsApp *app,
void gs_fwupd_app_set_is_locked (GsApp *app,
gboolean is_locked);
void gs_fwupd_app_set_from_device (GsApp *app,
+ FwupdClient *client,
FwupdDevice *dev);
void gs_fwupd_app_set_from_release (GsApp *app,
FwupdRelease *rel);
diff --git a/plugins/fwupd/gs-plugin-fwupd.c b/plugins/fwupd/gs-plugin-fwupd.c
index b5d99b7f1..7f9b465d1 100644
--- a/plugins/fwupd/gs-plugin-fwupd.c
+++ b/plugins/fwupd/gs-plugin-fwupd.c
@@ -259,6 +259,9 @@ setup_connect_cb (GObject *source_object,
/* send our implemented feature set */
fwupd_client_set_feature_flags_async (self->client,
+#if FWUPD_CHECK_VERSION(1, 8, 1)
+ FWUPD_FEATURE_FLAG_SHOW_PROBLEMS |
+#endif
FWUPD_FEATURE_FLAG_UPDATE_ACTION |
FWUPD_FEATURE_FLAG_DETACH_ACTION,
cancellable, setup_features_cb,
@@ -330,6 +333,7 @@ static GsApp *
gs_plugin_fwupd_new_app_from_device (GsPlugin *plugin, FwupdDevice *dev)
{
FwupdRelease *rel = fwupd_device_get_release_default (dev);
+ GsPluginFwupd *self = GS_PLUGIN_FWUPD (plugin);
GsApp *app;
g_autofree gchar *id = NULL;
g_autoptr(GIcon) icon = NULL;
@@ -362,7 +366,7 @@ gs_plugin_fwupd_new_app_from_device (GsPlugin *plugin, FwupdDevice *dev)
/* create icon */
icon = g_themed_icon_new ("system-component-firmware");
gs_app_add_icon (app, icon);
- gs_fwupd_app_set_from_device (app, dev);
+ gs_fwupd_app_set_from_device (app, self->client, dev);
gs_fwupd_app_set_from_release (app, rel);
if (fwupd_release_get_appstream_id (rel) != NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]