Commit 152a72cd authored by Christian Hergert's avatar Christian Hergert
Browse files

flatpak: add helper to check for system dependencies

This will check for flatpak-builder on the host by using:

  which flatpak-builder

as that is more reliable than checking the package manager. We will still
use pkcon to install the package, but we don't need the D-Bus service to
check for it.
parent 26cfd375
......@@ -1069,3 +1069,84 @@ gbp_flatpak_application_addin_get_deploy_dir (GbpFlatpakApplicationAddin *self,
return NULL;
}
static void
gbp_flatpak_application_addin_check_sysdeps_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
IdeSubprocess *subprocess = (IdeSubprocess *)object;
g_autoptr(GTask) task = user_data;
g_autoptr(GError) error = NULL;
IDE_ENTRY;
g_return_if_fail (IDE_IS_SUBPROCESS (subprocess));
g_return_if_fail (G_IS_ASYNC_RESULT (result));
g_return_if_fail (G_IS_TASK (task));
if (!ide_subprocess_wait_check_finish (subprocess, result, &error))
g_task_return_error (task, g_steal_pointer (&error));
else
g_task_return_boolean (task, TRUE);
IDE_EXIT;
}
void
gbp_flatpak_application_addin_check_sysdeps_async (GbpFlatpakApplicationAddin *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_autoptr(IdeSubprocessLauncher) launcher = NULL;
g_autoptr(IdeSubprocess) subprocess = NULL;
g_autoptr(GTask) task = NULL;
g_autoptr(GError) error = NULL;
IDE_ENTRY;
g_return_if_fail (GBP_IS_FLATPAK_APPLICATION_ADDIN (self));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, gbp_flatpak_application_addin_check_sysdeps_async);
launcher = ide_subprocess_launcher_new (0);
ide_subprocess_launcher_set_run_on_host (launcher, TRUE);
ide_subprocess_launcher_push_argv (launcher, "which");
ide_subprocess_launcher_push_argv (launcher, "flatpak-builder");
subprocess = ide_subprocess_launcher_spawn (launcher, cancellable, &error);
if (subprocess == NULL)
{
g_task_return_error (task, g_steal_pointer (&error));
IDE_GOTO (failure);
}
ide_subprocess_wait_check_async (subprocess,
cancellable,
gbp_flatpak_application_addin_check_sysdeps_cb,
g_steal_pointer (&task));
failure:
IDE_EXIT;
}
gboolean
gbp_flatpak_application_addin_check_sysdeps_finish (GbpFlatpakApplicationAddin *self,
GAsyncResult *result,
GError **error)
{
gboolean ret;
IDE_ENTRY;
g_return_val_if_fail (GBP_IS_FLATPAK_APPLICATION_ADDIN (self), FALSE);
g_return_val_if_fail (G_IS_TASK (result), FALSE);
ret = g_task_propagate_boolean (G_TASK (result), error);
IDE_RETURN (ret);
}
......@@ -34,6 +34,13 @@ gboolean gbp_flatpak_application_addin_has_runtime
const gchar *id,
const gchar *arch,
const gchar *branch);
void gbp_flatpak_application_addin_check_sysdeps_async (GbpFlatpakApplicationAddin *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean gbp_flatpak_application_addin_check_sysdeps_finish (GbpFlatpakApplicationAddin *self,
GAsyncResult *result,
GError **error);
void gbp_flatpak_application_addin_install_runtime_async (GbpFlatpakApplicationAddin *self,
const gchar *runtime_id,
const gchar *arch,
......
......@@ -20,6 +20,7 @@
#include <glib/gi18n.h>
#include "gbp-flatpak-application-addin.h"
#include "gbp-flatpak-workbench-addin.h"
struct _GbpFlatpakWorkbenchAddin
......@@ -32,27 +33,27 @@ struct _GbpFlatpakWorkbenchAddin
};
static void
query_packages_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
check_sysdeps_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
GDBusConnection *bus = (GDBusConnection *)object;
GbpFlatpakApplicationAddin *app_addin = (GbpFlatpakApplicationAddin *)object;
g_autoptr(IdeWorkbenchMessage) message = user_data;
g_autoptr(GVariant) reply = NULL;
g_autoptr(GError) error = NULL;
gboolean has_sysdeps;
g_assert (G_IS_DBUS_CONNECTION (bus));
g_assert (GBP_IS_FLATPAK_APPLICATION_ADDIN (app_addin));
g_assert (G_IS_ASYNC_RESULT (result));
g_assert (IDE_IS_WORKBENCH_MESSAGE (message));
reply = g_dbus_connection_call_finish (bus, result, &error);
has_sysdeps = gbp_flatpak_application_addin_check_sysdeps_finish (app_addin, result, &error);
if (reply != NULL)
{
gboolean installed = FALSE;
#ifdef IDE_ENABLE_TRACE
if (error != NULL)
IDE_TRACE_MSG ("which flatpak-builder resulted in %s", error->message);
#endif
g_variant_get (reply, "(b)", &installed);
gtk_widget_set_visible (GTK_WIDGET (message), !installed);
}
gtk_widget_set_visible (GTK_WIDGET (message), has_sysdeps == FALSE);
}
static void
......@@ -60,7 +61,7 @@ gbp_flatpak_workbench_addin_load (IdeWorkbenchAddin *addin,
IdeWorkbench *workbench)
{
GbpFlatpakWorkbenchAddin *self = (GbpFlatpakWorkbenchAddin *)addin;
g_autoptr(GDBusConnection) bus = NULL;
GbpFlatpakApplicationAddin *app_addin;
IdeContext *context;
g_assert (GBP_IS_FLATPAK_WORKBENCH_ADDIN (self));
......@@ -82,23 +83,11 @@ gbp_flatpak_workbench_addin_load (IdeWorkbenchAddin *addin,
ide_workbench_message_add_action (self->message, _("Install"), "flatpak.install-flatpak-builder");
ide_workbench_push_message (workbench, self->message);
/*
* Discover if flatpak-builder is available, and if not, we will show the
* message bar to the user.
*/
if (NULL != (bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL)))
g_dbus_connection_call (bus,
"org.freedesktop.PackageKit",
"/org/freedesktop/PackageKit",
"org.freedesktop.PackageKit.Query",
"IsInstalled",
g_variant_new ("(ss)", "flatpak-builder", ""),
G_VARIANT_TYPE ("(b)"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
query_packages_cb,
g_object_ref (self->message));
app_addin = gbp_flatpak_application_addin_get_default ();
gbp_flatpak_application_addin_check_sysdeps_async (app_addin,
NULL,
check_sysdeps_cb,
g_object_ref (self->message));
}
static void
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment