static gboolean gs_plugin_fwupd_modify_source (GsPlugin *plugin, GsApp *app, gboolean enabled, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); const gchar *remote_id = gs_app_get_metadata_item (app, "fwupd::remote-id"); if (remote_id == NULL) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED, "not enough data for fwupd %s", gs_app_get_unique_id (app)); return FALSE; } gs_app_set_state (app, enabled ? AS_APP_STATE_INSTALLING : AS_APP_STATE_REMOVING); if (!fwupd_client_modify_remote (priv->client, remote_id, "Enabled", enabled ? "true" : "false", cancellable, error)) { gs_app_set_state_recover (app); return FALSE; } gs_app_set_state (app, enabled ? AS_APP_STATE_INSTALLED : AS_APP_STATE_AVAILABLE); return TRUE; }
static void gs_plugin_fwupd_notify_status_cb (GObject *object, GParamSpec *pspec, GsPlugin *plugin) { GsPluginData *priv = gs_plugin_get_data (plugin); /* nothing in progress */ if (priv->app_current == NULL) { g_debug ("fwupd status: %s", fwupd_status_to_string (fwupd_client_get_status (priv->client))); return; } g_debug ("fwupd status for %s: %s", gs_app_get_unique_id (priv->app_current), fwupd_status_to_string (fwupd_client_get_status (priv->client))); switch (fwupd_client_get_status (priv->client)) { case FWUPD_STATUS_DECOMPRESSING: case FWUPD_STATUS_DEVICE_RESTART: case FWUPD_STATUS_DEVICE_WRITE: case FWUPD_STATUS_DEVICE_VERIFY: gs_app_set_state (priv->app_current, AS_APP_STATE_INSTALLING); break; case FWUPD_STATUS_IDLE: g_clear_object (&priv->app_current); break; default: break; } }
gboolean gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); /* add source */ priv->cached_origin = gs_app_new (gs_plugin_get_name (plugin)); gs_app_set_kind (priv->cached_origin, AS_APP_KIND_SOURCE); gs_app_set_bundle_kind (priv->cached_origin, AS_BUNDLE_KIND_CABINET); /* add the source to the plugin cache which allows us to match the * unique ID to a GsApp when creating an event */ gs_plugin_cache_add (plugin, gs_app_get_unique_id (priv->cached_origin), priv->cached_origin); /* register D-Bus errors */ fwupd_error_quark (); g_signal_connect (priv->client, "changed", G_CALLBACK (gs_plugin_fwupd_changed_cb), plugin); g_signal_connect (priv->client, "device-added", G_CALLBACK (gs_plugin_fwupd_device_changed_cb), plugin); g_signal_connect (priv->client, "device-removed", G_CALLBACK (gs_plugin_fwupd_device_changed_cb), plugin); g_signal_connect (priv->client, "device-changed", G_CALLBACK (gs_plugin_fwupd_device_changed_cb), plugin); g_signal_connect (priv->client, "notify::percentage", G_CALLBACK (gs_plugin_fwupd_notify_percentage_cb), plugin); g_signal_connect (priv->client, "notify::status", G_CALLBACK (gs_plugin_fwupd_notify_status_cb), plugin); return TRUE; }
/** * gs_utils_error_add_unique_id: * @error: a #GError * @app: a #GsApp * * Adds a unique ID prefix to the error. * * Since: 3.22 **/ void gs_utils_error_add_unique_id (GError **error, GsApp *app) { g_return_if_fail (GS_APP (app)); if (error == NULL || *error == NULL) return; g_prefix_error (error, "[%s] ", gs_app_get_unique_id (app)); }
void gs_plugin_initialize (GsPlugin *plugin) { GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData)); g_autoptr(GError) error = NULL; g_autoptr(GsOsRelease) os_release = NULL; priv->settings = g_settings_new ("org.gnome.software"); priv->review_server = g_settings_get_string (priv->settings, "review-server"); priv->ratings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_array_unref); /* get the machine+user ID hash value */ priv->user_hash = gs_utils_get_user_hash (&error); if (priv->user_hash == NULL) { g_warning ("Failed to get machine+user hash: %s", error->message); return; } /* get the distro name (e.g. 'Fedora') but allow a fallback */ os_release = gs_os_release_new (&error); if (os_release != NULL) { priv->distro = g_strdup (gs_os_release_get_name (os_release)); if (priv->distro == NULL) { g_warning ("no distro name specified"); priv->distro = g_strdup ("Unknown"); } } else { g_warning ("failed to get distro name: %s", error->message); priv->distro = g_strdup ("Unknown"); } /* add source */ priv->cached_origin = gs_app_new (gs_plugin_get_name (plugin)); gs_app_set_kind (priv->cached_origin, AS_APP_KIND_SOURCE); gs_app_set_origin_hostname (priv->cached_origin, priv->review_server); gs_app_set_origin_ui (priv->cached_origin, "Open Desktop Review Server"); /* add the source to the plugin cache which allows us to match the * unique ID to a GsApp when creating an event */ gs_plugin_cache_add (plugin, gs_app_get_unique_id (priv->cached_origin), priv->cached_origin); /* need application IDs and version */ gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream"); gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "flatpak-system"); gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "flatpak-user"); /* set name of MetaInfo file */ gs_plugin_set_appstream_id (plugin, "org.gnome.Software.Plugin.Odrs"); }
static AsApp * get_installed_appstream_app (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { AsApp *as_app; GsPluginData *priv = gs_plugin_get_data (plugin); const char *deploy_dir; g_autoptr(AsStore) store = NULL; g_autoptr(FlatpakInstalledRef) ref = NULL; g_autoptr(GFile) appstream_file = NULL; g_autofree char *appstream_xml = NULL; g_autofree char *appstream_path = NULL; ref = flatpak_installation_get_installed_ref (priv->installation, FLATPAK_REF_KIND_APP, gs_app_get_flatpak_name (app), gs_app_get_flatpak_arch (app), gs_app_get_flatpak_branch (app), cancellable, error); if (!ref) return NULL; deploy_dir = flatpak_installed_ref_get_deploy_dir (ref); appstream_xml = g_strdup_printf ("%s.appdata.xml", gs_app_get_flatpak_name (app)); appstream_path = g_build_filename (deploy_dir, "files", "share", "app-info", "xmls", appstream_xml, NULL); appstream_file = g_file_new_for_path (appstream_path); store = as_store_new (); as_store_set_add_flags (store, AS_STORE_ADD_FLAG_USE_UNIQUE_ID | AS_STORE_ADD_FLAG_USE_MERGE_HEURISTIC); if (!as_store_from_file (store, appstream_file, NULL, cancellable, error)) return NULL; as_app = as_store_get_app_by_id (store, gs_app_get_id (app)); if (!as_app) g_set_error (error, AS_STORE_ERROR, AS_STORE_ERROR_FAILED, "Failed to get app %s from its own installation " "AppStream file.", gs_app_get_unique_id (app)); return g_object_ref (as_app); }
gboolean gs_plugin_refine (GsPlugin *plugin, GsAppList *list, GsPluginRefineFlags flags, GCancellable *cancellable, GError **error) { g_autoptr(GsApp) app = NULL; g_autoptr(GsAppList) os_updates = gs_app_list_new (); /* not from get_updates() */ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_DETAILS) == 0) return TRUE; /* do we have any packages left that are not apps? */ for (guint i = 0; i < gs_app_list_length (list); i++) { GsApp *app_tmp = gs_app_list_index (list, i); if (gs_plugin_generic_updates_merge_os_update (app_tmp)) gs_app_list_add (os_updates, app_tmp); } if (gs_app_list_length (os_updates) == 0) return TRUE; /* create new meta object */ app = gs_plugin_generic_updates_get_os_update (plugin); for (guint i = 0; i < gs_app_list_length (os_updates); i++) { GsApp *app_tmp = gs_app_list_index (os_updates, i); const gchar *id = gs_app_get_unique_id (app_tmp); if (id == NULL) id = gs_app_get_source_default (app_tmp); g_debug ("moving %s to parent %s", id, gs_app_get_unique_id (app)); gs_app_add_related (app, app_tmp); gs_app_list_remove (list, app_tmp); } gs_app_list_add (list, app); return TRUE; }
static void gs_plugin_fwupd_notify_percentage_cb (GObject *object, GParamSpec *pspec, GsPlugin *plugin) { GsPluginData *priv = gs_plugin_get_data (plugin); /* nothing in progress */ if (priv->app_current == NULL) { g_debug ("fwupd percentage: %u%%", fwupd_client_get_percentage (priv->client)); return; } g_debug ("fwupd percentage for %s: %u%%", gs_app_get_unique_id (priv->app_current), fwupd_client_get_percentage (priv->client)); gs_app_set_progress (priv->app_current, fwupd_client_get_percentage (priv->client)); }
static gboolean setup_ext_runtime_version (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error) { const char *runtime_version; g_autoptr(GError) local_error = NULL; g_autoptr(AsApp) as_app = NULL; if (!app_is_legacy_external_app (app)) return TRUE; as_app = get_installed_appstream_app (plugin, app, cancellable, &local_error); if (!as_app) { g_warning ("Failed to get AsApp from installed AppStream " "data of app '%s': %s", gs_app_get_unique_id (app), local_error->message); g_propagate_error (error, g_steal_pointer (&local_error)); return FALSE; } /* get the runtime version that is set in the installed AppStream data */ runtime_version = as_app_get_metadata_item (as_app, LEGACY_RUNTIME_MTD_KEY); /* we setup the version of the external runtime used by this external * app so it is later used by "external-apps-cleaner" plugin when * removing those runtimes; we use a new key and not the one that is * already set in the metadata so we verify that this key has been * set by this plugin (and thus, by what was installed) and not by * the general AppStream data */ gs_app_set_metadata (app, LEGACY_RUNTIME_INSTALLED_MTD_KEY, NULL); gs_app_set_metadata (app, LEGACY_RUNTIME_INSTALLED_MTD_KEY, runtime_version); return TRUE; }
gboolean gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); const gchar *verstr = NULL; gchar *endptr = NULL; g_autoptr(GFile) file = NULL; g_autoptr(GsOsRelease) os_release = NULL; /* get the file to cache */ priv->cachefn = gs_utils_get_cache_filename ("upgrades", "fedora.json", GS_UTILS_CACHE_FLAG_WRITEABLE, error); if (priv->cachefn == NULL) return FALSE; /* watch this in case it is changed by the user */ file = g_file_new_for_path (priv->cachefn); priv->cachefn_monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, cancellable, error); if (priv->cachefn_monitor == NULL) return FALSE; g_signal_connect (priv->cachefn_monitor, "changed", G_CALLBACK (gs_plugin_fedora_distro_upgrades_changed_cb), plugin); /* read os-release for the current versions */ os_release = gs_os_release_new (error); if (os_release == NULL) return FALSE; priv->os_name = g_strdup (gs_os_release_get_name (os_release)); if (priv->os_name == NULL) return FALSE; verstr = gs_os_release_get_version_id (os_release); if (verstr == NULL) return FALSE; /* parse the version */ priv->os_version = g_ascii_strtoull (verstr, &endptr, 10); if (endptr == verstr || priv->os_version > G_MAXUINT) { g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_INVALID_FORMAT, "Failed parse VERSION_ID: %s", verstr); return FALSE; } /* add source */ priv->cached_origin = gs_app_new (gs_plugin_get_name (plugin)); gs_app_set_kind (priv->cached_origin, AS_APP_KIND_SOURCE); gs_app_set_origin_ui (priv->cached_origin, "Fedora Project PkgDb"); gs_app_set_origin_hostname (priv->cached_origin, FEDORA_PKGDB_COLLECTIONS_API_URI); /* add the source to the plugin cache which allows us to match the * unique ID to a GsApp when creating an event */ gs_plugin_cache_add (plugin, gs_app_get_unique_id (priv->cached_origin), priv->cached_origin); /* success */ return TRUE; }