From a635b9ea40a0f6af0d956596b263050453e3b231 Mon Sep 17 00:00:00 2001 From: lenemter Date: Mon, 6 Oct 2025 01:00:07 +0300 Subject: [PATCH 1/2] Add Notification Portal v2 --- data/pantheon.portal | 2 +- src/Notification/Portal.vala | 52 +++++++++++++++++++++++++++++++ src/XdgDesktopPortalPantheon.vala | 3 ++ src/meson.build | 1 + 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/Notification/Portal.vala diff --git a/data/pantheon.portal b/data/pantheon.portal index b9de94e3..b677a33e 100644 --- a/data/pantheon.portal +++ b/data/pantheon.portal @@ -1,4 +1,4 @@ [portal] DBusName=org.freedesktop.impl.portal.desktop.pantheon -Interfaces=org.freedesktop.impl.portal.Access;org.freedesktop.impl.portal.AppChooser;org.freedesktop.impl.portal.Background;org.freedesktop.impl.portal.Screenshot;org.freedesktop.impl.portal.Wallpaper;org.freedesktop.impl.portal.ScreenCast +Interfaces=org.freedesktop.impl.portal.Access;org.freedesktop.impl.portal.AppChooser;org.freedesktop.impl.portal.Background;org.freedesktop.impl.portal.Notification;org.freedesktop.impl.portal.Screenshot;org.freedesktop.impl.portal.Wallpaper;org.freedesktop.impl.portal.ScreenCast UseIn=pantheon diff --git a/src/Notification/Portal.vala b/src/Notification/Portal.vala new file mode 100644 index 00000000..03bd012c --- /dev/null +++ b/src/Notification/Portal.vala @@ -0,0 +1,52 @@ +// Copyright + +[DBus (name = "org.freedesktop.impl.portal.Notification")] +public class Notification.Portal : Object { + [DBus (name = "io.elementary.notifications.PortalProxy")] + private interface PortalProxy : Object { + public abstract HashTable supported_options { owned get; } + public abstract uint version { owned get; } + + public signal void action_invoked (string app_id, string id, string action_name, Variant[] action_parameters); + + public abstract void add_notification (string app_id, string id, HashTable data) throws Error; + public abstract void remove_notification (string app_id, string id) throws Error; + } + + public signal void action_invoked (string app_id, string id, string action_name, Variant[] parameters); + + public HashTable supported_options { + owned get { + return proxy.supported_options; + } + } + + public uint version { + get { + return proxy.version; + } + } + + private PortalProxy proxy; + + construct { + try { + proxy = Bus.get_proxy_sync ( + SESSION, "io.elementary.notifications.PortalProxy", "/io/elementary/notifications/PortalProxy" + ); + proxy.action_invoked.connect ( + (app_id, id, action, parameters) => action_invoked (app_id, id, action, parameters) + ); + } catch (Error e) { + critical ("Couldn't connect to notifications portal proxy: %s", e.message); + } + } + + public void add_notification (string app_id, string id, HashTable data) throws Error { + proxy.add_notification (app_id, id, data); + } + + public void remove_notification (string app_id, string id) throws Error { + proxy.remove_notification (app_id, id); + } +} \ No newline at end of file diff --git a/src/XdgDesktopPortalPantheon.vala b/src/XdgDesktopPortalPantheon.vala index 69d8a778..ae75d543 100644 --- a/src/XdgDesktopPortalPantheon.vala +++ b/src/XdgDesktopPortalPantheon.vala @@ -41,6 +41,9 @@ private void on_bus_acquired (DBusConnection connection, string name) { connection.register_object ("/org/freedesktop/portal/desktop", new Background.Portal (connection)); debug ("Background Portal registered!"); + connection.register_object ("/org/freedesktop/portal/desktop", new Notification.Portal ()); + debug ("Notification Portal registered!"); + connection.register_object ("/org/freedesktop/portal/desktop", new Screenshot.Portal (connection)); debug ("Screenshot Portal registered!"); diff --git a/src/meson.build b/src/meson.build index 68f41c3d..25b58328 100644 --- a/src/meson.build +++ b/src/meson.build @@ -8,6 +8,7 @@ executable( 'AppChooser/Portal.vala', 'Background/NotificationRequest.vala', 'Background/Portal.vala', + 'Notification/Portal.vala', 'ScreenCast/MonitorTracker/Interface.vala', 'ScreenCast/MonitorTracker/Monitor.vala', 'ScreenCast/MonitorTracker/MonitorTracker.vala', From a14e4f59f7fd4ff2ecc4b83e4090e1f1ef2486a8 Mon Sep 17 00:00:00 2001 From: lenemter Date: Mon, 6 Oct 2025 01:07:03 +0300 Subject: [PATCH 2/2] Fix lint, add copyright header --- src/Notification/Portal.vala | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/Notification/Portal.vala b/src/Notification/Portal.vala index 03bd012c..0435376a 100644 --- a/src/Notification/Portal.vala +++ b/src/Notification/Portal.vala @@ -1,4 +1,7 @@ -// Copyright +/* + * SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ [DBus (name = "org.freedesktop.impl.portal.Notification")] public class Notification.Portal : Object { @@ -15,19 +18,11 @@ public class Notification.Portal : Object { public signal void action_invoked (string app_id, string id, string action_name, Variant[] parameters); - public HashTable supported_options { - owned get { - return proxy.supported_options; - } - } + public HashTable supported_options { owned get { return proxy.supported_options; } } - public uint version { - get { - return proxy.version; - } - } + public uint version { get { return proxy.version; } } - private PortalProxy proxy; + private PortalProxy proxy; construct { try { @@ -49,4 +44,4 @@ public class Notification.Portal : Object { public void remove_notification (string app_id, string id) throws Error { proxy.remove_notification (app_id, id); } -} \ No newline at end of file +}