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..0435376a --- /dev/null +++ b/src/Notification/Portal.vala @@ -0,0 +1,47 @@ +/* + * 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 { + [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); + } +} diff --git a/src/XdgDesktopPortalPantheon.vala b/src/XdgDesktopPortalPantheon.vala index 1569817e..00638380 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 843990a7..8bcfc3df 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',