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"); }
/** * gs_plugin_initialize: */ void gs_plugin_initialize (GsPlugin *plugin) { g_autoptr(GError) error = NULL; plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate); plugin->priv->settings = g_settings_new ("org.gnome.software"); plugin->priv->review_server = g_settings_get_string (plugin->priv->settings, "review-server"); /* get the machine+user ID hash value */ plugin->priv->user_hash = gs_utils_get_user_hash (&error); if (plugin->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 */ plugin->priv->distro = gs_os_release_get_name (&error); if (plugin->priv->distro == NULL) { g_warning ("Failed to get distro name: %s", error->message); plugin->priv->distro = g_strdup ("Unknown"); } }
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; }