2011-09-28 13:16:26 +00:00
|
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
|
import GdkPixbuf from 'gi://GdkPixbuf';
|
|
|
|
|
import Gio from 'gi://Gio';
|
|
|
|
|
import GLib from 'gi://GLib';
|
|
|
|
|
import GObject from 'gi://GObject';
|
|
|
|
|
import Shell from 'gi://Shell';
|
|
|
|
|
import St from 'gi://St';
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2011-01-11 21:34:09 +00:00
|
|
|
|
const Config = imports.misc.config;
|
2023-07-10 09:53:00 +00:00
|
|
|
|
import * as Main from './main.js';
|
|
|
|
|
import * as MessageTray from './messageTray.js';
|
|
|
|
|
import * as Params from '../misc/params.js';
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
|
import {loadInterfaceXML} from '../misc/fileUtils.js';
|
2011-08-16 12:26:49 +00:00
|
|
|
|
|
2018-09-06 00:55:20 +00:00
|
|
|
|
const FdoNotificationsIface = loadInterfaceXML('org.freedesktop.Notifications');
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2023-07-30 12:56:59 +00:00
|
|
|
|
/** @enum {number} */
|
2023-07-10 09:53:00 +00:00
|
|
|
|
const NotificationClosedReason = {
|
2010-01-13 20:05:20 +00:00
|
|
|
|
EXPIRED: 1,
|
|
|
|
|
DISMISSED: 2,
|
|
|
|
|
APP_CLOSED: 3,
|
2019-08-20 21:43:54 +00:00
|
|
|
|
UNDEFINED: 4,
|
2010-01-13 20:05:20 +00:00
|
|
|
|
};
|
|
|
|
|
|
2023-07-30 12:56:59 +00:00
|
|
|
|
/** @enum {number} */
|
2023-07-10 09:53:00 +00:00
|
|
|
|
const Urgency = {
|
2010-01-13 20:05:20 +00:00
|
|
|
|
LOW: 0,
|
|
|
|
|
NORMAL: 1,
|
2019-08-20 21:43:54 +00:00
|
|
|
|
CRITICAL: 2,
|
2010-01-13 20:05:20 +00:00
|
|
|
|
};
|
|
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
|
class FdoNotificationDaemon {
|
2017-10-31 01:19:44 +00:00
|
|
|
|
constructor() {
|
2013-10-13 14:44:28 +00:00
|
|
|
|
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(FdoNotificationsIface, this);
|
2011-08-16 12:26:49 +00:00
|
|
|
|
this._dbusImpl.export(Gio.DBus.session, '/org/freedesktop/Notifications');
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2011-12-20 05:51:35 +00:00
|
|
|
|
this._sources = [];
|
2010-09-02 14:45:53 +00:00
|
|
|
|
this._notifications = {};
|
2010-02-21 05:25:23 +00:00
|
|
|
|
|
2013-10-14 03:42:59 +00:00
|
|
|
|
this._nextNotificationId = 1;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_imageForNotificationData(hints) {
|
2012-12-30 16:45:43 +00:00
|
|
|
|
if (hints['image-data']) {
|
2020-03-27 13:18:34 +00:00
|
|
|
|
const [
|
|
|
|
|
width, height, rowStride, hasAlpha,
|
|
|
|
|
bitsPerSample, nChannels_, data,
|
|
|
|
|
] = hints['image-data'];
|
2023-08-06 23:45:22 +00:00
|
|
|
|
return Shell.util_create_pixbuf_from_data(data,
|
|
|
|
|
GdkPixbuf.Colorspace.RGB,
|
|
|
|
|
hasAlpha,
|
|
|
|
|
bitsPerSample,
|
|
|
|
|
width,
|
|
|
|
|
height,
|
|
|
|
|
rowStride);
|
2018-11-23 16:57:59 +00:00
|
|
|
|
} else if (hints['image-path']) {
|
2019-01-17 03:55:04 +00:00
|
|
|
|
return this._iconForNotificationData(hints['image-path']);
|
2012-12-30 16:45:43 +00:00
|
|
|
|
}
|
2018-11-23 16:57:59 +00:00
|
|
|
|
return null;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-12-30 16:45:43 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_fallbackIconForNotificationData(hints) {
|
2012-12-30 16:31:11 +00:00
|
|
|
|
let stockIcon;
|
|
|
|
|
switch (hints.urgency) {
|
2019-02-01 12:21:00 +00:00
|
|
|
|
case Urgency.LOW:
|
|
|
|
|
case Urgency.NORMAL:
|
|
|
|
|
stockIcon = 'dialog-information';
|
|
|
|
|
break;
|
|
|
|
|
case Urgency.CRITICAL:
|
|
|
|
|
stockIcon = 'dialog-error';
|
|
|
|
|
break;
|
2012-12-30 16:31:11 +00:00
|
|
|
|
}
|
2023-08-06 22:40:20 +00:00
|
|
|
|
return new Gio.ThemedIcon({name: stockIcon});
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-12-30 16:31:11 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_iconForNotificationData(icon) {
|
2010-08-05 17:09:27 +00:00
|
|
|
|
if (icon) {
|
2023-08-07 00:51:19 +00:00
|
|
|
|
if (icon.substr(0, 7) === 'file://')
|
2023-08-06 22:40:20 +00:00
|
|
|
|
return new Gio.FileIcon({file: Gio.File.new_for_uri(icon)});
|
2023-08-07 00:51:19 +00:00
|
|
|
|
else if (icon[0] === '/')
|
2023-08-06 22:40:20 +00:00
|
|
|
|
return new Gio.FileIcon({file: Gio.File.new_for_path(icon)});
|
2012-12-30 16:25:28 +00:00
|
|
|
|
else
|
2023-08-06 22:40:20 +00:00
|
|
|
|
return new Gio.ThemedIcon({name: icon});
|
2010-08-05 17:09:27 +00:00
|
|
|
|
}
|
2012-12-30 16:31:11 +00:00
|
|
|
|
return null;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-08-05 17:09:27 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_lookupSource(title, pid) {
|
2011-12-20 05:51:35 +00:00
|
|
|
|
for (let i = 0; i < this._sources.length; i++) {
|
|
|
|
|
let source = this._sources[i];
|
2023-08-07 00:51:19 +00:00
|
|
|
|
if (source.pid === pid && source.initialTitle === title)
|
2011-12-20 05:51:35 +00:00
|
|
|
|
return source;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2011-12-20 05:51:35 +00:00
|
|
|
|
|
2010-12-15 21:30:50 +00:00
|
|
|
|
// Returns the source associated with ndata.notification if it is set.
|
2013-10-11 17:13:36 +00:00
|
|
|
|
// If the existing or requested source is associated with a tray icon
|
|
|
|
|
// and passed in pid matches a pid of an existing source, the title
|
|
|
|
|
// match is ignored to enable representing a tray icon and notifications
|
|
|
|
|
// from the same application with a single source.
|
2011-12-20 05:51:35 +00:00
|
|
|
|
//
|
|
|
|
|
// If no existing source is found, a new source is created as long as
|
|
|
|
|
// pid is provided.
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_getSource(title, pid, ndata, sender) {
|
2010-12-15 21:30:50 +00:00
|
|
|
|
if (!pid && !(ndata && ndata.notification))
|
2020-05-15 13:28:17 +00:00
|
|
|
|
throw new Error('Either a pid or ndata.notification is needed');
|
2010-12-15 21:30:50 +00:00
|
|
|
|
|
|
|
|
|
// We use notification's source for the notifications we still have
|
|
|
|
|
// around that are getting replaced because we don't keep sources
|
|
|
|
|
// for transient notifications in this._sources, but we still want
|
|
|
|
|
// the notification associated with them to get replaced correctly.
|
|
|
|
|
if (ndata && ndata.notification)
|
|
|
|
|
return ndata.notification.source;
|
|
|
|
|
|
2014-06-13 13:06:45 +00:00
|
|
|
|
let source = this._lookupSource(title, pid);
|
2013-10-11 17:13:36 +00:00
|
|
|
|
if (source) {
|
|
|
|
|
source.setTitle(title);
|
|
|
|
|
return source;
|
2011-06-08 06:27:57 +00:00
|
|
|
|
}
|
2010-12-15 21:30:50 +00:00
|
|
|
|
|
2020-08-12 18:59:01 +00:00
|
|
|
|
const appId = ndata?.hints['desktop-entry'];
|
2017-06-13 04:49:07 +00:00
|
|
|
|
source = new FdoNotificationDaemonSource(title, pid, sender, appId);
|
2013-10-11 17:13:36 +00:00
|
|
|
|
|
|
|
|
|
this._sources.push(source);
|
2017-10-31 00:38:18 +00:00
|
|
|
|
source.connect('destroy', () => {
|
2013-10-11 17:13:36 +00:00
|
|
|
|
let index = this._sources.indexOf(source);
|
|
|
|
|
if (index >= 0)
|
|
|
|
|
this._sources.splice(index, 1);
|
2017-10-31 00:38:18 +00:00
|
|
|
|
});
|
2010-08-09 16:33:34 +00:00
|
|
|
|
|
|
|
|
|
Main.messageTray.add(source);
|
|
|
|
|
return source;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-08-09 16:33:34 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
NotifyAsync(params, invocation) {
|
2011-08-16 12:26:49 +00:00
|
|
|
|
let [appName, replacesId, icon, summary, body, actions, hints, timeout] = params;
|
2010-09-02 14:45:53 +00:00
|
|
|
|
let id;
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2012-05-31 09:28:41 +00:00
|
|
|
|
for (let hint in hints) {
|
|
|
|
|
// unpack the variants
|
2022-08-10 09:56:14 +00:00
|
|
|
|
hints[hint] = hints[hint].deepUnpack();
|
2012-05-31 09:28:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-06 22:40:20 +00:00
|
|
|
|
hints = Params.parse(hints, {urgency: Urgency.NORMAL}, true);
|
2012-05-31 09:28:41 +00:00
|
|
|
|
|
2011-07-11 11:09:45 +00:00
|
|
|
|
// Filter out chat, presence, calls and invitation notifications from
|
|
|
|
|
// Empathy, since we handle that information from telepathyClient.js
|
2015-03-03 08:30:01 +00:00
|
|
|
|
//
|
|
|
|
|
// Note that empathy uses im.received for one to one chats and
|
|
|
|
|
// x-empathy.im.mentioned for multi-user, so we're good here
|
2023-08-07 00:51:19 +00:00
|
|
|
|
if (appName === 'Empathy' && hints['category'] === 'im.received') {
|
2010-09-02 14:45:53 +00:00
|
|
|
|
// Ignore replacesId since we already sent back a
|
|
|
|
|
// NotificationClosed for that id.
|
2013-10-14 03:42:59 +00:00
|
|
|
|
id = this._nextNotificationId++;
|
2019-08-19 18:50:33 +00:00
|
|
|
|
let idleId = GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
|
2017-10-31 00:38:18 +00:00
|
|
|
|
this._emitNotificationClosed(id, NotificationClosedReason.DISMISSED);
|
|
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
|
});
|
2019-01-31 13:43:52 +00:00
|
|
|
|
GLib.Source.set_name_by_id(idleId, '[gnome-shell] this._emitNotificationClosed');
|
2011-08-16 12:26:49 +00:00
|
|
|
|
return invocation.return_value(GLib.Variant.new('(u)', [id]));
|
2010-02-02 15:21:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-29 17:11:24 +00:00
|
|
|
|
// Be compatible with the various hints for image data and image path
|
|
|
|
|
// 'image-data' and 'image-path' are the latest name of these hints, introduced in 1.2
|
|
|
|
|
|
|
|
|
|
if (!hints['image-path'] && hints['image_path'])
|
|
|
|
|
hints['image-path'] = hints['image_path']; // version 1.1 of the spec
|
|
|
|
|
|
2013-10-11 17:35:51 +00:00
|
|
|
|
if (!hints['image-data']) {
|
2011-01-19 15:30:01 +00:00
|
|
|
|
if (hints['image_data'])
|
|
|
|
|
hints['image-data'] = hints['image_data']; // version 1.1 of the spec
|
2011-08-29 17:11:24 +00:00
|
|
|
|
else if (hints['icon_data'] && !hints['image-path'])
|
|
|
|
|
// early versions of the spec; 'icon_data' should only be used if 'image-path' is not available
|
|
|
|
|
hints['image-data'] = hints['icon_data'];
|
2013-10-11 17:35:51 +00:00
|
|
|
|
}
|
2011-01-19 15:30:01 +00:00
|
|
|
|
|
2020-03-29 21:51:13 +00:00
|
|
|
|
const ndata = {
|
|
|
|
|
appName,
|
|
|
|
|
icon,
|
|
|
|
|
summary,
|
|
|
|
|
body,
|
|
|
|
|
actions,
|
|
|
|
|
hints,
|
|
|
|
|
timeout,
|
|
|
|
|
};
|
2023-08-07 00:51:19 +00:00
|
|
|
|
if (replacesId !== 0 && this._notifications[replacesId]) {
|
2010-09-02 14:45:53 +00:00
|
|
|
|
ndata.id = id = replacesId;
|
|
|
|
|
ndata.notification = this._notifications[replacesId].notification;
|
|
|
|
|
} else {
|
|
|
|
|
replacesId = 0;
|
2013-10-14 03:42:59 +00:00
|
|
|
|
ndata.id = id = this._nextNotificationId++;
|
2010-09-02 14:45:53 +00:00
|
|
|
|
}
|
|
|
|
|
this._notifications[id] = ndata;
|
|
|
|
|
|
2011-08-16 12:26:49 +00:00
|
|
|
|
let sender = invocation.get_sender();
|
2020-05-15 13:28:17 +00:00
|
|
|
|
let pid = hints['sender-pid'];
|
2010-12-15 21:30:50 +00:00
|
|
|
|
|
2011-12-20 05:51:35 +00:00
|
|
|
|
let source = this._getSource(appName, pid, ndata, sender, null);
|
2020-05-15 13:28:17 +00:00
|
|
|
|
this._notifyForSource(source, ndata);
|
2010-09-02 14:45:53 +00:00
|
|
|
|
|
2011-08-16 12:26:49 +00:00
|
|
|
|
return invocation.return_value(GLib.Variant.new('(u)', [id]));
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-09-02 14:45:53 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_notifyForSource(source, ndata) {
|
2023-08-06 22:40:20 +00:00
|
|
|
|
const {icon, summary, body, actions, hints} = ndata;
|
|
|
|
|
let {notification} = ndata;
|
2010-09-02 14:45:53 +00:00
|
|
|
|
|
2010-02-22 22:19:32 +00:00
|
|
|
|
if (notification == null) {
|
2012-12-30 16:37:43 +00:00
|
|
|
|
notification = new MessageTray.Notification(source);
|
2010-09-02 14:45:53 +00:00
|
|
|
|
ndata.notification = notification;
|
2017-10-31 00:38:18 +00:00
|
|
|
|
notification.connect('destroy', (n, reason) => {
|
|
|
|
|
delete this._notifications[ndata.id];
|
|
|
|
|
let notificationClosedReason;
|
|
|
|
|
switch (reason) {
|
2019-02-01 12:21:00 +00:00
|
|
|
|
case MessageTray.NotificationDestroyedReason.EXPIRED:
|
|
|
|
|
notificationClosedReason = NotificationClosedReason.EXPIRED;
|
|
|
|
|
break;
|
|
|
|
|
case MessageTray.NotificationDestroyedReason.DISMISSED:
|
|
|
|
|
notificationClosedReason = NotificationClosedReason.DISMISSED;
|
|
|
|
|
break;
|
|
|
|
|
case MessageTray.NotificationDestroyedReason.SOURCE_CLOSED:
|
|
|
|
|
notificationClosedReason = NotificationClosedReason.APP_CLOSED;
|
|
|
|
|
break;
|
2017-10-31 00:38:18 +00:00
|
|
|
|
}
|
|
|
|
|
this._emitNotificationClosed(ndata.id, notificationClosedReason);
|
|
|
|
|
});
|
2010-02-22 22:19:32 +00:00
|
|
|
|
}
|
2011-08-29 17:11:24 +00:00
|
|
|
|
|
2021-01-31 04:11:18 +00:00
|
|
|
|
// 'image-data' (or 'image-path') takes precedence over 'app-icon'.
|
|
|
|
|
let gicon = this._imageForNotificationData(hints);
|
|
|
|
|
|
|
|
|
|
if (!gicon)
|
|
|
|
|
gicon = this._iconForNotificationData(icon);
|
|
|
|
|
|
|
|
|
|
if (!gicon)
|
2012-12-30 16:31:11 +00:00
|
|
|
|
gicon = this._fallbackIconForNotificationData(hints);
|
|
|
|
|
|
2021-09-27 13:40:05 +00:00
|
|
|
|
const soundFile = 'sound-file' in hints
|
|
|
|
|
? Gio.File.new_for_path(hints['sound-file']) : null;
|
|
|
|
|
|
|
|
|
|
notification.update(summary, body, {
|
|
|
|
|
gicon,
|
|
|
|
|
bannerMarkup: true,
|
|
|
|
|
clear: true,
|
|
|
|
|
soundFile,
|
|
|
|
|
soundName: hints['sound-name'],
|
|
|
|
|
});
|
2012-12-30 16:37:43 +00:00
|
|
|
|
|
2013-10-14 03:20:50 +00:00
|
|
|
|
let hasDefaultAction = false;
|
|
|
|
|
|
2010-02-01 20:41:22 +00:00
|
|
|
|
if (actions.length) {
|
2011-08-02 13:42:45 +00:00
|
|
|
|
for (let i = 0; i < actions.length - 1; i += 2) {
|
2019-01-29 01:27:05 +00:00
|
|
|
|
let [actionId, label] = [actions[i], actions[i + 1]];
|
2023-08-07 00:51:19 +00:00
|
|
|
|
if (actionId === 'default') {
|
2013-10-14 03:20:50 +00:00
|
|
|
|
hasDefaultAction = true;
|
2019-08-20 00:51:42 +00:00
|
|
|
|
} else {
|
2017-10-31 00:38:18 +00:00
|
|
|
|
notification.addAction(label, () => {
|
2013-10-14 03:06:09 +00:00
|
|
|
|
this._emitActionInvoked(ndata.id, actionId);
|
2017-10-31 00:38:18 +00:00
|
|
|
|
});
|
2019-08-20 00:51:42 +00:00
|
|
|
|
}
|
2011-08-02 13:42:45 +00:00
|
|
|
|
}
|
2010-02-01 20:41:22 +00:00
|
|
|
|
}
|
2013-10-14 03:20:50 +00:00
|
|
|
|
|
|
|
|
|
if (hasDefaultAction) {
|
2017-10-31 00:38:18 +00:00
|
|
|
|
notification.connect('activated', () => {
|
2013-10-14 03:20:50 +00:00
|
|
|
|
this._emitActionInvoked(ndata.id, 'default');
|
2017-10-31 00:38:18 +00:00
|
|
|
|
});
|
2013-10-14 03:20:50 +00:00
|
|
|
|
} else {
|
2017-10-31 00:38:18 +00:00
|
|
|
|
notification.connect('activated', () => {
|
2013-10-14 03:20:50 +00:00
|
|
|
|
source.open();
|
2017-10-31 00:38:18 +00:00
|
|
|
|
});
|
2013-10-14 03:20:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-04 09:34:57 +00:00
|
|
|
|
switch (hints.urgency) {
|
2019-02-01 12:21:00 +00:00
|
|
|
|
case Urgency.LOW:
|
|
|
|
|
notification.setUrgency(MessageTray.Urgency.LOW);
|
|
|
|
|
break;
|
|
|
|
|
case Urgency.NORMAL:
|
|
|
|
|
notification.setUrgency(MessageTray.Urgency.NORMAL);
|
|
|
|
|
break;
|
|
|
|
|
case Urgency.CRITICAL:
|
|
|
|
|
notification.setUrgency(MessageTray.Urgency.CRITICAL);
|
|
|
|
|
break;
|
2011-01-04 09:34:57 +00:00
|
|
|
|
}
|
2017-06-13 04:49:07 +00:00
|
|
|
|
notification.setResident(!!hints.resident);
|
2010-12-15 21:30:50 +00:00
|
|
|
|
// 'transient' is a reserved keyword in JS, so we have to retrieve the value
|
|
|
|
|
// of the 'transient' hint with hints['transient'] rather than hints.transient
|
2017-06-13 04:49:07 +00:00
|
|
|
|
notification.setTransient(!!hints['transient']);
|
2010-04-28 19:34:27 +00:00
|
|
|
|
|
2019-08-19 19:38:51 +00:00
|
|
|
|
let privacyScope = hints['x-gnome-privacy-scope'] || 'user';
|
2023-08-07 00:51:19 +00:00
|
|
|
|
notification.setPrivacyScope(privacyScope === 'system'
|
2019-08-19 19:33:15 +00:00
|
|
|
|
? MessageTray.PrivacyScope.SYSTEM
|
|
|
|
|
: MessageTray.PrivacyScope.USER);
|
2018-11-01 20:56:25 +00:00
|
|
|
|
|
2012-12-30 16:29:32 +00:00
|
|
|
|
let sourceGIcon = source.useNotificationIcon ? gicon : null;
|
2012-07-19 13:05:17 +00:00
|
|
|
|
source.processNotification(notification, sourceGIcon);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
CloseNotification(id) {
|
2010-09-02 14:45:53 +00:00
|
|
|
|
let ndata = this._notifications[id];
|
|
|
|
|
if (ndata) {
|
|
|
|
|
if (ndata.notification)
|
2011-01-27 23:26:53 +00:00
|
|
|
|
ndata.notification.destroy(MessageTray.NotificationDestroyedReason.SOURCE_CLOSED);
|
2010-09-02 14:45:53 +00:00
|
|
|
|
delete this._notifications[id];
|
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
GetCapabilities() {
|
2010-01-13 20:05:20 +00:00
|
|
|
|
return [
|
2010-02-01 20:41:22 +00:00
|
|
|
|
'actions',
|
2015-02-16 15:43:30 +00:00
|
|
|
|
// 'action-icons',
|
2010-01-13 20:05:20 +00:00
|
|
|
|
'body',
|
|
|
|
|
// 'body-hyperlinks',
|
|
|
|
|
// 'body-images',
|
|
|
|
|
'body-markup',
|
|
|
|
|
// 'icon-multi',
|
2010-06-11 21:19:18 +00:00
|
|
|
|
'icon-static',
|
2010-10-09 02:34:04 +00:00
|
|
|
|
'persistence',
|
2012-11-05 17:10:24 +00:00
|
|
|
|
'sound',
|
2010-01-13 20:05:20 +00:00
|
|
|
|
];
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
GetServerInformation() {
|
2010-01-13 20:05:20 +00:00
|
|
|
|
return [
|
2011-01-11 21:34:09 +00:00
|
|
|
|
Config.PACKAGE_NAME,
|
2010-01-13 20:05:20 +00:00
|
|
|
|
'GNOME',
|
2011-01-11 21:34:09 +00:00
|
|
|
|
Config.PACKAGE_VERSION,
|
2019-08-20 21:43:54 +00:00
|
|
|
|
'1.2',
|
2010-01-13 20:05:20 +00:00
|
|
|
|
];
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_emitNotificationClosed(id, reason) {
|
2011-08-16 12:26:49 +00:00
|
|
|
|
this._dbusImpl.emit_signal('NotificationClosed',
|
2023-08-06 23:45:22 +00:00
|
|
|
|
GLib.Variant.new('(uu)', [id, reason]));
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-02-01 20:41:22 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_emitActionInvoked(id, action) {
|
2011-08-16 12:26:49 +00:00
|
|
|
|
this._dbusImpl.emit_signal('ActionInvoked',
|
2023-08-06 23:45:22 +00:00
|
|
|
|
GLib.Variant.new('(us)', [id, action]));
|
2010-01-13 20:05:20 +00:00
|
|
|
|
}
|
2023-07-10 09:53:00 +00:00
|
|
|
|
}
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2023-08-07 18:48:45 +00:00
|
|
|
|
export const FdoNotificationDaemonSource = GObject.registerClass(
|
2017-10-31 01:19:44 +00:00
|
|
|
|
class FdoNotificationDaemonSource extends MessageTray.Source {
|
2019-05-13 21:32:31 +00:00
|
|
|
|
_init(title, pid, sender, appId) {
|
2012-11-04 00:53:43 +00:00
|
|
|
|
this.pid = pid;
|
2020-05-29 19:51:14 +00:00
|
|
|
|
this.initialTitle = title;
|
2012-11-04 00:53:43 +00:00
|
|
|
|
this.app = this._getApp(appId);
|
|
|
|
|
|
2020-03-23 19:59:31 +00:00
|
|
|
|
super._init(title);
|
|
|
|
|
|
2012-11-04 00:53:43 +00:00
|
|
|
|
if (this.app)
|
|
|
|
|
this.title = this.app.get_name();
|
|
|
|
|
else
|
|
|
|
|
this.useNotificationIcon = true;
|
|
|
|
|
|
2019-08-20 00:51:42 +00:00
|
|
|
|
if (sender) {
|
2011-08-16 12:26:49 +00:00
|
|
|
|
this._nameWatcherId = Gio.DBus.session.watch_name(sender,
|
2023-08-06 23:45:22 +00:00
|
|
|
|
Gio.BusNameWatcherFlags.NONE,
|
|
|
|
|
null,
|
|
|
|
|
this._onNameVanished.bind(this));
|
2019-08-20 00:51:42 +00:00
|
|
|
|
} else {
|
2011-08-16 12:26:49 +00:00
|
|
|
|
this._nameWatcherId = 0;
|
2019-08-20 00:51:42 +00:00
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_createPolicy() {
|
2013-11-04 16:45:22 +00:00
|
|
|
|
if (this.app && this.app.get_app_info()) {
|
2019-01-29 01:27:05 +00:00
|
|
|
|
let id = this.app.get_id().replace(/\.desktop$/, '');
|
2013-10-13 20:01:56 +00:00
|
|
|
|
return new MessageTray.NotificationApplicationPolicy(id);
|
2012-10-16 15:08:54 +00:00
|
|
|
|
} else {
|
2013-10-13 20:01:56 +00:00
|
|
|
|
return new MessageTray.NotificationGenericPolicy();
|
2012-10-16 15:08:54 +00:00
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-10-16 15:08:54 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_onNameVanished() {
|
2011-07-06 21:01:07 +00:00
|
|
|
|
// Destroy the notification source when its sender is removed from DBus.
|
2011-07-27 21:08:08 +00:00
|
|
|
|
// Only do so if this.app is set to avoid removing "notify-send" sources, senders
|
|
|
|
|
// of which аre removed from DBus immediately.
|
2011-07-06 21:01:07 +00:00
|
|
|
|
// Sender being removed from DBus would normally result in a tray icon being removed,
|
|
|
|
|
// so allow the code path that handles the tray icon being removed to handle that case.
|
2014-06-13 13:06:45 +00:00
|
|
|
|
if (this.app)
|
2011-07-06 21:01:07 +00:00
|
|
|
|
this.destroy();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2011-07-06 21:01:07 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
processNotification(notification, gicon) {
|
2012-07-19 13:05:17 +00:00
|
|
|
|
if (gicon)
|
|
|
|
|
this._gicon = gicon;
|
2014-06-13 13:06:45 +00:00
|
|
|
|
this.iconUpdated();
|
2011-03-21 21:26:04 +00:00
|
|
|
|
|
|
|
|
|
let tracker = Shell.WindowTracker.get_default();
|
2023-08-07 00:51:19 +00:00
|
|
|
|
if (notification.resident && this.app && tracker.focus_app === this.app)
|
2011-03-21 21:26:04 +00:00
|
|
|
|
this.pushNotification(notification);
|
|
|
|
|
else
|
2019-05-13 21:32:31 +00:00
|
|
|
|
this.showNotification(notification);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-02-15 17:27:28 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_getApp(appId) {
|
2020-05-29 19:51:14 +00:00
|
|
|
|
const appSys = Shell.AppSystem.get_default();
|
2012-04-09 01:39:59 +00:00
|
|
|
|
let app;
|
|
|
|
|
|
|
|
|
|
app = Shell.WindowTracker.get_default().get_app_from_pid(this.pid);
|
|
|
|
|
if (app != null)
|
|
|
|
|
return app;
|
|
|
|
|
|
2020-05-29 19:51:14 +00:00
|
|
|
|
if (appId)
|
2022-02-07 14:14:06 +00:00
|
|
|
|
app = appSys.lookup_app(`${appId}.desktop`);
|
2012-04-09 01:39:59 +00:00
|
|
|
|
|
2020-05-29 19:51:14 +00:00
|
|
|
|
if (!app)
|
2022-02-07 14:14:06 +00:00
|
|
|
|
app = appSys.lookup_app(`${this.initialTitle}.desktop`);
|
2020-05-29 19:51:14 +00:00
|
|
|
|
|
|
|
|
|
return app;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-04-09 01:39:59 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
setTitle(title) {
|
2012-08-06 14:34:20 +00:00
|
|
|
|
// Do nothing if .app is set, we don't want to override the
|
|
|
|
|
// app name with whatever is provided through libnotify (usually
|
|
|
|
|
// garbage)
|
|
|
|
|
if (this.app)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
|
super.setTitle(title);
|
|
|
|
|
}
|
2012-08-06 14:34:20 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
open() {
|
2010-02-15 17:27:28 +00:00
|
|
|
|
this.openApp();
|
2013-10-07 20:11:18 +00:00
|
|
|
|
this.destroyNonResidentNotifications();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-09-30 20:56:50 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
openApp() {
|
2010-09-02 14:45:53 +00:00
|
|
|
|
if (this.app == null)
|
2010-02-15 17:27:28 +00:00
|
|
|
|
return;
|
2010-09-02 14:45:53 +00:00
|
|
|
|
|
2013-10-10 20:28:42 +00:00
|
|
|
|
this.app.activate();
|
|
|
|
|
Main.overview.hide();
|
2015-02-14 04:59:01 +00:00
|
|
|
|
Main.panel.closeCalendar();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2011-03-07 23:10:10 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
destroy() {
|
2011-08-16 12:26:49 +00:00
|
|
|
|
if (this._nameWatcherId) {
|
|
|
|
|
Gio.DBus.session.unwatch_name(this._nameWatcherId);
|
|
|
|
|
this._nameWatcherId = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
|
super.destroy();
|
|
|
|
|
}
|
2011-10-08 22:00:32 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
createIcon(size) {
|
2014-06-13 13:06:45 +00:00
|
|
|
|
if (this.app) {
|
2012-07-19 13:05:17 +00:00
|
|
|
|
return this.app.create_icon_texture(size);
|
|
|
|
|
} else if (this._gicon) {
|
2020-03-29 21:51:13 +00:00
|
|
|
|
return new St.Icon({
|
|
|
|
|
gicon: this._gicon,
|
|
|
|
|
icon_size: size,
|
|
|
|
|
});
|
2012-07-19 13:05:17 +00:00
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2010-01-13 20:05:20 +00:00
|
|
|
|
}
|
2019-05-13 21:32:31 +00:00
|
|
|
|
});
|
2013-10-13 14:44:28 +00:00
|
|
|
|
|
2014-07-01 19:47:31 +00:00
|
|
|
|
const PRIORITY_URGENCY_MAP = {
|
|
|
|
|
low: MessageTray.Urgency.LOW,
|
|
|
|
|
normal: MessageTray.Urgency.NORMAL,
|
|
|
|
|
high: MessageTray.Urgency.HIGH,
|
2019-08-20 21:43:54 +00:00
|
|
|
|
urgent: MessageTray.Urgency.CRITICAL,
|
2014-07-01 19:47:31 +00:00
|
|
|
|
};
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
|
const GtkNotificationDaemonNotification = GObject.registerClass(
|
2017-10-31 01:19:44 +00:00
|
|
|
|
class GtkNotificationDaemonNotification extends MessageTray.Notification {
|
2019-05-13 21:32:31 +00:00
|
|
|
|
_init(source, notification) {
|
|
|
|
|
super._init(source);
|
2013-10-13 22:52:37 +00:00
|
|
|
|
this._serialized = GLib.Variant.new('a{sv}', notification);
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2020-03-29 21:51:13 +00:00
|
|
|
|
const {
|
|
|
|
|
title,
|
|
|
|
|
body,
|
|
|
|
|
icon: gicon,
|
|
|
|
|
urgent,
|
|
|
|
|
priority,
|
|
|
|
|
buttons,
|
|
|
|
|
'default-action': defaultAction,
|
|
|
|
|
'default-action-target': defaultActionTarget,
|
|
|
|
|
timestamp: time,
|
|
|
|
|
} = notification;
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2014-07-01 19:47:31 +00:00
|
|
|
|
if (priority) {
|
|
|
|
|
let urgency = PRIORITY_URGENCY_MAP[priority.unpack()];
|
2023-08-07 00:51:19 +00:00
|
|
|
|
this.setUrgency(urgency !== undefined ? urgency : MessageTray.Urgency.NORMAL);
|
2014-07-01 19:47:31 +00:00
|
|
|
|
} else if (urgent) {
|
2019-08-19 19:33:15 +00:00
|
|
|
|
this.setUrgency(urgent.unpack()
|
|
|
|
|
? MessageTray.Urgency.CRITICAL
|
|
|
|
|
: MessageTray.Urgency.NORMAL);
|
2014-07-01 19:47:31 +00:00
|
|
|
|
} else {
|
|
|
|
|
this.setUrgency(MessageTray.Urgency.NORMAL);
|
|
|
|
|
}
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
|
|
|
|
if (buttons) {
|
2022-08-10 09:56:14 +00:00
|
|
|
|
buttons.deepUnpack().forEach(button => {
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this.addAction(button.label.unpack(), () => {
|
|
|
|
|
this._onButtonClicked(button);
|
|
|
|
|
});
|
2017-10-31 00:38:18 +00:00
|
|
|
|
});
|
2013-10-13 17:04:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-12 18:59:01 +00:00
|
|
|
|
this._defaultAction = defaultAction?.unpack();
|
2013-10-21 20:21:22 +00:00
|
|
|
|
this._defaultActionTarget = defaultActionTarget;
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2020-03-29 21:51:13 +00:00
|
|
|
|
this.update(title.unpack(), body?.unpack(), {
|
|
|
|
|
gicon: gicon
|
|
|
|
|
? Gio.icon_deserialize(gicon) : null,
|
|
|
|
|
datetime: time
|
|
|
|
|
? GLib.DateTime.new_from_unix_local(time.unpack()) : null,
|
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_activateAction(namespacedActionId, target) {
|
2013-10-13 17:04:02 +00:00
|
|
|
|
if (namespacedActionId) {
|
|
|
|
|
if (namespacedActionId.startsWith('app.')) {
|
|
|
|
|
let actionId = namespacedActionId.slice('app.'.length);
|
|
|
|
|
this.source.activateAction(actionId, target);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.source.open();
|
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_onButtonClicked(button) {
|
2023-08-06 22:40:20 +00:00
|
|
|
|
let {action, target} = button;
|
2019-09-12 15:19:51 +00:00
|
|
|
|
this._activateAction(action.unpack(), target);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
activate() {
|
2013-10-13 17:04:02 +00:00
|
|
|
|
this._activateAction(this._defaultAction, this._defaultActionTarget);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
super.activate();
|
|
|
|
|
}
|
2013-10-13 22:52:37 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
serialize() {
|
2013-10-13 22:52:37 +00:00
|
|
|
|
return this._serialized;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2019-05-13 21:32:31 +00:00
|
|
|
|
});
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2018-09-06 00:55:20 +00:00
|
|
|
|
const FdoApplicationIface = loadInterfaceXML('org.freedesktop.Application');
|
2013-10-13 17:04:02 +00:00
|
|
|
|
const FdoApplicationProxy = Gio.DBusProxy.makeProxyWrapper(FdoApplicationIface);
|
|
|
|
|
|
|
|
|
|
function objectPathFromAppId(appId) {
|
2020-03-24 04:02:20 +00:00
|
|
|
|
return `/${appId.replace(/\./g, '/').replace(/-/g, '_')}`;
|
2013-10-13 17:04:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-30 12:56:59 +00:00
|
|
|
|
/**
|
|
|
|
|
* @returns {{ 'desktop-startup-id': string }}
|
|
|
|
|
*/
|
2013-10-13 17:04:02 +00:00
|
|
|
|
function getPlatformData() {
|
2022-02-07 14:14:06 +00:00
|
|
|
|
let startupId = GLib.Variant.new('s', `_TIME${global.get_current_time()}`);
|
2023-07-30 12:56:59 +00:00
|
|
|
|
return {'desktop-startup-id': startupId};
|
2013-10-13 17:04:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function InvalidAppError() {}
|
|
|
|
|
|
2023-08-07 18:48:45 +00:00
|
|
|
|
export const GtkNotificationDaemonAppSource = GObject.registerClass(
|
2017-10-31 01:19:44 +00:00
|
|
|
|
class GtkNotificationDaemonAppSource extends MessageTray.Source {
|
2019-05-13 21:32:31 +00:00
|
|
|
|
_init(appId) {
|
2017-10-31 01:19:44 +00:00
|
|
|
|
let objectPath = objectPathFromAppId(appId);
|
|
|
|
|
if (!GLib.Variant.is_object_path(objectPath))
|
2016-11-18 14:52:46 +00:00
|
|
|
|
throw new InvalidAppError();
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2022-02-07 14:14:06 +00:00
|
|
|
|
let app = Shell.AppSystem.get_default().lookup_app(`${appId}.desktop`);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
if (!app)
|
2013-10-13 17:04:02 +00:00
|
|
|
|
throw new InvalidAppError();
|
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
|
this._appId = appId;
|
|
|
|
|
this._app = app;
|
|
|
|
|
this._objectPath = objectPath;
|
|
|
|
|
|
2020-03-23 19:59:31 +00:00
|
|
|
|
super._init(app.get_name());
|
|
|
|
|
|
2013-10-13 17:04:02 +00:00
|
|
|
|
this._notifications = {};
|
2016-11-26 18:32:22 +00:00
|
|
|
|
this._notificationPending = false;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
createIcon(size) {
|
2013-10-13 17:04:02 +00:00
|
|
|
|
return this._app.create_icon_texture(size);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_createPolicy() {
|
2013-10-13 17:04:02 +00:00
|
|
|
|
return new MessageTray.NotificationApplicationPolicy(this._appId);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2022-06-23 12:53:29 +00:00
|
|
|
|
_createApp() {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
new FdoApplicationProxy(Gio.DBus.session,
|
|
|
|
|
this._appId, this._objectPath, (proxy, err) => {
|
|
|
|
|
if (err)
|
|
|
|
|
reject(err);
|
|
|
|
|
else
|
|
|
|
|
resolve(proxy);
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2018-10-11 00:28:43 +00:00
|
|
|
|
_createNotification(params) {
|
|
|
|
|
return new GtkNotificationDaemonNotification(this, params);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2018-10-11 00:28:43 +00:00
|
|
|
|
|
2022-06-23 12:53:29 +00:00
|
|
|
|
async activateAction(actionId, target) {
|
|
|
|
|
try {
|
|
|
|
|
const app = await this._createApp();
|
|
|
|
|
const params = target ? [target] : [];
|
|
|
|
|
app.ActivateActionAsync(actionId, params, getPlatformData());
|
|
|
|
|
} catch (error) {
|
2022-12-16 21:33:10 +00:00
|
|
|
|
logError(error, 'Failed to activate app proxy');
|
2022-06-23 12:53:29 +00:00
|
|
|
|
}
|
2015-02-14 05:01:20 +00:00
|
|
|
|
Main.overview.hide();
|
|
|
|
|
Main.panel.closeCalendar();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2022-06-23 12:53:29 +00:00
|
|
|
|
async open() {
|
|
|
|
|
try {
|
|
|
|
|
const app = await this._createApp();
|
|
|
|
|
app.ActivateAsync(getPlatformData());
|
|
|
|
|
} catch (error) {
|
2022-12-16 21:33:10 +00:00
|
|
|
|
logError(error, 'Failed to open app proxy');
|
2022-06-23 12:53:29 +00:00
|
|
|
|
}
|
2015-02-14 05:01:20 +00:00
|
|
|
|
Main.overview.hide();
|
|
|
|
|
Main.panel.closeCalendar();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
addNotification(notificationId, notificationParams, showBanner) {
|
2016-11-26 18:32:22 +00:00
|
|
|
|
this._notificationPending = true;
|
|
|
|
|
|
2013-10-13 17:04:02 +00:00
|
|
|
|
if (this._notifications[notificationId])
|
2018-10-11 01:26:31 +00:00
|
|
|
|
this._notifications[notificationId].destroy(MessageTray.NotificationDestroyedReason.REPLACED);
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2018-10-11 00:28:43 +00:00
|
|
|
|
let notification = this._createNotification(notificationParams);
|
2017-10-31 00:38:18 +00:00
|
|
|
|
notification.connect('destroy', () => {
|
2013-10-13 17:04:02 +00:00
|
|
|
|
delete this._notifications[notificationId];
|
2017-10-31 00:38:18 +00:00
|
|
|
|
});
|
2013-10-13 17:04:02 +00:00
|
|
|
|
this._notifications[notificationId] = notification;
|
|
|
|
|
|
2013-10-13 22:52:37 +00:00
|
|
|
|
if (showBanner)
|
2019-05-13 21:32:31 +00:00
|
|
|
|
this.showNotification(notification);
|
2013-10-13 22:52:37 +00:00
|
|
|
|
else
|
|
|
|
|
this.pushNotification(notification);
|
2016-11-26 18:32:22 +00:00
|
|
|
|
|
|
|
|
|
this._notificationPending = false;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2016-11-26 18:32:22 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
destroy(reason) {
|
2016-11-26 18:32:22 +00:00
|
|
|
|
if (this._notificationPending)
|
|
|
|
|
return;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
super.destroy(reason);
|
|
|
|
|
}
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
removeNotification(notificationId) {
|
2013-10-13 17:04:02 +00:00
|
|
|
|
if (this._notifications[notificationId])
|
|
|
|
|
this._notifications[notificationId].destroy(MessageTray.NotificationDestroyedReason.SOURCE_CLOSED);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 22:52:37 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
serialize() {
|
2013-10-13 22:52:37 +00:00
|
|
|
|
let notifications = [];
|
|
|
|
|
for (let notificationId in this._notifications) {
|
|
|
|
|
let notification = this._notifications[notificationId];
|
|
|
|
|
notifications.push([notificationId, notification.serialize()]);
|
|
|
|
|
}
|
2013-10-21 20:02:03 +00:00
|
|
|
|
return [this._appId, notifications];
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2019-05-13 21:32:31 +00:00
|
|
|
|
});
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2018-09-06 00:55:20 +00:00
|
|
|
|
const GtkNotificationsIface = loadInterfaceXML('org.gtk.Notifications');
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
|
class GtkNotificationDaemon {
|
2017-10-31 01:19:44 +00:00
|
|
|
|
constructor() {
|
2013-10-13 17:04:02 +00:00
|
|
|
|
this._sources = {};
|
|
|
|
|
|
2013-10-13 22:52:37 +00:00
|
|
|
|
this._loadNotifications();
|
|
|
|
|
|
2013-10-13 17:04:02 +00:00
|
|
|
|
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(GtkNotificationsIface, this);
|
|
|
|
|
this._dbusImpl.export(Gio.DBus.session, '/org/gtk/Notifications');
|
|
|
|
|
|
|
|
|
|
Gio.DBus.session.own_name('org.gtk.Notifications', Gio.BusNameOwnerFlags.REPLACE, null, null);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_ensureAppSource(appId) {
|
2013-10-13 17:04:02 +00:00
|
|
|
|
if (this._sources[appId])
|
|
|
|
|
return this._sources[appId];
|
|
|
|
|
|
|
|
|
|
let source = new GtkNotificationDaemonAppSource(appId);
|
|
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
|
source.connect('destroy', () => {
|
2013-10-13 17:04:02 +00:00
|
|
|
|
delete this._sources[appId];
|
2013-10-28 10:26:17 +00:00
|
|
|
|
this._saveNotifications();
|
2017-10-31 00:38:18 +00:00
|
|
|
|
});
|
2019-05-13 21:32:31 +00:00
|
|
|
|
source.connect('notify::count', this._saveNotifications.bind(this));
|
2013-10-13 17:04:02 +00:00
|
|
|
|
Main.messageTray.add(source);
|
|
|
|
|
this._sources[appId] = source;
|
|
|
|
|
return source;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_loadNotifications() {
|
2013-10-13 22:52:37 +00:00
|
|
|
|
this._isLoading = true;
|
|
|
|
|
|
2019-08-28 14:38:03 +00:00
|
|
|
|
try {
|
|
|
|
|
let value = global.get_persistent_state('a(sa(sv))', 'notifications');
|
|
|
|
|
if (value) {
|
2022-08-10 09:56:14 +00:00
|
|
|
|
let sources = value.deepUnpack();
|
2019-08-28 14:38:03 +00:00
|
|
|
|
sources.forEach(([appId, notifications]) => {
|
2023-08-07 00:51:19 +00:00
|
|
|
|
if (notifications.length === 0)
|
2018-07-15 01:17:42 +00:00
|
|
|
|
return;
|
2013-10-13 22:52:37 +00:00
|
|
|
|
|
2019-08-28 14:38:03 +00:00
|
|
|
|
let source;
|
|
|
|
|
try {
|
|
|
|
|
source = this._ensureAppSource(appId);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (e instanceof InvalidAppError)
|
|
|
|
|
return;
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
notifications.forEach(([notificationId, notification]) => {
|
2022-08-10 09:56:14 +00:00
|
|
|
|
source.addNotification(notificationId, notification.deepUnpack(), false);
|
2019-08-28 14:38:03 +00:00
|
|
|
|
});
|
2013-10-13 22:52:37 +00:00
|
|
|
|
});
|
2019-08-28 14:38:03 +00:00
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
logError(e, 'Failed to load saved notifications');
|
|
|
|
|
} finally {
|
|
|
|
|
this._isLoading = false;
|
2013-10-13 22:52:37 +00:00
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 22:52:37 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_saveNotifications() {
|
2013-10-13 22:52:37 +00:00
|
|
|
|
if (this._isLoading)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
let sources = [];
|
|
|
|
|
for (let appId in this._sources) {
|
|
|
|
|
let source = this._sources[appId];
|
|
|
|
|
sources.push(source.serialize());
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 20:02:03 +00:00
|
|
|
|
global.set_persistent_state('notifications', new GLib.Variant('a(sa(sv))', sources));
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 22:52:37 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
AddNotificationAsync(params, invocation) {
|
2013-10-13 17:04:02 +00:00
|
|
|
|
let [appId, notificationId, notification] = params;
|
|
|
|
|
|
|
|
|
|
let source;
|
|
|
|
|
try {
|
|
|
|
|
source = this._ensureAppSource(appId);
|
2019-01-29 01:26:39 +00:00
|
|
|
|
} catch (e) {
|
2018-07-15 01:17:42 +00:00
|
|
|
|
if (e instanceof InvalidAppError) {
|
2022-02-07 14:14:06 +00:00
|
|
|
|
invocation.return_dbus_error('org.gtk.Notifications.InvalidApp',
|
|
|
|
|
`The app by ID "${appId}" could not be found`);
|
2018-07-15 01:17:42 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
throw e;
|
2013-10-13 17:04:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-26 23:15:29 +00:00
|
|
|
|
let timestamp = GLib.DateTime.new_now_local().to_unix();
|
|
|
|
|
notification['timestamp'] = new GLib.Variant('x', timestamp);
|
|
|
|
|
|
2013-10-13 22:52:37 +00:00
|
|
|
|
source.addNotification(notificationId, notification, true);
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
|
|
|
|
invocation.return_value(null);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 17:04:02 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
RemoveNotificationAsync(params, invocation) {
|
2013-10-13 17:04:02 +00:00
|
|
|
|
let [appId, notificationId] = params;
|
|
|
|
|
let source = this._sources[appId];
|
|
|
|
|
if (source)
|
|
|
|
|
source.removeNotification(notificationId);
|
|
|
|
|
|
|
|
|
|
invocation.return_value(null);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2023-07-10 09:53:00 +00:00
|
|
|
|
}
|
2013-10-13 14:44:28 +00:00
|
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
|
export class NotificationDaemon {
|
2017-10-31 01:19:44 +00:00
|
|
|
|
constructor() {
|
2013-10-13 14:44:28 +00:00
|
|
|
|
this._fdoNotificationDaemon = new FdoNotificationDaemon();
|
2013-10-13 17:04:02 +00:00
|
|
|
|
this._gtkNotificationDaemon = new GtkNotificationDaemon();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2023-07-10 09:53:00 +00:00
|
|
|
|
}
|