summaryrefslogtreecommitdiffstats
path: root/js/dbusServices/notifications
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 15:07:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 15:07:22 +0000
commitf9d480cfe50ca1d7a0f0b5a2b8bb9932962bfbe7 (patch)
treece9e8db2d4e8799780fa72ae8f1953039373e2ee /js/dbusServices/notifications
parentInitial commit. (diff)
downloadgnome-shell-upstream.tar.xz
gnome-shell-upstream.zip
Adding upstream version 3.38.6.upstream/3.38.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/dbusServices/notifications')
-rw-r--r--js/dbusServices/notifications/main.js11
-rw-r--r--js/dbusServices/notifications/notificationDaemon.js105
2 files changed, 116 insertions, 0 deletions
diff --git a/js/dbusServices/notifications/main.js b/js/dbusServices/notifications/main.js
new file mode 100644
index 0000000..7944cd1
--- /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 0000000..bf0f85b
--- /dev/null
+++ b/js/dbusServices/notifications/notificationDaemon.js
@@ -0,0 +1,105 @@
+// -*- 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);
+
+Gio._promisify(Gio.DBusConnection.prototype, 'call', 'call_finish');
+
+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);
+ }
+
+ async NotifyAsync(params, invocation) {
+ const pid = await this._getSenderPid(invocation.get_sender());
+ const hints = params[6];
+
+ params[6] = {
+ ...hints,
+ 'sender-pid': new GLib.Variant('u', pid),
+ };
+
+ 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));
+ });
+ }
+
+ async _getSenderPid(sender) {
+ const res = await Gio.DBus.session.call(
+ 'org.freedesktop.DBus',
+ '/',
+ 'org.freedesktop.DBus',
+ 'GetConnectionUnixProcessID',
+ new GLib.Variant('(s)', [sender]),
+ new GLib.VariantType('(u)'),
+ Gio.DBusCallFlags.NONE,
+ -1,
+ null);
+ const [pid] = res.deepUnpack();
+ return pid;
+ }
+};