[gnome-software] Add a proxy app update example to the dummy plugin
- From: Joaquim Manuel Pereira Rocha <jrocha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Add a proxy app update example to the dummy plugin
- Date: Thu, 15 Dec 2016 11:19:04 +0000 (UTC)
commit 5e146f4af40b66e222d02127c5656960cd24819b
Author: Joaquim Rocha <jrocha endlessm com>
Date: Wed Dec 14 21:23:10 2016 +0100
Add a proxy app update example to the dummy plugin
Thus dummy proxy app has two updatable related apps. So each one will
affect 50% of the proxy app's progress.
src/gs-self-test.c | 9 +++++-
src/plugins/gs-plugin-dummy.c | 61 ++++++++++++++++++++++++++++++++++++-----
2 files changed, 62 insertions(+), 8 deletions(-)
---
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index fbc7af9..f667db3 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -580,7 +580,7 @@ gs_plugin_loader_updates_func (GsPluginLoader *plugin_loader)
g_assert (list != NULL);
/* make sure there are two entries */
- g_assert_cmpint (gs_app_list_length (list), ==, 2);
+ g_assert_cmpint (gs_app_list_length (list), ==, 3);
app = gs_app_list_index (list, 0);
g_assert_cmpstr (gs_app_get_id (app), ==, "chiron.desktop");
g_assert_cmpint (gs_app_get_kind (app), ==, AS_APP_KIND_DESKTOP);
@@ -596,6 +596,13 @@ gs_plugin_loader_updates_func (GsPluginLoader *plugin_loader)
g_assert_cmpint (gs_app_get_kind (app), ==, AS_APP_KIND_OS_UPDATE);
g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_UPDATABLE);
g_assert_cmpint (gs_app_get_related(app)->len, ==, 2);
+
+ /* get the virtual non-apps OS update */
+ app = gs_app_list_index (list, 2);
+ g_assert_cmpstr (gs_app_get_id (app), ==, "proxy.desktop");
+ g_assert (gs_app_has_quirk (app, AS_APP_QUIRK_IS_PROXY));
+ g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_UPDATABLE_LIVE);
+ g_assert_cmpint (gs_app_get_related(app)->len, ==, 2);
}
static void
diff --git a/src/plugins/gs-plugin-dummy.c b/src/plugins/gs-plugin-dummy.c
index 80cf496..f4a4686 100644
--- a/src/plugins/gs-plugin-dummy.c
+++ b/src/plugins/gs-plugin-dummy.c
@@ -230,6 +230,7 @@ gs_plugin_add_updates (GsPlugin *plugin,
GError **error)
{
GsApp *app;
+ GsApp *proxy;
g_autoptr(AsIcon) ic = NULL;
/* update UI as this might take some time */
@@ -285,6 +286,40 @@ gs_plugin_add_updates (GsPlugin *plugin,
gs_app_list_add (list, app);
g_object_unref (app);
+ /* add a proxy app update */
+ proxy = gs_app_new ("proxy.desktop");
+ gs_app_set_name (proxy, GS_APP_QUALITY_NORMAL, "Proxy");
+ gs_app_set_summary (proxy, GS_APP_QUALITY_NORMAL, "A proxy app");
+ gs_app_set_update_details (proxy, "Update all related apps.");
+ gs_app_set_update_urgency (proxy, AS_URGENCY_KIND_HIGH);
+ gs_app_add_icon (proxy, ic);
+ gs_app_set_kind (proxy, AS_APP_KIND_DESKTOP);
+ gs_app_add_quirk (proxy, AS_APP_QUIRK_IS_PROXY);
+ gs_app_set_state (proxy, AS_APP_STATE_UPDATABLE_LIVE);
+ gs_app_set_management_plugin (proxy, gs_plugin_get_name (plugin));
+ gs_app_list_add (list, proxy);
+ g_object_unref (proxy);
+
+ /* add a proxy related app */
+ app = gs_app_new ("proxy-related-app.desktop");
+ gs_app_set_name (app, GS_APP_QUALITY_NORMAL, "Related app");
+ gs_app_set_summary (app, GS_APP_QUALITY_NORMAL, "A related app");
+ gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
+ gs_app_set_state (app, AS_APP_STATE_UPDATABLE_LIVE);
+ gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
+ gs_app_add_related (proxy, app);
+ g_object_unref (app);
+
+ /* add another proxy related app */
+ app = gs_app_new ("proxy-another-related-app.desktop");
+ gs_app_set_name (app, GS_APP_QUALITY_NORMAL, "Another Related app");
+ gs_app_set_summary (app, GS_APP_QUALITY_NORMAL, "A related app");
+ gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
+ gs_app_set_state (app, AS_APP_STATE_UPDATABLE_LIVE);
+ gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
+ gs_app_add_related (proxy, app);
+ g_object_unref (app);
+
return TRUE;
}
@@ -406,13 +441,25 @@ gs_plugin_update_app (GsPlugin *plugin,
gs_plugin_get_name (plugin)) != 0)
return TRUE;
- /* always fail */
- g_set_error_literal (error,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_DOWNLOAD_FAILED,
- "no network connection is available");
- gs_utils_error_add_unique_id (error, priv->cached_origin);
- return FALSE;
+ if (!g_str_has_prefix (gs_app_get_id (app), "proxy")) {
+ /* always fail */
+ g_set_error_literal (error,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_DOWNLOAD_FAILED,
+ "no network connection is available");
+ gs_utils_error_add_unique_id (error, priv->cached_origin);
+ return FALSE;
+ }
+
+ /* simulate an update for 4 seconds */
+ gs_app_set_state (app, AS_APP_STATE_INSTALLING);
+ for (guint i = 1; i <= 4; ++i) {
+ gs_app_set_progress (app, 25 * i);
+ sleep (1);
+ }
+ gs_app_set_state (app, AS_APP_STATE_INSTALLED);
+
+ return TRUE;
}
gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]