[gnome-software/wip/temp/ubuntu-xenial-rebased-corrected: 241/331] Only request appstream refresh while window is visible
- From: William Hua <williamhua src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/temp/ubuntu-xenial-rebased-corrected: 241/331] Only request appstream refresh while window is visible
- Date: Wed, 4 May 2016 14:18:47 +0000 (UTC)
commit 0b0a2fb7252306bb3084678fbcc1927fcc87eef1
Author: William Hua <william hua canonical com>
Date: Fri Apr 15 08:00:38 2016 -0400
Only request appstream refresh while window is visible
src/gs-application.c | 82 +++++++++++++++++++++++++++++++-
src/plugins/gs-plugin-appstream.c | 96 ++++++------------------------------
2 files changed, 97 insertions(+), 81 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 7ef3eef..cad567f 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -243,15 +243,95 @@ gs_application_dbus_unregister (GApplication *application,
}
static void
+refreshed_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GsPluginLoader *loader = GS_PLUGIN_LOADER (source_object);
+
+ if (gs_plugin_loader_refresh_finish (loader, res, NULL)) {
+ gs_plugin_loader_refresh_async (loader,
+ 0,
+ GS_PLUGIN_REFRESH_FLAGS_UPDATES,
+ NULL,
+ NULL,
+ NULL);
+ }
+}
+
+static void
+start_refresh (GsApplication *app)
+{
+ g_action_group_activate_action (G_ACTION_GROUP (app),
+ "set-mode",
+ g_variant_new_string ("updates"));
+
+ gs_plugin_loader_refresh_async (gs_application_get_plugin_loader (app),
+ 0,
+ GS_PLUGIN_REFRESH_FLAGS_UPDATES,
+ NULL,
+ refreshed_cb,
+ app);
+}
+
+#define APP_INFO_PATH "/var/lib/app-info"
+
+static gboolean
+needs_refresh (void)
+{
+ g_autoptr(GDir) dir = g_dir_open (APP_INFO_PATH, 0, NULL);
+
+ return dir == NULL || g_dir_read_name (dir) == NULL;
+}
+
+static gboolean
+ask_refresh (gpointer user_data)
+{
+ GsApplication *app = user_data;
+ GtkWindow *parent;
+ GtkWidget *dialog;
+
+ parent = gtk_application_get_active_window (GTK_APPLICATION (app));
+
+ if (gtk_widget_is_visible (GTK_WIDGET (parent))) {
+ dialog = gtk_message_dialog_new (parent,
+ GTK_DIALOG_MODAL |
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_YES_NO,
+ _("An update is needed to show all installable apps.
Download now?"));
+
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES)
+ start_refresh (app);
+
+ gtk_widget_destroy (dialog);
+ }
+
+ return G_SOURCE_REMOVE;
+}
+
+static void
+first_run_dialog_destroyed_cb (GtkWidget *object,
+ gpointer user_data)
+{
+ g_signal_handlers_disconnect_by_data (object, user_data);
+
+ if (needs_refresh ())
+ gdk_threads_add_idle (ask_refresh, user_data);
+}
+
+static void
gs_application_show_first_run_dialog (GsApplication *app)
{
GtkWidget *dialog;
if (g_settings_get_boolean (app->settings, "first-run") == TRUE) {
dialog = gs_first_run_dialog_new ();
+ g_signal_connect (dialog, "destroy", G_CALLBACK (first_run_dialog_destroyed_cb), app);
gs_shell_modal_dialog_present (app->shell, GTK_DIALOG (dialog));
g_settings_set_boolean (app->settings, "first-run", FALSE);
- }
+ } else if (needs_refresh ())
+ gdk_threads_add_idle (ask_refresh, app);
}
static void
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index eb7fba3..8d3dfe5 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -67,6 +67,22 @@ gs_plugin_appstream_store_changed_cb (AsStore *store, GsPlugin *plugin)
gs_plugin_updates_changed (plugin);
}
+static gboolean gs_plugin_appstream_startup (GsPlugin *plugin, GError **error);
+
+gboolean
+gs_plugin_refresh (GsPlugin *plugin,
+ guint cache_age,
+ GsPluginRefreshFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ plugin->priv->done_init = FALSE;
+ gs_plugin_appstream_startup (plugin, NULL);
+ gs_plugin_updates_changed (plugin);
+
+ return TRUE;
+}
+
/**
* gs_plugin_initialize:
*/
@@ -149,83 +165,6 @@ gs_plugin_appstream_get_origins_hash (GPtrArray *array)
return origins;
}
-#define APP_INFO_PATH "/var/lib/app-info"
-#define REFRESH_TIMEOUT 1000
-
-static gboolean
-needs_refresh (GsPlugin *plugin)
-{
- g_autoptr(GDir) dir = g_dir_open (APP_INFO_PATH, 0, NULL);
-
- return dir == NULL || g_dir_read_name (dir) == NULL;
-}
-
-static gboolean gs_plugin_appstream_startup (GsPlugin *plugin,
- GError **error);
-
-static void
-refreshed_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- GsPlugin *plugin = user_data;
- GsPluginLoader *loader = GS_PLUGIN_LOADER (source_object);
-
- if (gs_plugin_loader_refresh_finish (loader, res, NULL)) {
- plugin->priv->done_init = FALSE;
- gs_plugin_appstream_startup (plugin, NULL);
- gs_plugin_updates_changed (plugin);
- }
-}
-
-static void
-start_refresh (GsPlugin *plugin)
-{
- GApplication *application;
- GsPluginLoader *loader;
-
- application = g_application_get_default ();
-
- g_action_group_activate_action (G_ACTION_GROUP (application), "set-mode", g_variant_new_string
("updates"));
-
- loader = gs_application_get_plugin_loader (GS_APPLICATION (application));
-
- gs_plugin_loader_refresh_async (loader,
- 0,
- GS_PLUGIN_REFRESH_FLAGS_UPDATES,
- NULL,
- refreshed_cb,
- plugin);
-}
-
-static gboolean
-ask_refresh (gpointer user_data)
-{
- GApplication *application;
- GtkWindow *parent;
- GtkWidget *dialog;
-
- application = g_application_get_default ();
-
- parent = gtk_application_get_active_window (GTK_APPLICATION (application));
-
- if (gtk_widget_is_visible (GTK_WIDGET (parent))) {
- dialog = gtk_message_dialog_new (parent,
- GTK_DIALOG_MODAL |
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_QUESTION,
- GTK_BUTTONS_YES_NO,
- _("An update is needed to show all installable apps.
Download now?"));
-
- if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES)
- start_refresh (user_data);
-
- gtk_widget_destroy (dialog);
- }
-
- return G_SOURCE_REMOVE;
-}
-
/**
* gs_plugin_setup:
*/
@@ -241,9 +180,6 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
guint i;
g_autoptr(GHashTable) origins = NULL;
- if (needs_refresh (plugin))
- gdk_threads_add_timeout (REFRESH_TIMEOUT, ask_refresh, plugin);
-
/* Parse the XML */
if (g_getenv ("GNOME_SOFTWARE_PREFER_LOCAL") != NULL) {
as_store_set_add_flags (plugin->priv->store,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]