[gnome-shell] dbusServices/notifications: Add a separate notification daemon



commit 799bbdb5033f7b39b0af2057d530f2394334b0b7
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu May 16 21:08:06 2019 +0200

    dbusServices/notifications: Add a separate notification daemon
    
    Add a small service that exposes the Fdo notification API under the
    well-known name, and forwards any requests to the actual implementation
    in the shell.
    
    That way any app with permission to talk to org.freedesktop.Notifications
    will get exactly that, and nothing more.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/547

 js/dbusServices/meson.build                        |  1 +
 js/dbusServices/notifications/main.js              | 11 +++
 .../notifications/notificationDaemon.js            | 80 ++++++++++++++++++++++
 ...org.gnome.Shell.Notifications.src.gresource.xml | 11 +++
 4 files changed, 103 insertions(+)
---
diff --git a/js/dbusServices/meson.build b/js/dbusServices/meson.build
index c2c4d6392f..2cca6544fa 100644
--- a/js/dbusServices/meson.build
+++ b/js/dbusServices/meson.build
@@ -4,6 +4,7 @@ launcherconf.set('prefix', prefix)
 launcherconf.set('libdir', libdir)
 
 dbus_services = {
+  'org.gnome.Shell.Notifications': 'notifications',
 }
 
 config_dir = '@0@/..'.format(meson.current_build_dir())
diff --git a/js/dbusServices/notifications/main.js b/js/dbusServices/notifications/main.js
new file mode 100644
index 0000000000..7944cd122a
--- /dev/null
+++ b/js/dbusServices/notifications/main.js
@@ -0,0 +1,11 @@
+/* exported main */
+
+const { DBusService } = imports.dbusService;
+const { NotificationDaemon } = imports.notificationDaemon;
+
+function main() {
+    const service = new DBusService(
+        'org.gnome.Shell.Notifications',
+        new NotificationDaemon());
+    service.run();
+}
diff --git a/js/dbusServices/notifications/notificationDaemon.js 
b/js/dbusServices/notifications/notificationDaemon.js
new file mode 100644
index 0000000000..c2d2ef6f9f
--- /dev/null
+++ b/js/dbusServices/notifications/notificationDaemon.js
@@ -0,0 +1,80 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+/* exported NotificationDaemon */
+
+const { Gio, GLib } = imports.gi;
+
+const { loadInterfaceXML } = imports.misc.fileUtils;
+const { ServiceImplementation } = imports.dbusService;
+
+const NotificationsIface = loadInterfaceXML('org.freedesktop.Notifications');
+const NotificationsProxy = Gio.DBusProxy.makeProxyWrapper(NotificationsIface);
+
+var NotificationDaemon = class extends ServiceImplementation {
+    constructor() {
+        super(NotificationsIface, '/org/freedesktop/Notifications');
+
+        this._autoShutdown = false;
+
+        this._proxy = new NotificationsProxy(Gio.DBus.session,
+            'org.gnome.Shell',
+            '/org/freedesktop/Notifications',
+            (proxy, error) => {
+                if (error)
+                    log(error.message);
+            });
+
+        this._proxy.connectSignal('ActionInvoked',
+            (proxy, sender, params) => {
+                this._dbusImpl.emit_signal('ActionInvoked',
+                    new GLib.Variant('(us)', params));
+            });
+        this._proxy.connectSignal('NotificationClosed',
+            (proxy, sender, params) => {
+                this._dbusImpl.emit_signal('NotificationClosed',
+                    new GLib.Variant('(uu)', params));
+            });
+    }
+
+    register() {
+        Gio.DBus.session.own_name(
+            'org.freedesktop.Notifications',
+            Gio.BusNameOwnerFlags.REPLACE,
+            null, null);
+    }
+
+    NotifyAsync(params, invocation) {
+        this._proxy.NotifyRemote(...params, (res, error) => {
+            if (this._handleError(invocation, error))
+                return;
+
+            invocation.return_value(new GLib.Variant('(u)', res));
+        });
+    }
+
+    CloseNotificationAsync(params, invocation) {
+        this._proxy.CloseNotificationRemote(...params, (res, error) => {
+            if (this._handleError(invocation, error))
+                return;
+
+            invocation.return_value(null);
+        });
+    }
+
+    GetCapabilitiesAsync(params, invocation) {
+        this._proxy.GetCapabilitiesRemote(...params, (res, error) => {
+            if (this._handleError(invocation, error))
+                return;
+
+            invocation.return_value(new GLib.Variant('(as)', res));
+        });
+    }
+
+    GetServerInformationAsync(params, invocation) {
+        this._proxy.GetServerInformationRemote(...params, (res, error) => {
+            if (this._handleError(invocation, error))
+                return;
+
+            invocation.return_value(new GLib.Variant('(ssss)', res));
+        });
+    }
+};
diff --git a/js/dbusServices/org.gnome.Shell.Notifications.src.gresource.xml 
b/js/dbusServices/org.gnome.Shell.Notifications.src.gresource.xml
new file mode 100644
index 0000000000..ccf0e98a72
--- /dev/null
+++ b/js/dbusServices/org.gnome.Shell.Notifications.src.gresource.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/Shell/Notifications/js">
+    <file>main.js</file>
+    <file>notificationDaemon.js</file>
+    <file>dbusService.js</file>
+
+    <file>misc/config.js</file>
+    <file>misc/fileUtils.js</file>
+  </gresource>
+</gresources>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]