[gnome-builder] update-manager: add update manager plugin
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] update-manager: add update manager plugin
- Date: Thu, 16 Jan 2020 22:55:49 +0000 (UTC)
commit 5dce429c34df868bff285ce4a116cd874103dcf3
Author: Christian Hergert <chergert redhat com>
Date: Thu Jan 16 14:41:04 2020 -0800
update-manager: add update manager plugin
This provides a notification when there is an update to Builder. The
notification will be displayed to the user on the current workbench,
including an action to update Builder automatically using libportal.
build-aux/flatpak/org.gnome.Builder.json | 15 ++
meson_options.txt | 1 +
src/plugins/meson.build | 2 +
.../update-manager/gbp-update-manager-app-addin.c | 296 +++++++++++++++++++++
.../update-manager/gbp-update-manager-app-addin.h | 31 +++
src/plugins/update-manager/meson.build | 20 ++
src/plugins/update-manager/update-manager-plugin.c | 36 +++
.../update-manager/update-manager.gresource.xml | 6 +
src/plugins/update-manager/update-manager.plugin | 10 +
9 files changed, 417 insertions(+)
---
diff --git a/build-aux/flatpak/org.gnome.Builder.json b/build-aux/flatpak/org.gnome.Builder.json
index 94bac6212..c7f1cd0ca 100644
--- a/build-aux/flatpak/org.gnome.Builder.json
+++ b/build-aux/flatpak/org.gnome.Builder.json
@@ -601,6 +601,21 @@
}
]
},
+ {
+ "name" : "libportal",
+ "config-opts" : [
+ "--libdir=/app/lib",
+ "--buildtype=debugoptimized"
+ ],
+ "buildsystem" : "meson",
+ "builddir" : true,
+ "sources" : [
+ {
+ "type" : "git",
+ "url" : "https://github.com/flatpak/libportal.git"
+ }
+ ]
+ },
{
"name" : "gnome-builder",
"buildsystem" : "meson",
diff --git a/meson_options.txt b/meson_options.txt
index 0e131f2b5..5d5288ac5 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -72,6 +72,7 @@ option('plugin_stylelint', type: 'boolean')
option('plugin_sysprof', type: 'boolean')
option('plugin_sysroot', type: 'boolean')
option('plugin_todo', type: 'boolean')
+option('plugin_update_manager', type: 'boolean')
option('plugin_vala', type: 'boolean', value: false)
option('plugin_vagrant', type: 'boolean', value: false)
option('plugin_valgrind', type: 'boolean')
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index 316fea869..72794c712 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -119,6 +119,7 @@ subdir('terminal')
subdir('testui')
subdir('todo')
subdir('trim-spaces')
+subdir('update-manager')
subdir('vagrant')
subdir('vala-pack')
subdir('valgrind')
@@ -188,6 +189,7 @@ status += [
'Sysprof ............... : @0@'.format(get_option('plugin_sysprof')),
'Sysroot ............... : @0@'.format(get_option('plugin_sysroot')),
'Todo .................. : @0@'.format(get_option('plugin_todo')),
+ 'Update Manager ........ : @0@'.format(get_option('plugin_update_manager')),
'Vala Language Server... : @0@'.format(get_option('plugin_gvls')),
'Vala Pack ............. : @0@'.format(get_option('plugin_vala')),
'Vagrant ............... : @0@'.format(get_option('plugin_vagrant')),
diff --git a/src/plugins/update-manager/gbp-update-manager-app-addin.c
b/src/plugins/update-manager/gbp-update-manager-app-addin.c
new file mode 100644
index 000000000..cba2cf811
--- /dev/null
+++ b/src/plugins/update-manager/gbp-update-manager-app-addin.c
@@ -0,0 +1,296 @@
+/* gbp-update-manager-app-addin.c
+ *
+ * Copyright 2020 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-update-manager-app-addin"
+
+#include "config.h"
+
+#include <libportal/portal.h>
+#include <glib/gi18n.h>
+
+#include "gbp-update-manager-app-addin.h"
+
+struct _GbpUpdateManagerAppAddin
+{
+ GObject parent_instance;
+ IdeApplication *app;
+ XdpPortal *portal;
+ GCancellable *cancellable;
+ IdeNotification *progress_notif;
+ IdeNotification *update_notif;
+};
+
+static void
+on_update_install_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ XdpPortal *portal = (XdpPortal *)object;
+ g_autoptr(GbpUpdateManagerAppAddin) self = user_data;
+ g_autoptr(GError) error = NULL;
+
+ IDE_ENTRY;
+
+ g_assert (XDP_IS_PORTAL (portal));
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (GBP_IS_UPDATE_MANAGER_APP_ADDIN (self));
+
+ if (!xdp_portal_update_install_finish (portal, result, &error))
+ g_warning ("Failed to update Builder: %s", error->message);
+
+ if (self->progress_notif)
+ {
+ ide_notification_withdraw_in_seconds (self->progress_notif, -1);
+ g_clear_object (&self->progress_notif);
+ }
+
+ IDE_EXIT;
+}
+
+static void
+action_update_builder (GSimpleAction *action,
+ GVariant *param,
+ gpointer user_data)
+{
+ GbpUpdateManagerAppAddin *self = user_data;
+ IdeWorkbench *workbench;
+ IdeContext *context;
+ GtkWindow *window;
+
+ IDE_ENTRY;
+
+ g_assert (G_IS_SIMPLE_ACTION (action));
+ g_assert (GBP_IS_UPDATE_MANAGER_APP_ADDIN (self));
+
+ if (self->app == NULL || self->portal == NULL)
+ IDE_EXIT;
+
+ if (!(window = gtk_application_get_active_window (GTK_APPLICATION (self->app))))
+ IDE_EXIT;
+
+ if (!(workbench = ide_widget_get_workbench (GTK_WIDGET (window))))
+ IDE_EXIT;
+
+ context = ide_workbench_get_context (workbench);
+
+ self->progress_notif = ide_notification_new ();
+ ide_notification_set_id (self->progress_notif, "org.gnome.builder.update-progress");
+ ide_notification_set_icon_name (self->progress_notif, "folder-download-symbolic");
+ ide_notification_set_title (self->progress_notif, _("Updating Builder"));
+ ide_notification_set_has_progress (self->progress_notif, TRUE);
+ ide_notification_attach (self->progress_notif, IDE_OBJECT (context));
+
+ xdp_portal_update_install (self->portal,
+ NULL,
+ XDP_UPDATE_INSTALL_FLAG_NONE,
+ self->cancellable,
+ on_update_install_cb,
+ g_object_ref (self));
+
+ IDE_EXIT;
+}
+
+static GActionEntry entries[] = {
+ { "update-builder", action_update_builder },
+};
+
+static void
+on_update_available_cb (GbpUpdateManagerAppAddin *self,
+ const gchar *current_commit,
+ const gchar *local_commit,
+ const gchar *remote_commit,
+ XdpPortal *portal)
+{
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_UPDATE_MANAGER_APP_ADDIN (self));
+ g_assert (XDP_IS_PORTAL (portal));
+
+ if (self->app != NULL)
+ {
+ IdeWorkbench *workbench;
+ IdeContext *context;
+ GActionMap *map;
+ GtkWindow *window;
+ GAction *action;
+
+ map = G_ACTION_MAP (self->app);
+ action = g_action_map_lookup_action (map, "update-builder");
+ if (G_IS_SIMPLE_ACTION (action))
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+
+ if (!(window = gtk_application_get_active_window (GTK_APPLICATION (self->app))))
+ IDE_EXIT;
+
+ if (!(workbench = ide_widget_get_workbench (GTK_WIDGET (window))))
+ IDE_EXIT;
+
+ context = ide_workbench_get_context (workbench);
+
+ self->update_notif = ide_notification_new ();
+ ide_notification_set_id (self->update_notif, "org.gnome.builder.update-progress");
+ ide_notification_set_icon_name (self->update_notif, "folder-download-symbolic");
+ ide_notification_set_title (self->update_notif, _("Updating Builder"));
+ ide_notification_attach (self->update_notif, IDE_OBJECT (context));
+ }
+
+ IDE_EXIT;
+}
+
+static void
+on_update_progress_cb (GbpUpdateManagerAppAddin *self,
+ guint n_ops,
+ guint op,
+ guint progress,
+ const gchar *error,
+ const gchar *error_message,
+ XdpPortal *portal)
+{
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_UPDATE_MANAGER_APP_ADDIN (self));
+ g_assert (XDP_IS_PORTAL (portal));
+
+ if (self->progress_notif != NULL)
+ ide_notification_set_progress (self->progress_notif, progress / 100.0);
+
+ IDE_EXIT;
+}
+
+static void
+gbp_update_manager_app_addin_start_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ XdpPortal *portal = (XdpPortal *)object;
+ g_autoptr(GbpUpdateManagerAppAddin) self = user_data;
+ g_autoptr(GError) error = NULL;
+
+ IDE_ENTRY;
+
+ g_assert (XDP_IS_PORTAL (portal));
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (GBP_IS_UPDATE_MANAGER_APP_ADDIN (self));
+
+ if (!xdp_portal_update_monitor_start_finish (portal, result, &error))
+ g_warning ("Failed to start update monitor: %s", error->message);
+
+ IDE_EXIT;
+}
+
+static void
+gbp_update_manager_app_addin_load (IdeApplicationAddin *addin,
+ IdeApplication *app)
+{
+ GbpUpdateManagerAppAddin *self = (GbpUpdateManagerAppAddin *)addin;
+ GAction *action;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_UPDATE_MANAGER_APP_ADDIN (self));
+ g_assert (IDE_IS_APPLICATION (app));
+
+ self->app = app;
+ self->cancellable = g_cancellable_new ();
+ self->portal = xdp_portal_new ();
+
+ g_signal_connect_object (self->portal,
+ "update-available",
+ G_CALLBACK (on_update_available_cb),
+ self,
+ G_CONNECT_SWAPPED);
+ g_signal_connect_object (self->portal,
+ "update-progress",
+ G_CALLBACK (on_update_progress_cb),
+ self,
+ G_CONNECT_SWAPPED);
+
+ g_action_map_add_action_entries (G_ACTION_MAP (app),
+ entries,
+ G_N_ELEMENTS (entries),
+ self);
+
+ if ((action = g_action_map_lookup_action (G_ACTION_MAP (app), "update-builder")))
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
+
+ xdp_portal_update_monitor_start (self->portal,
+ XDP_UPDATE_MONITOR_FLAG_NONE,
+ self->cancellable,
+ gbp_update_manager_app_addin_start_cb,
+ g_object_ref (self));
+
+ IDE_EXIT;
+}
+
+static void
+gbp_update_manager_app_addin_unload (IdeApplicationAddin *addin,
+ IdeApplication *app)
+{
+ GbpUpdateManagerAppAddin *self = (GbpUpdateManagerAppAddin *)addin;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_UPDATE_MANAGER_APP_ADDIN (self));
+ g_assert (IDE_IS_APPLICATION (app));
+
+ g_cancellable_cancel (self->cancellable);
+
+ for (guint i = 0; i < G_N_ELEMENTS (entries); i++)
+ g_action_map_remove_action (G_ACTION_MAP (app), entries[i].name);
+
+ g_clear_object (&self->portal);
+ g_clear_object (&self->cancellable);
+
+ if (self->progress_notif)
+ {
+ ide_notification_withdraw (self->progress_notif);
+ g_clear_object (&self->progress_notif);
+ }
+
+ if (self->update_notif)
+ {
+ ide_notification_withdraw (self->update_notif);
+ g_clear_object (&self->update_notif);
+ }
+
+ self->app = NULL;
+
+ IDE_EXIT;
+}
+
+static void
+app_addin_iface_init (IdeApplicationAddinInterface *iface)
+{
+ iface->load = gbp_update_manager_app_addin_load;
+ iface->unload = gbp_update_manager_app_addin_unload;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpUpdateManagerAppAddin, gbp_update_manager_app_addin, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_APPLICATION_ADDIN, app_addin_iface_init))
+
+static void
+gbp_update_manager_app_addin_class_init (GbpUpdateManagerAppAddinClass *klass)
+{
+}
+
+static void
+gbp_update_manager_app_addin_init (GbpUpdateManagerAppAddin *self)
+{
+}
diff --git a/src/plugins/update-manager/gbp-update-manager-app-addin.h
b/src/plugins/update-manager/gbp-update-manager-app-addin.h
new file mode 100644
index 000000000..6ffd04abb
--- /dev/null
+++ b/src/plugins/update-manager/gbp-update-manager-app-addin.h
@@ -0,0 +1,31 @@
+/* gbp-update-manager-app-addin.h
+ *
+ * Copyright 2020 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-gui.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_UPDATE_MANAGER_APP_ADDIN (gbp_update_manager_app_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpUpdateManagerAppAddin, gbp_update_manager_app_addin, GBP, UPDATE_MANAGER_APP_ADDIN,
GObject)
+
+G_END_DECLS
diff --git a/src/plugins/update-manager/meson.build b/src/plugins/update-manager/meson.build
new file mode 100644
index 000000000..0cd402e3c
--- /dev/null
+++ b/src/plugins/update-manager/meson.build
@@ -0,0 +1,20 @@
+if get_option('plugin_update_manager')
+
+plugins_deps += [
+ dependency('libportal', version: '>= 0.3'),
+]
+
+plugins_sources += files([
+ 'update-manager-plugin.c',
+ 'gbp-update-manager-app-addin.c',
+])
+
+plugin_update_manager_resources = gnome.compile_resources(
+ 'gbp-update-manager-resources',
+ 'update-manager.gresource.xml',
+ c_name: 'gbp_update_manager',
+)
+
+plugins_sources += plugin_update_manager_resources
+
+endif
diff --git a/src/plugins/update-manager/update-manager-plugin.c
b/src/plugins/update-manager/update-manager-plugin.c
new file mode 100644
index 000000000..b76f83653
--- /dev/null
+++ b/src/plugins/update-manager/update-manager-plugin.c
@@ -0,0 +1,36 @@
+/* update-manager-plugin.c
+ *
+ * Copyright 2020 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "update-manager-plugin"
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+#include <libide-gui.h>
+
+#include "gbp-update-manager-app-addin.h"
+
+_IDE_EXTERN void
+_gbp_update_manager_register_types (PeasObjectModule *module)
+{
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_APPLICATION_ADDIN,
+ GBP_TYPE_UPDATE_MANAGER_APP_ADDIN);
+}
diff --git a/src/plugins/update-manager/update-manager.gresource.xml
b/src/plugins/update-manager/update-manager.gresource.xml
new file mode 100644
index 000000000..bd14620b3
--- /dev/null
+++ b/src/plugins/update-manager/update-manager.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/plugins/update-manager">
+ <file>update-manager.plugin</file>
+ </gresource>
+</gresources>
diff --git a/src/plugins/update-manager/update-manager.plugin
b/src/plugins/update-manager/update-manager.plugin
new file mode 100644
index 000000000..b09c4bba2
--- /dev/null
+++ b/src/plugins/update-manager/update-manager.plugin
@@ -0,0 +1,10 @@
+[Plugin]
+Authors=Christian Hergert <christian hergert me>
+Builtin=true
+Copyright=Copyright 2020 Christian Hergert
+Depends=editor;
+Description=Notifies the user of new Builder releases
+Embedded=_gbp_update_manager_register_types
+Hidden=true
+Module=update-manager
+Name=Update Manager
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]