[gnome-software] Use GsPluginLoaderAction to launch applications
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Use GsPluginLoaderAction to launch applications
- Date: Wed, 27 Jan 2016 10:11:51 +0000 (UTC)
commit 4a9df7d3bf544ee075ea02ba81d4880a78e536b0
Author: Richard Hughes <richard hughsie com>
Date: Wed Jan 27 09:24:44 2016 +0000
Use GsPluginLoaderAction to launch applications
I don't know why I created yet another plugin-loader action for this.
src/gs-cmd.c | 3 +-
src/gs-plugin-loader-sync.c | 48 ------------------
src/gs-plugin-loader-sync.h | 4 --
src/gs-plugin-loader.c | 114 ++-----------------------------------------
src/gs-plugin-loader.h | 9 +---
src/gs-plugin.h | 4 --
src/gs-shell-details.c | 5 +-
7 files changed, 11 insertions(+), 176 deletions(-)
---
diff --git a/src/gs-cmd.c b/src/gs-cmd.c
index 3e013d4..a5b4005 100644
--- a/src/gs-cmd.c
+++ b/src/gs-cmd.c
@@ -301,8 +301,9 @@ main (int argc, char **argv)
} else if (argc == 3 && g_strcmp0 (argv[1], "launch") == 0) {
app = gs_app_new (argv[2]);
for (i = 0; i < repeat; i++) {
- ret = gs_plugin_loader_app_launch (plugin_loader,
+ ret = gs_plugin_loader_app_action (plugin_loader,
app,
+ GS_PLUGIN_LOADER_ACTION_LAUNCH,
NULL,
&error);
if (!ret)
diff --git a/src/gs-plugin-loader-sync.c b/src/gs-plugin-loader-sync.c
index f50fc9b..254b8b9 100644
--- a/src/gs-plugin-loader-sync.c
+++ b/src/gs-plugin-loader-sync.c
@@ -515,54 +515,6 @@ gs_plugin_loader_app_refine (GsPluginLoader *plugin_loader,
}
/**
- * gs_plugin_loader_app_launch_finish_sync:
- **/
-static void
-gs_plugin_loader_app_launch_finish_sync (GsPluginLoader *plugin_loader,
- GAsyncResult *res,
- GsPluginLoaderHelper *helper)
-{
- helper->ret = gs_plugin_loader_app_launch_finish (plugin_loader,
- res,
- helper->error);
- g_main_loop_quit (helper->loop);
-}
-
-/**
- * gs_plugin_loader_app_launch:
- **/
-gboolean
-gs_plugin_loader_app_launch (GsPluginLoader *plugin_loader,
- GsApp *app,
- GCancellable *cancellable,
- GError **error)
-{
- GsPluginLoaderHelper helper;
-
- /* create temp object */
- helper.context = g_main_context_new ();
- helper.loop = g_main_loop_new (helper.context, FALSE);
- helper.error = error;
-
- g_main_context_push_thread_default (helper.context);
-
- /* run async method */
- gs_plugin_loader_app_launch_async (plugin_loader,
- app,
- cancellable,
- (GAsyncReadyCallback) gs_plugin_loader_app_launch_finish_sync,
- &helper);
- g_main_loop_run (helper.loop);
-
- g_main_context_pop_thread_default (helper.context);
-
- g_main_loop_unref (helper.loop);
- g_main_context_unref (helper.context);
-
- return helper.ret;
-}
-
-/**
* gs_plugin_loader_app_action_finish_sync:
**/
static void
diff --git a/src/gs-plugin-loader-sync.h b/src/gs-plugin-loader-sync.h
index 90d65c0..b1b88ec 100644
--- a/src/gs-plugin-loader-sync.h
+++ b/src/gs-plugin-loader-sync.h
@@ -71,10 +71,6 @@ gboolean gs_plugin_loader_app_refine (GsPluginLoader *plugin_loader,
GsPluginRefineFlags flags,
GCancellable *cancellable,
GError **error);
-gboolean gs_plugin_loader_app_launch (GsPluginLoader *plugin_loader,
- GsApp *app,
- GCancellable *cancellable,
- GError **error);
gboolean gs_plugin_loader_app_action (GsPluginLoader *plugin_loader,
GsApp *app,
GsPluginLoaderAction action,
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index c2e6ffe..92db90a 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -336,37 +336,6 @@ out:
}
/**
- * gs_plugin_loader_run_launch:
- **/
-static gboolean
-gs_plugin_loader_run_launch (GsPluginLoader *plugin_loader,
- GsApp *app,
- GCancellable *cancellable,
- GError **error)
-{
- GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
- GsPluginLaunchFunc plugin_func = NULL;
- GsPlugin *plugin;
- gboolean ret = TRUE;
- guint i;
-
- /* run each plugin */
- for (i = 0; i < priv->plugins->len; i++) {
- plugin = g_ptr_array_index (priv->plugins, i);
- if (!plugin->enabled)
- continue;
- if (!g_module_symbol (plugin->module,
- "gs_plugin_launch",
- (gpointer *) &plugin_func))
- continue;
- ret = plugin_func (plugin, app, cancellable, error);
- if (!ret)
- return FALSE;
- }
- return TRUE;
-}
-
-/**
* gs_plugin_loader_run_results_plugin:
**/
static gboolean
@@ -2332,84 +2301,6 @@ gs_plugin_loader_app_refine_finish (GsPluginLoader *plugin_loader,
/******************************************************************************/
-/**
- * gs_plugin_loader_app_launch_thread_cb:
- **/
-static void
-gs_plugin_loader_app_launch_thread_cb (GTask *task,
- gpointer object,
- gpointer task_data,
- GCancellable *cancellable)
-{
- GError *error = NULL;
- GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) task_data;
- GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
- gboolean ret;
-
- ret = gs_plugin_loader_run_launch (plugin_loader,
- state->app,
- cancellable,
- &error);
- if (!ret) {
- g_task_return_error (task, error);
- return;
- }
-
- /* success */
- g_task_return_boolean (task, TRUE);
-}
-
-/**
- * gs_plugin_loader_app_launch_async:
- *
- * This method calls all plugins that implement the gs_plugin_launch()
- * function.
- **/
-void
-gs_plugin_loader_app_launch_async (GsPluginLoader *plugin_loader,
- GsApp *app,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- GsPluginLoaderAsyncState *state;
- g_autoptr(GTask) task = NULL;
-
- g_return_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader));
- g_return_if_fail (GS_IS_APP (app));
- g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
-
- /* save state */
- state = g_slice_new0 (GsPluginLoaderAsyncState);
- state->app = g_object_ref (app);
-
- /* run in a thread */
- task = g_task_new (plugin_loader, cancellable, callback, user_data);
- g_task_set_task_data (task, state, (GDestroyNotify) gs_plugin_loader_free_async_state);
- g_task_set_return_on_cancel (task, TRUE);
- g_task_run_in_thread (task, gs_plugin_loader_app_launch_thread_cb);
-}
-
-/**
- * gs_plugin_loader_app_launch_finish:
- *
- * Return value: success
- **/
-gboolean
-gs_plugin_loader_app_launch_finish (GsPluginLoader *plugin_loader,
- GAsyncResult *res,
- GError **error)
-{
- g_return_val_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader), FALSE);
- g_return_val_if_fail (G_IS_TASK (res), FALSE);
- g_return_val_if_fail (g_task_is_valid (res, plugin_loader), FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
-
- return g_task_propagate_boolean (G_TASK (res), error);
-}
-
-/******************************************************************************/
-
static gboolean
emit_pending_apps_idle (gpointer loader)
{
@@ -2725,6 +2616,11 @@ gs_plugin_loader_app_action_async (GsPluginLoader *plugin_loader,
state->state_success = AS_APP_STATE_UNKNOWN;
state->state_failure = AS_APP_STATE_UNKNOWN;
break;
+ case GS_PLUGIN_LOADER_ACTION_LAUNCH:
+ state->function_name = "gs_plugin_launch";
+ state->state_success = AS_APP_STATE_UNKNOWN;
+ state->state_failure = AS_APP_STATE_UNKNOWN;
+ break;
default:
g_assert_not_reached ();
break;
diff --git a/src/gs-plugin-loader.h b/src/gs-plugin-loader.h
index 133760c..73eaeab 100644
--- a/src/gs-plugin-loader.h
+++ b/src/gs-plugin-loader.h
@@ -59,6 +59,7 @@ typedef enum {
GS_PLUGIN_LOADER_ACTION_SET_RATING,
GS_PLUGIN_LOADER_ACTION_UPGRADE_DOWNLOAD,
GS_PLUGIN_LOADER_ACTION_UPGRADE_TRIGGER,
+ GS_PLUGIN_LOADER_ACTION_LAUNCH,
GS_PLUGIN_LOADER_ACTION_LAST
} GsPluginLoaderAction;
@@ -198,14 +199,6 @@ void gs_plugin_loader_app_refine_async (GsPluginLoader
*plugin_loader,
gboolean gs_plugin_loader_app_refine_finish (GsPluginLoader *plugin_loader,
GAsyncResult *res,
GError **error);
-void gs_plugin_loader_app_launch_async (GsPluginLoader *plugin_loader,
- GsApp *app,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-gboolean gs_plugin_loader_app_launch_finish (GsPluginLoader *plugin_loader,
- GAsyncResult *res,
- GError **error);
void gs_plugin_loader_app_action_async (GsPluginLoader *plugin_loader,
GsApp *app,
GsPluginLoaderAction a,
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index b37fb7f..c737dc8 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -142,10 +142,6 @@ typedef gboolean (*GsPluginRefineFunc) (GsPlugin *plugin,
GsPluginRefineFlags flags,
GCancellable *cancellable,
GError **error);
-typedef gboolean (*GsPluginLaunchFunc) (GsPlugin *plugin,
- GsApp *app,
- GCancellable *cancellable,
- GError **error);
typedef gboolean (*GsPluginRefreshFunc ) (GsPlugin *plugin,
guint cache_age,
GsPluginRefreshFlags flags,
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 9246ffc..de6c926 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -1199,7 +1199,7 @@ gs_shell_details_app_launch_cb (GObject *source,
{
GsShellDetails *self = GS_SHELL_DETAILS (user_data);
g_autoptr(GError) error = NULL;
- if (!gs_plugin_loader_app_launch_finish (self->plugin_loader, res, &error)) {
+ if (!gs_plugin_loader_app_action_finish (self->plugin_loader, res, &error)) {
g_warning ("failed to launch GsApp: %s", error->message);
return;
}
@@ -1211,8 +1211,9 @@ gs_shell_details_app_launch_cb (GObject *source,
static void
gs_shell_details_app_launch_button_cb (GtkWidget *widget, GsShellDetails *self)
{
- gs_plugin_loader_app_launch_async (self->plugin_loader,
+ gs_plugin_loader_app_action_async (self->plugin_loader,
self->app,
+ GS_PLUGIN_LOADER_ACTION_LAUNCH,
self->cancellable,
gs_shell_details_app_launch_cb,
self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]