diff options
author | Marco Trevisan (TreviƱo) <[email protected]> | 2025-09-18 01:23:12 +0200 |
---|---|---|
committer | Alessandro Astone <[email protected]> | 2025-09-18 16:31:09 +0200 |
commit | 700b00e334c54816c9a794c7a67f25bd04b219f4 (patch) | |
tree | 1435589aaa58cbc9f0a3bb5f8c1914a06b92f8ff | |
parent | 21abc4350ca7c9d84b12be1d6075a78bcc43cf0a (diff) |
update: Export notify-app-launch-context to a public headers
So we can reuse it in other notifications in which we're launching stuff
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/notify-utils.c | 59 | ||||
-rw-r--r-- | src/notify-utils.h | 11 | ||||
-rw-r--r-- | src/update.c | 47 |
4 files changed, 74 insertions, 45 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 2d4383a7..a793d39d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,6 +29,8 @@ update_notifier_SOURCES = update-notifier.c \ livepatch-tray.h\ livepatch-utils.c\ livepatch-utils.h\ + notify-utils.c\ + notify-utils.h\ update.c\ update.h\ unattended-upgrade.c\ diff --git a/src/notify-utils.c b/src/notify-utils.c new file mode 100644 index 00000000..a736dccd --- /dev/null +++ b/src/notify-utils.c @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* Copyright 2025 Canonical Ltd */ + +#include "notify-utils.h" + +struct _NotificationAppLaunchContext +{ + GAppLaunchContext parent_instance; + + char *activation_token; +}; + +G_DEFINE_TYPE (NotificationAppLaunchContext, + notification_app_launch_context, + G_TYPE_APP_LAUNCH_CONTEXT); + +GAppLaunchContext * +notification_app_launch_context_new (NotifyNotification *notification) +{ + NotificationAppLaunchContext *self; + + self = g_object_new (notification_app_launch_context_get_type (), NULL); + self->activation_token = + g_strdup (notify_notification_get_activation_token (notification)); + + return G_APP_LAUNCH_CONTEXT (self); +} + +static void +notification_app_launch_context_init (NotificationAppLaunchContext *self) +{} + +static void +notification_app_launch_context_finalize (GObject *object) +{ + NotificationAppLaunchContext *self = NOTIFICATION_APP_LAUNCH_CONTEXT (object); + g_clear_pointer (&self->activation_token, g_free); + G_OBJECT_CLASS (notification_app_launch_context_parent_class)->finalize(object); +} + +static char * +notification_app_launch_context_get_startup_notify_id (GAppLaunchContext *context, + GAppInfo *, + GList *) +{ + NotificationAppLaunchContext *self = NOTIFICATION_APP_LAUNCH_CONTEXT (context); + + return g_strdup (self->activation_token); +} + +static void +notification_app_launch_context_class_init (NotificationAppLaunchContextClass *klass) +{ + GAppLaunchContextClass *context_class = G_APP_LAUNCH_CONTEXT_CLASS (klass); + GObjectClass* object_class = G_OBJECT_CLASS (klass); + + context_class->get_startup_notify_id = notification_app_launch_context_get_startup_notify_id; + object_class->finalize = notification_app_launch_context_finalize; +} diff --git a/src/notify-utils.h b/src/notify-utils.h new file mode 100644 index 00000000..78523eb7 --- /dev/null +++ b/src/notify-utils.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* Copyright 2025 Canonical Ltd */ + +#include <gio/gio.h> +#include <libnotify/notify.h> + +G_DECLARE_FINAL_TYPE (NotificationAppLaunchContext, + notification_app_launch_context, + NOTIFICATION, APP_LAUNCH_CONTEXT, GAppLaunchContext); + +GAppLaunchContext *notification_app_launch_context_new (NotifyNotification *notification); diff --git a/src/update.c b/src/update.c index ce79d66d..6746897d 100644 --- a/src/update.c +++ b/src/update.c @@ -15,6 +15,7 @@ #include <unistd.h> #include <stdlib.h> +#include "notify-utils.h" #include "update-notifier.h" #include "update.h" #include "trayappletui.h" @@ -22,16 +23,6 @@ #define UPGRADE_CHECKER PACKAGE_LIB_DIR"/update-notifier/apt-check" #define PACKAGE_SYSTEM_LOCKED PACKAGE_LIB_DIR"/update-notifier/package-system-locked" -G_DECLARE_FINAL_TYPE (UpdateAppLaunchContext, update_app_launch_context, UPDATE, APP_LAUNCH_CONTEXT, GAppLaunchContext) -static GAppLaunchContext* update_app_launch_context_new (const char *activation_token); - -struct _UpdateAppLaunchContext { - GAppLaunchContext parent_instance; - - char *activation_token; -}; -G_DEFINE_TYPE(UpdateAppLaunchContext, update_app_launch_context, G_TYPE_APP_LAUNCH_CONTEXT) - typedef struct { const char *id; // the action identifier const char *command; // the command to execude @@ -279,8 +270,7 @@ on_notification_action(NotifyNotification *notification, char* id, gpointer user if (!found && !g_str_equal (id, "default")) g_warning ("received bad notification action; fallback to default"); - activation_token = notify_notification_get_activation_token (notification); - context = update_app_launch_context_new (activation_token); + context = notification_app_launch_context_new (notification); launch_update_action (&actions[action_idx], ta, context); } @@ -734,39 +724,6 @@ update_check (TrayApplet *ta) return TRUE; } -GAppLaunchContext * -update_app_launch_context_new (const char *activation_token) { - UpdateAppLaunchContext *self = UPDATE_APP_LAUNCH_CONTEXT (g_object_new (update_app_launch_context_get_type (), NULL)); - self->activation_token = g_strdup (activation_token); - return G_APP_LAUNCH_CONTEXT (self); -} - -static void -update_app_launch_context_init (UpdateAppLaunchContext *self) { -} - -static void -update_app_launch_context_finalize (GObject *object) { - UpdateAppLaunchContext *self = UPDATE_APP_LAUNCH_CONTEXT (object); - g_clear_pointer (&self->activation_token, g_free); - G_OBJECT_CLASS(update_app_launch_context_parent_class)->finalize(object); -} - -static char* -update_app_launch_context_get_startup_notify_id (GAppLaunchContext *context, GAppInfo*, GList*) { - UpdateAppLaunchContext *self = UPDATE_APP_LAUNCH_CONTEXT (context); - return g_strdup (self->activation_token); -} - -static void -update_app_launch_context_class_init (UpdateAppLaunchContextClass *klass) { - GAppLaunchContextClass *context_class = G_APP_LAUNCH_CONTEXT_CLASS (klass); - GObjectClass* object_class = G_OBJECT_CLASS(klass); - - context_class->get_startup_notify_id = update_app_launch_context_get_startup_notify_id; - object_class->finalize = update_app_launch_context_finalize; -} - void update_tray_icon_init(TrayApplet *ta, GDesktopAppInfo *software_updater_app) { |