messageTray: Inherit Notification, Source and NotificationPolicy from GObject
Register notifications, sources and policies as GObject gtypes so that they can be passed in signals and use native properties and signals. Reimplement all the extending classes. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/559
This commit is contained in:
parent
7059dcced3
commit
b5676a2a5c
@ -1,7 +1,7 @@
|
|||||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||||
/* exported Component */
|
/* exported Component */
|
||||||
|
|
||||||
const { Gio, St } = imports.gi;
|
const { Gio, GObject, St } = imports.gi;
|
||||||
|
|
||||||
const GnomeSession = imports.misc.gnomeSession;
|
const GnomeSession = imports.misc.gnomeSession;
|
||||||
const Main = imports.ui.main;
|
const Main = imports.ui.main;
|
||||||
@ -272,9 +272,10 @@ var AutorunDispatcher = class {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var AutorunSource = class extends MessageTray.Source {
|
var AutorunSource = GObject.registerClass(
|
||||||
constructor(manager, mount, apps) {
|
class AutorunSource extends MessageTray.Source {
|
||||||
super(mount.get_name());
|
_init(manager, mount, apps) {
|
||||||
|
super._init(mount.get_name());
|
||||||
|
|
||||||
this._manager = manager;
|
this._manager = manager;
|
||||||
this.mount = mount;
|
this.mount = mount;
|
||||||
@ -284,7 +285,7 @@ var AutorunSource = class extends MessageTray.Source {
|
|||||||
|
|
||||||
// add ourselves as a source, and popup the notification
|
// add ourselves as a source, and popup the notification
|
||||||
Main.messageTray.add(this);
|
Main.messageTray.add(this);
|
||||||
this.notify(this._notification);
|
this.showNotification(this._notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
getIcon() {
|
getIcon() {
|
||||||
@ -294,11 +295,12 @@ var AutorunSource = class extends MessageTray.Source {
|
|||||||
_createPolicy() {
|
_createPolicy() {
|
||||||
return new MessageTray.NotificationApplicationPolicy('org.gnome.Nautilus');
|
return new MessageTray.NotificationApplicationPolicy('org.gnome.Nautilus');
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
var AutorunNotification = class extends MessageTray.Notification {
|
var AutorunNotification = GObject.registerClass(
|
||||||
constructor(manager, source) {
|
class AutorunNotification extends MessageTray.Notification {
|
||||||
super(source, source.title);
|
_init(manager, source) {
|
||||||
|
super._init(source, source.title);
|
||||||
|
|
||||||
this._manager = manager;
|
this._manager = manager;
|
||||||
this._mount = source.mount;
|
this._mount = source.mount;
|
||||||
@ -350,6 +352,6 @@ var AutorunNotification = class extends MessageTray.Notification {
|
|||||||
let app = Gio.app_info_get_default_for_type('inode/directory', false);
|
let app = Gio.app_info_get_default_for_type('inode/directory', false);
|
||||||
startAppForMount(app, this._mount);
|
startAppForMount(app, this._mount);
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
var Component = AutorunManager;
|
var Component = AutorunManager;
|
||||||
|
@ -734,7 +734,7 @@ var NetworkAgent = class {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Main.messageTray.add(source);
|
Main.messageTray.add(source);
|
||||||
source.notify(notification);
|
source.showNotification(notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
_newRequest(agent, requestId, connection, settingName, hints, flags) {
|
_newRequest(agent, requestId, connection, settingName, hints, flags) {
|
||||||
|
@ -215,7 +215,7 @@ class TelepathyClient extends Tp.BaseClient {
|
|||||||
// We are already handling the channel, display the source
|
// We are already handling the channel, display the source
|
||||||
let source = this._chatSources[channel.get_object_path()];
|
let source = this._chatSources[channel.get_object_path()];
|
||||||
if (source)
|
if (source)
|
||||||
source.notify();
|
source.showNotification();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -266,9 +266,10 @@ class TelepathyClient extends Tp.BaseClient {
|
|||||||
}
|
}
|
||||||
}) : null;
|
}) : null;
|
||||||
|
|
||||||
var ChatSource = class extends MessageTray.Source {
|
var ChatSource = HAVE_TP ? GObject.registerClass(
|
||||||
constructor(account, conn, channel, contact, client) {
|
class ChatSource extends MessageTray.Source {
|
||||||
super(contact.get_alias());
|
_init(account, conn, channel, contact, client) {
|
||||||
|
super._init(contact.get_alias());
|
||||||
|
|
||||||
this._account = account;
|
this._account = account;
|
||||||
this._contact = contact;
|
this._contact = contact;
|
||||||
@ -476,7 +477,7 @@ var ChatSource = class extends MessageTray.Source {
|
|||||||
this._notification.appendMessage(pendingMessages[i], true);
|
this._notification.appendMessage(pendingMessages[i], true);
|
||||||
|
|
||||||
if (pendingMessages.length > 0)
|
if (pendingMessages.length > 0)
|
||||||
this.notify();
|
this.showNotification();
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy(reason) {
|
destroy(reason) {
|
||||||
@ -553,7 +554,7 @@ var ChatSource = class extends MessageTray.Source {
|
|||||||
|
|
||||||
_notifyTimeout() {
|
_notifyTimeout() {
|
||||||
if (this._pendingMessages.length != 0)
|
if (this._pendingMessages.length != 0)
|
||||||
this.notify();
|
this.showNotification();
|
||||||
|
|
||||||
this._notifyTimeoutId = 0;
|
this._notifyTimeoutId = 0;
|
||||||
|
|
||||||
@ -568,8 +569,8 @@ var ChatSource = class extends MessageTray.Source {
|
|||||||
this._notification.appendMessage(message);
|
this._notification.appendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
notify() {
|
showNotification() {
|
||||||
super.notify(this._notification);
|
super.showNotification(this._notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
respond(text) {
|
respond(text) {
|
||||||
@ -625,12 +626,18 @@ var ChatSource = class extends MessageTray.Source {
|
|||||||
// 'pending-message-removed' for each one.
|
// 'pending-message-removed' for each one.
|
||||||
this._channel.ack_all_pending_messages_async(null);
|
this._channel.ack_all_pending_messages_async(null);
|
||||||
}
|
}
|
||||||
};
|
}) : null;
|
||||||
|
|
||||||
var ChatNotification = class extends MessageTray.Notification {
|
var ChatNotification = HAVE_TP ? GObject.registerClass({
|
||||||
constructor(source) {
|
Signals: {
|
||||||
super(source, source.title, null,
|
'message-removed': { param_types: [Tp.Message.$gtype] },
|
||||||
{ secondaryGIcon: source.getSecondaryIcon() });
|
'message-added': { param_types: [Tp.Message.$gtype] },
|
||||||
|
'timestamp-changed': { param_types: [Tp.Message.$gtype] },
|
||||||
|
}
|
||||||
|
}, class ChatNotification extends MessageTray.Notification {
|
||||||
|
_init(source) {
|
||||||
|
super._init(source, source.title, null,
|
||||||
|
{ secondaryGIcon: source.getSecondaryIcon() });
|
||||||
this.setUrgency(MessageTray.Urgency.HIGH);
|
this.setUrgency(MessageTray.Urgency.HIGH);
|
||||||
this.setResident(true);
|
this.setResident(true);
|
||||||
|
|
||||||
@ -782,7 +789,7 @@ var ChatNotification = class extends MessageTray.Notification {
|
|||||||
|
|
||||||
this._filterMessages();
|
this._filterMessages();
|
||||||
}
|
}
|
||||||
};
|
}) : null;
|
||||||
|
|
||||||
var ChatLineBox = GObject.registerClass(
|
var ChatLineBox = GObject.registerClass(
|
||||||
class ChatLineBox extends St.BoxLayout {
|
class ChatLineBox extends St.BoxLayout {
|
||||||
|
@ -405,7 +405,7 @@ var MessagesIndicator = class MessagesIndicator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_onSourceAdded(tray, source) {
|
_onSourceAdded(tray, source) {
|
||||||
source.connect('count-updated', this._updateCount.bind(this));
|
source.connect('notify::count', this._updateCount.bind(this));
|
||||||
this._sources.push(source);
|
this._sources.push(source);
|
||||||
this._updateCount();
|
this._updateCount();
|
||||||
}
|
}
|
||||||
|
@ -403,7 +403,7 @@ function notify(msg, details) {
|
|||||||
messageTray.add(source);
|
messageTray.add(source);
|
||||||
let notification = new MessageTray.Notification(source, msg, details);
|
let notification = new MessageTray.Notification(source, msg, details);
|
||||||
notification.setTransient(true);
|
notification.setTransient(true);
|
||||||
source.notify(notification);
|
source.showNotification(notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,72 +134,84 @@ var FocusGrabber = class FocusGrabber {
|
|||||||
// source, such as whether to play sound or honour the critical bit.
|
// source, such as whether to play sound or honour the critical bit.
|
||||||
//
|
//
|
||||||
// A notification without a policy object will inherit the default one.
|
// A notification without a policy object will inherit the default one.
|
||||||
var NotificationPolicy = class NotificationPolicy {
|
var NotificationPolicy = GObject.registerClass({
|
||||||
constructor(params) {
|
GTypeName: 'MessageTray_NotificationPolicy',
|
||||||
params = Params.parse(params, {
|
Properties: {
|
||||||
enable: true,
|
'enable': GObject.ParamSpec.boolean(
|
||||||
enableSound: true,
|
'enable', 'enable', 'enable',
|
||||||
showBanners: true,
|
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
|
||||||
forceExpanded: false,
|
true),
|
||||||
showInLockScreen: true,
|
'enable-sound': GObject.ParamSpec.boolean(
|
||||||
detailsInLockScreen: false,
|
'enable-sound', 'enable-sound', 'enable-sound',
|
||||||
});
|
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
|
||||||
Object.getOwnPropertyNames(params).forEach(key => {
|
true),
|
||||||
let desc = Object.getOwnPropertyDescriptor(params, key);
|
'show-banners': GObject.ParamSpec.boolean(
|
||||||
Object.defineProperty(this, `_${key}`, desc);
|
'show-banners', 'show-banners', 'show-banners',
|
||||||
});
|
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
|
||||||
|
true),
|
||||||
|
'force-expanded': GObject.ParamSpec.boolean(
|
||||||
|
'force-expanded', 'force-expanded', 'force-expanded',
|
||||||
|
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
|
||||||
|
false),
|
||||||
|
'show-in-lock-screen': GObject.ParamSpec.boolean(
|
||||||
|
'show-in-lock-screen', 'show-in-lock-screen', 'show-in-lock-screen',
|
||||||
|
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
|
||||||
|
false),
|
||||||
|
'details-in-lock-screen': GObject.ParamSpec.boolean(
|
||||||
|
'details-in-lock-screen', 'details-in-lock-screen', 'details-in-lock-screen',
|
||||||
|
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
|
||||||
|
false),
|
||||||
}
|
}
|
||||||
|
}, class NotificationPolicy extends GObject.Object {
|
||||||
// Do nothing for the default policy. These methods are only useful for the
|
// Do nothing for the default policy. These methods are only useful for the
|
||||||
// GSettings policy.
|
// GSettings policy.
|
||||||
store() { }
|
store() { }
|
||||||
|
|
||||||
destroy() { }
|
destroy() {
|
||||||
|
this.run_dispose();
|
||||||
get enable() {
|
|
||||||
return this._enable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get enableSound() {
|
get enableSound() {
|
||||||
return this._enableSound;
|
return this.enable_sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
get showBanners() {
|
get showBanners() {
|
||||||
return this._showBanners;
|
return this.show_banners;
|
||||||
}
|
}
|
||||||
|
|
||||||
get forceExpanded() {
|
get forceExpanded() {
|
||||||
return this._forceExpanded;
|
return this.force_expanded;
|
||||||
}
|
}
|
||||||
|
|
||||||
get showInLockScreen() {
|
get showInLockScreen() {
|
||||||
return this._showInLockScreen;
|
return this.show_in_lock_screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
get detailsInLockScreen() {
|
get detailsInLockScreen() {
|
||||||
return this._detailsInLockScreen;
|
return this.details_in_lock_screen;
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
Signals.addSignalMethods(NotificationPolicy.prototype);
|
|
||||||
|
|
||||||
var NotificationGenericPolicy =
|
var NotificationGenericPolicy = GObject.registerClass({
|
||||||
class NotificationGenericPolicy extends NotificationPolicy {
|
GTypeName: 'MessageTray_NotificationGenericPolicy'
|
||||||
constructor() {
|
}, class NotificationGenericPolicy extends NotificationPolicy {
|
||||||
super();
|
_init() {
|
||||||
|
super._init();
|
||||||
this.id = 'generic';
|
this.id = 'generic';
|
||||||
|
|
||||||
this._masterSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.notifications' });
|
this._masterSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.notifications' });
|
||||||
this._masterSettings.connect('changed', this._changed.bind(this));
|
this._masterSettings.connect('changed', this._changed.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
store() { }
|
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this._masterSettings.run_dispose();
|
this._masterSettings.run_dispose();
|
||||||
|
|
||||||
|
super.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
_changed(settings, key) {
|
_changed(settings, key) {
|
||||||
this.emit('policy-changed', key);
|
if (this.constructor.find_property(key))
|
||||||
|
this.notify(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
get showBanners() {
|
get showBanners() {
|
||||||
@ -209,12 +221,13 @@ class NotificationGenericPolicy extends NotificationPolicy {
|
|||||||
get showInLockScreen() {
|
get showInLockScreen() {
|
||||||
return this._masterSettings.get_boolean('show-in-lock-screen');
|
return this._masterSettings.get_boolean('show-in-lock-screen');
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
var NotificationApplicationPolicy =
|
var NotificationApplicationPolicy = GObject.registerClass({
|
||||||
class NotificationApplicationPolicy extends NotificationPolicy {
|
GTypeName: 'MessageTray_NotificationApplicationPolicy'
|
||||||
constructor(id) {
|
}, class NotificationApplicationPolicy extends NotificationPolicy {
|
||||||
super();
|
_init(id) {
|
||||||
|
super._init();
|
||||||
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this._canonicalId = this._canonicalizeId(id);
|
this._canonicalId = this._canonicalizeId(id);
|
||||||
@ -240,12 +253,13 @@ class NotificationApplicationPolicy extends NotificationPolicy {
|
|||||||
destroy() {
|
destroy() {
|
||||||
this._masterSettings.run_dispose();
|
this._masterSettings.run_dispose();
|
||||||
this._settings.run_dispose();
|
this._settings.run_dispose();
|
||||||
|
|
||||||
|
super.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
_changed(settings, key) {
|
_changed(settings, key) {
|
||||||
this.emit('policy-changed', key);
|
if (this.constructor.find_property(key))
|
||||||
if (key == 'enable')
|
this.notify(key);
|
||||||
this.emit('enable-changed');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_canonicalizeId(id) {
|
_canonicalizeId(id) {
|
||||||
@ -279,7 +293,7 @@ class NotificationApplicationPolicy extends NotificationPolicy {
|
|||||||
get detailsInLockScreen() {
|
get detailsInLockScreen() {
|
||||||
return this._settings.get_boolean('details-in-lock-screen');
|
return this._settings.get_boolean('details-in-lock-screen');
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
// Notification:
|
// Notification:
|
||||||
// @source: the notification's Source
|
// @source: the notification's Source
|
||||||
@ -336,8 +350,23 @@ class NotificationApplicationPolicy extends NotificationPolicy {
|
|||||||
// @source allows playing sounds).
|
// @source allows playing sounds).
|
||||||
//
|
//
|
||||||
// [1] https://developer.gnome.org/notification-spec/#markup
|
// [1] https://developer.gnome.org/notification-spec/#markup
|
||||||
var Notification = class Notification {
|
var Notification = GObject.registerClass({
|
||||||
constructor(source, title, banner, params) {
|
GTypeName: 'MessageTray_Notification',
|
||||||
|
Properties: {
|
||||||
|
'acknowledged': GObject.ParamSpec.boolean(
|
||||||
|
'acknowledged', 'acknowledged', 'acknowledged',
|
||||||
|
GObject.ParamFlags.READWRITE,
|
||||||
|
false),
|
||||||
|
},
|
||||||
|
Signals: {
|
||||||
|
'activated': {},
|
||||||
|
'destroy': { param_types: [GObject.TYPE_UINT] },
|
||||||
|
'updated': { param_types: [GObject.TYPE_BOOLEAN] },
|
||||||
|
}
|
||||||
|
}, class Notification extends GObject.Object {
|
||||||
|
_init(source, title, banner, params) {
|
||||||
|
super._init();
|
||||||
|
|
||||||
this.source = source;
|
this.source = source;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.urgency = Urgency.NORMAL;
|
this.urgency = Urgency.NORMAL;
|
||||||
@ -422,7 +451,7 @@ var Notification = class Notification {
|
|||||||
if (this._acknowledged == v)
|
if (this._acknowledged == v)
|
||||||
return;
|
return;
|
||||||
this._acknowledged = v;
|
this._acknowledged = v;
|
||||||
this.emit('acknowledged-changed');
|
this.notify('acknowledged');
|
||||||
}
|
}
|
||||||
|
|
||||||
setUrgency(urgency) {
|
setUrgency(urgency) {
|
||||||
@ -479,8 +508,7 @@ var Notification = class Notification {
|
|||||||
destroy(reason = NotificationDestroyedReason.DISMISSED) {
|
destroy(reason = NotificationDestroyedReason.DISMISSED) {
|
||||||
this.emit('destroy', reason);
|
this.emit('destroy', reason);
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
Signals.addSignalMethods(Notification.prototype);
|
|
||||||
|
|
||||||
var NotificationBanner =
|
var NotificationBanner =
|
||||||
class NotificationBanner extends Calendar.NotificationMessage {
|
class NotificationBanner extends Calendar.NotificationMessage {
|
||||||
@ -640,7 +668,7 @@ class SourceActorWithLabel extends SourceActor {
|
|||||||
|
|
||||||
this.add_actor(this._counterBin);
|
this.add_actor(this._counterBin);
|
||||||
|
|
||||||
this._countUpdatedId = this._source.connect('count-updated', this._updateCount.bind(this));
|
this._countUpdatedId = this._source.connect('notify::count', this._updateCount.bind(this));
|
||||||
this._updateCount();
|
this._updateCount();
|
||||||
|
|
||||||
this.connect('destroy', () => {
|
this.connect('destroy', () => {
|
||||||
@ -688,11 +716,34 @@ class SourceActorWithLabel extends SourceActor {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var Source = class Source {
|
var Source = GObject.registerClass({
|
||||||
constructor(title, iconName) {
|
GTypeName: 'MessageTray_Source',
|
||||||
|
Properties: {
|
||||||
|
'count': GObject.ParamSpec.int(
|
||||||
|
'count', 'count', 'count',
|
||||||
|
GObject.ParamFlags.READABLE,
|
||||||
|
0, GLib.MAXINT32, 0),
|
||||||
|
'policy': GObject.ParamSpec.object(
|
||||||
|
'policy', 'policy', 'policy',
|
||||||
|
GObject.ParamFlags.READWRITE,
|
||||||
|
NotificationPolicy.$gtype),
|
||||||
|
'title': GObject.ParamSpec.string(
|
||||||
|
'title', 'title', 'title',
|
||||||
|
GObject.ParamFlags.READWRITE,
|
||||||
|
null),
|
||||||
|
},
|
||||||
|
Signals: {
|
||||||
|
'destroy': { param_types: [GObject.TYPE_UINT] },
|
||||||
|
'icon-updated': {},
|
||||||
|
'notification-added': { param_types: [Notification.$gtype] },
|
||||||
|
'notification-show': { param_types: [Notification.$gtype] },
|
||||||
|
}
|
||||||
|
}, class Source extends GObject.Object {
|
||||||
|
_init(title, iconName) {
|
||||||
|
super._init({ title: title });
|
||||||
|
|
||||||
this.SOURCE_ICON_SIZE = 48;
|
this.SOURCE_ICON_SIZE = 48;
|
||||||
|
|
||||||
this.title = title;
|
|
||||||
this.iconName = iconName;
|
this.iconName = iconName;
|
||||||
|
|
||||||
this.isChat = false;
|
this.isChat = false;
|
||||||
@ -727,7 +778,7 @@ var Source = class Source {
|
|||||||
}
|
}
|
||||||
|
|
||||||
countUpdated() {
|
countUpdated() {
|
||||||
this.emit('count-updated');
|
super.notify('count');
|
||||||
}
|
}
|
||||||
|
|
||||||
_createPolicy() {
|
_createPolicy() {
|
||||||
@ -741,8 +792,11 @@ var Source = class Source {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setTitle(newTitle) {
|
setTitle(newTitle) {
|
||||||
|
if (this.title == newTitle)
|
||||||
|
return;
|
||||||
|
|
||||||
this.title = newTitle;
|
this.title = newTitle;
|
||||||
this.emit('title-changed');
|
this.notify('title');
|
||||||
}
|
}
|
||||||
|
|
||||||
createBanner(notification) {
|
createBanner(notification) {
|
||||||
@ -781,24 +835,39 @@ var Source = class Source {
|
|||||||
this.notifications.shift().destroy(NotificationDestroyedReason.EXPIRED);
|
this.notifications.shift().destroy(NotificationDestroyedReason.EXPIRED);
|
||||||
|
|
||||||
notification.connect('destroy', this._onNotificationDestroy.bind(this));
|
notification.connect('destroy', this._onNotificationDestroy.bind(this));
|
||||||
notification.connect('acknowledged-changed', this.countUpdated.bind(this));
|
notification.connect('notify::acknowledged', this.countUpdated.bind(this));
|
||||||
this.notifications.push(notification);
|
this.notifications.push(notification);
|
||||||
this.emit('notification-added', notification);
|
this.emit('notification-added', notification);
|
||||||
|
|
||||||
this.countUpdated();
|
this.countUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
notify(notification) {
|
showNotification(notification) {
|
||||||
notification.acknowledged = false;
|
notification.acknowledged = false;
|
||||||
this.pushNotification(notification);
|
this.pushNotification(notification);
|
||||||
|
|
||||||
if (this.policy.showBanners || notification.urgency == Urgency.CRITICAL) {
|
if (this.policy.showBanners || notification.urgency == Urgency.CRITICAL) {
|
||||||
this.emit('notify', notification);
|
this.emit('notification-show', notification);
|
||||||
} else {
|
} else {
|
||||||
notification.playSound();
|
notification.playSound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notify(propName) {
|
||||||
|
if (propName instanceof Notification) {
|
||||||
|
try {
|
||||||
|
throw new Error('Source.notify() has been moved to Source.showNotification()' +
|
||||||
|
'this code will break in the future');
|
||||||
|
} catch (e) {
|
||||||
|
logError(e);
|
||||||
|
this.showNotification(propName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
super.notify(propName);
|
||||||
|
}
|
||||||
|
|
||||||
destroy(reason) {
|
destroy(reason) {
|
||||||
this.policy.destroy();
|
this.policy.destroy();
|
||||||
|
|
||||||
@ -826,8 +895,7 @@ var Source = class Source {
|
|||||||
|
|
||||||
this.countUpdated();
|
this.countUpdated();
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
Signals.addSignalMethods(Source.prototype);
|
|
||||||
|
|
||||||
var MessageTray = class MessageTray {
|
var MessageTray = class MessageTray {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -997,22 +1065,22 @@ var MessageTray = class MessageTray {
|
|||||||
// Register that we got a notification for this source
|
// Register that we got a notification for this source
|
||||||
source.policy.store();
|
source.policy.store();
|
||||||
|
|
||||||
source.policy.connect('enable-changed', () => {
|
source.policy.connect('notify::enable', () => {
|
||||||
this._onSourceEnableChanged(source.policy, source);
|
this._onSourceEnableChanged(source.policy, source);
|
||||||
});
|
});
|
||||||
source.policy.connect('policy-changed', this._updateState.bind(this));
|
source.policy.connect('notify', this._updateState.bind(this));
|
||||||
this._onSourceEnableChanged(source.policy, source);
|
this._onSourceEnableChanged(source.policy, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
_addSource(source) {
|
_addSource(source) {
|
||||||
let obj = {
|
let obj = {
|
||||||
notifyId: 0,
|
showId: 0,
|
||||||
destroyId: 0,
|
destroyId: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
this._sources.set(source, obj);
|
this._sources.set(source, obj);
|
||||||
|
|
||||||
obj.notifyId = source.connect('notify', this._onNotify.bind(this));
|
obj.showId = source.connect('notification-show', this._onNotificationShow.bind(this));
|
||||||
obj.destroyId = source.connect('destroy', this._onSourceDestroy.bind(this));
|
obj.destroyId = source.connect('destroy', this._onSourceDestroy.bind(this));
|
||||||
|
|
||||||
this.emit('source-added', source);
|
this.emit('source-added', source);
|
||||||
@ -1022,7 +1090,7 @@ var MessageTray = class MessageTray {
|
|||||||
let obj = this._sources.get(source);
|
let obj = this._sources.get(source);
|
||||||
this._sources.delete(source);
|
this._sources.delete(source);
|
||||||
|
|
||||||
source.disconnect(obj.notifyId);
|
source.disconnect(obj.showId);
|
||||||
source.disconnect(obj.destroyId);
|
source.disconnect(obj.destroyId);
|
||||||
|
|
||||||
this.emit('source-removed', source);
|
this.emit('source-removed', source);
|
||||||
@ -1063,7 +1131,7 @@ var MessageTray = class MessageTray {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onNotify(source, notification) {
|
_onNotificationShow(_source, notification) {
|
||||||
if (this._notification == notification) {
|
if (this._notification == notification) {
|
||||||
// If a notification that is being shown is updated, we update
|
// If a notification that is being shown is updated, we update
|
||||||
// how it is shown and extend the time until it auto-hides.
|
// how it is shown and extend the time until it auto-hides.
|
||||||
@ -1460,12 +1528,13 @@ var MessageTray = class MessageTray {
|
|||||||
};
|
};
|
||||||
Signals.addSignalMethods(MessageTray.prototype);
|
Signals.addSignalMethods(MessageTray.prototype);
|
||||||
|
|
||||||
var SystemNotificationSource = class SystemNotificationSource extends Source {
|
var SystemNotificationSource = GObject.registerClass(
|
||||||
constructor() {
|
class SystemNotificationSource extends Source {
|
||||||
super(_("System Information"), 'dialog-information-symbolic');
|
_init() {
|
||||||
|
super._init(_("System Information"), 'dialog-information-symbolic');
|
||||||
}
|
}
|
||||||
|
|
||||||
open() {
|
open() {
|
||||||
this.destroy();
|
this.destroy();
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||||
/* exported NotificationDaemon */
|
/* exported NotificationDaemon */
|
||||||
|
|
||||||
const { GdkPixbuf, Gio, GLib, Shell, St } = imports.gi;
|
const { GdkPixbuf, Gio, GLib, GObject, Shell, St } = imports.gi;
|
||||||
|
|
||||||
const Config = imports.misc.config;
|
const Config = imports.misc.config;
|
||||||
const Main = imports.ui.main;
|
const Main = imports.ui.main;
|
||||||
@ -412,10 +412,10 @@ var FdoNotificationDaemon = class FdoNotificationDaemon {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var FdoNotificationDaemonSource =
|
var FdoNotificationDaemonSource = GObject.registerClass(
|
||||||
class FdoNotificationDaemonSource extends MessageTray.Source {
|
class FdoNotificationDaemonSource extends MessageTray.Source {
|
||||||
constructor(title, pid, sender, appId) {
|
_init(title, pid, sender, appId) {
|
||||||
super(title);
|
super._init(title);
|
||||||
|
|
||||||
this.pid = pid;
|
this.pid = pid;
|
||||||
this.app = this._getApp(appId);
|
this.app = this._getApp(appId);
|
||||||
@ -464,7 +464,7 @@ class FdoNotificationDaemonSource extends MessageTray.Source {
|
|||||||
if (notification.resident && this.app && tracker.focus_app == this.app)
|
if (notification.resident && this.app && tracker.focus_app == this.app)
|
||||||
this.pushNotification(notification);
|
this.pushNotification(notification);
|
||||||
else
|
else
|
||||||
this.notify(notification);
|
this.showNotification(notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
_getApp(appId) {
|
_getApp(appId) {
|
||||||
@ -526,7 +526,7 @@ class FdoNotificationDaemonSource extends MessageTray.Source {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
const PRIORITY_URGENCY_MAP = {
|
const PRIORITY_URGENCY_MAP = {
|
||||||
low: MessageTray.Urgency.LOW,
|
low: MessageTray.Urgency.LOW,
|
||||||
@ -535,10 +535,10 @@ const PRIORITY_URGENCY_MAP = {
|
|||||||
urgent: MessageTray.Urgency.CRITICAL
|
urgent: MessageTray.Urgency.CRITICAL
|
||||||
};
|
};
|
||||||
|
|
||||||
var GtkNotificationDaemonNotification =
|
var GtkNotificationDaemonNotification = GObject.registerClass(
|
||||||
class GtkNotificationDaemonNotification extends MessageTray.Notification {
|
class GtkNotificationDaemonNotification extends MessageTray.Notification {
|
||||||
constructor(source, notification) {
|
_init(source, notification) {
|
||||||
super(source);
|
super._init(source);
|
||||||
this._serialized = GLib.Variant.new('a{sv}', notification);
|
this._serialized = GLib.Variant.new('a{sv}', notification);
|
||||||
|
|
||||||
let { title,
|
let { title,
|
||||||
@ -602,7 +602,7 @@ class GtkNotificationDaemonNotification extends MessageTray.Notification {
|
|||||||
serialize() {
|
serialize() {
|
||||||
return this._serialized;
|
return this._serialized;
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
const FdoApplicationIface = loadInterfaceXML('org.freedesktop.Application');
|
const FdoApplicationIface = loadInterfaceXML('org.freedesktop.Application');
|
||||||
const FdoApplicationProxy = Gio.DBusProxy.makeProxyWrapper(FdoApplicationIface);
|
const FdoApplicationProxy = Gio.DBusProxy.makeProxyWrapper(FdoApplicationIface);
|
||||||
@ -618,9 +618,9 @@ function getPlatformData() {
|
|||||||
|
|
||||||
function InvalidAppError() {}
|
function InvalidAppError() {}
|
||||||
|
|
||||||
var GtkNotificationDaemonAppSource =
|
var GtkNotificationDaemonAppSource = GObject.registerClass(
|
||||||
class GtkNotificationDaemonAppSource extends MessageTray.Source {
|
class GtkNotificationDaemonAppSource extends MessageTray.Source {
|
||||||
constructor(appId) {
|
_init(appId) {
|
||||||
let objectPath = objectPathFromAppId(appId);
|
let objectPath = objectPathFromAppId(appId);
|
||||||
if (!GLib.Variant.is_object_path(objectPath))
|
if (!GLib.Variant.is_object_path(objectPath))
|
||||||
throw new InvalidAppError();
|
throw new InvalidAppError();
|
||||||
@ -629,7 +629,7 @@ class GtkNotificationDaemonAppSource extends MessageTray.Source {
|
|||||||
if (!app)
|
if (!app)
|
||||||
throw new InvalidAppError();
|
throw new InvalidAppError();
|
||||||
|
|
||||||
super(app.get_name());
|
super._init(app.get_name());
|
||||||
|
|
||||||
this._appId = appId;
|
this._appId = appId;
|
||||||
this._app = app;
|
this._app = app;
|
||||||
@ -690,7 +690,7 @@ class GtkNotificationDaemonAppSource extends MessageTray.Source {
|
|||||||
this._notifications[notificationId] = notification;
|
this._notifications[notificationId] = notification;
|
||||||
|
|
||||||
if (showBanner)
|
if (showBanner)
|
||||||
this.notify(notification);
|
this.showNotification(notification);
|
||||||
else
|
else
|
||||||
this.pushNotification(notification);
|
this.pushNotification(notification);
|
||||||
|
|
||||||
@ -716,7 +716,7 @@ class GtkNotificationDaemonAppSource extends MessageTray.Source {
|
|||||||
}
|
}
|
||||||
return [this._appId, notifications];
|
return [this._appId, notifications];
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
const GtkNotificationsIface = loadInterfaceXML('org.gtk.Notifications');
|
const GtkNotificationsIface = loadInterfaceXML('org.gtk.Notifications');
|
||||||
|
|
||||||
@ -742,7 +742,7 @@ var GtkNotificationDaemon = class GtkNotificationDaemon {
|
|||||||
delete this._sources[appId];
|
delete this._sources[appId];
|
||||||
this._saveNotifications();
|
this._saveNotifications();
|
||||||
});
|
});
|
||||||
source.connect('count-updated', this._saveNotifications.bind(this));
|
source.connect('notify::count', this._saveNotifications.bind(this));
|
||||||
Main.messageTray.add(source);
|
Main.messageTray.add(source);
|
||||||
this._sources[appId] = source;
|
this._sources[appId] = source;
|
||||||
return source;
|
return source;
|
||||||
|
@ -72,7 +72,7 @@ var ShellInfo = class {
|
|||||||
if (undoCallback)
|
if (undoCallback)
|
||||||
notification.addAction(_("Undo"), this._onUndoClicked.bind(this));
|
notification.addAction(_("Undo"), this._onUndoClicked.bind(this));
|
||||||
|
|
||||||
this._source.notify(notification);
|
this._source.showNotification(notification);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -224,14 +224,14 @@ var NotificationsBox = class {
|
|||||||
this._showSource(source, obj, obj.sourceBox);
|
this._showSource(source, obj, obj.sourceBox);
|
||||||
this._notificationBox.add(obj.sourceBox, { x_fill: false, x_align: St.Align.START });
|
this._notificationBox.add(obj.sourceBox, { x_fill: false, x_align: St.Align.START });
|
||||||
|
|
||||||
obj.sourceCountChangedId = source.connect('count-updated', source => {
|
obj.sourceCountChangedId = source.connect('notify::count', source => {
|
||||||
this._countChanged(source, obj);
|
this._countChanged(source, obj);
|
||||||
});
|
});
|
||||||
obj.sourceTitleChangedId = source.connect('title-changed', source => {
|
obj.sourceTitleChangedId = source.connect('notify::title', source => {
|
||||||
this._titleChanged(source, obj);
|
this._titleChanged(source, obj);
|
||||||
});
|
});
|
||||||
obj.policyChangedId = source.policy.connect('policy-changed', (policy, key) => {
|
obj.policyChangedId = source.policy.connect('notify', (policy, pspec) => {
|
||||||
if (key == 'show-in-lock-screen')
|
if (pspec.name == 'show-in-lock-screen')
|
||||||
this._visibleChanged(source, obj);
|
this._visibleChanged(source, obj);
|
||||||
else
|
else
|
||||||
this._detailedChanged(source, obj);
|
this._detailedChanged(source, obj);
|
||||||
|
@ -219,9 +219,10 @@ var ShellMountOperation = class {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var ShellUnmountNotifier = class extends MessageTray.Source {
|
var ShellUnmountNotifier = GObject.registerClass(
|
||||||
constructor() {
|
class ShellUnmountNotifier extends MessageTray.Source {
|
||||||
super('', 'media-removable');
|
_init() {
|
||||||
|
super._init('', 'media-removable');
|
||||||
|
|
||||||
this._notification = null;
|
this._notification = null;
|
||||||
Main.messageTray.add(this);
|
Main.messageTray.add(this);
|
||||||
@ -238,7 +239,7 @@ var ShellUnmountNotifier = class extends MessageTray.Source {
|
|||||||
this._notification.update(header, text);
|
this._notification.update(header, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.notify(this._notification);
|
this.showNotification(this._notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
done(message) {
|
done(message) {
|
||||||
@ -251,10 +252,10 @@ var ShellUnmountNotifier = class extends MessageTray.Source {
|
|||||||
let notification = new MessageTray.Notification(this, message, null);
|
let notification = new MessageTray.Notification(this, message, null);
|
||||||
notification.setTransient(true);
|
notification.setTransient(true);
|
||||||
|
|
||||||
this.notify(notification);
|
this.showNotification(notification);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
var ShellMountQuestionDialog = GObject.registerClass({
|
var ShellMountQuestionDialog = GObject.registerClass({
|
||||||
Signals: { 'response': { param_types: [GObject.TYPE_INT] } }
|
Signals: { 'response': { param_types: [GObject.TYPE_INT] } }
|
||||||
|
@ -1706,7 +1706,7 @@ var NMApplet = class extends PanelMenu.SystemIndicator {
|
|||||||
this._notification.connect('destroy', () => {
|
this._notification.connect('destroy', () => {
|
||||||
this._notification = null;
|
this._notification = null;
|
||||||
});
|
});
|
||||||
this._source.notify(this._notification);
|
this._source.showNotification(this._notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onActivationFailed(_device, _reason) {
|
_onActivationFailed(_device, _reason) {
|
||||||
|
@ -284,7 +284,7 @@ var Indicator = class extends PanelMenu.SystemIndicator {
|
|||||||
if (app)
|
if (app)
|
||||||
app.activate();
|
app.activate();
|
||||||
});
|
});
|
||||||
this._source.notify(this._notification);
|
this._source.showNotification(this._notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Session callbacks */
|
/* Session callbacks */
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||||
/* exported WindowAttentionHandler */
|
/* exported WindowAttentionHandler */
|
||||||
|
|
||||||
const Shell = imports.gi.Shell;
|
const { GObject, Shell } = imports.gi;
|
||||||
|
|
||||||
const Main = imports.ui.main;
|
const Main = imports.ui.main;
|
||||||
const MessageTray = imports.ui.messageTray;
|
const MessageTray = imports.ui.messageTray;
|
||||||
@ -34,7 +34,7 @@ var WindowAttentionHandler = class {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
let app = this._tracker.get_window_app(window);
|
let app = this._tracker.get_window_app(window);
|
||||||
let source = new Source(app, window);
|
let source = new WindowAttentionSource(app, window);
|
||||||
Main.messageTray.add(source);
|
Main.messageTray.add(source);
|
||||||
|
|
||||||
let [title, banner] = this._getTitleAndBanner(app, window);
|
let [title, banner] = this._getTitleAndBanner(app, window);
|
||||||
@ -45,7 +45,7 @@ var WindowAttentionHandler = class {
|
|||||||
});
|
});
|
||||||
notification.setForFeedback(true);
|
notification.setForFeedback(true);
|
||||||
|
|
||||||
source.notify(notification);
|
source.showNotification(notification);
|
||||||
|
|
||||||
source.signalIDs.push(window.connect('notify::title', () => {
|
source.signalIDs.push(window.connect('notify::title', () => {
|
||||||
let [title, banner] = this._getTitleAndBanner(app, window);
|
let [title, banner] = this._getTitleAndBanner(app, window);
|
||||||
@ -54,9 +54,10 @@ var WindowAttentionHandler = class {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var Source = class WindowAttentionSource extends MessageTray.Source {
|
var WindowAttentionSource = GObject.registerClass(
|
||||||
constructor(app, window) {
|
class WindowAttentionSource extends MessageTray.Source {
|
||||||
super(app.get_name());
|
_init(app, window) {
|
||||||
|
super._init(app.get_name());
|
||||||
|
|
||||||
this._window = window;
|
this._window = window;
|
||||||
this._app = app;
|
this._app = app;
|
||||||
@ -102,4 +103,4 @@ var Source = class WindowAttentionSource extends MessageTray.Source {
|
|||||||
open() {
|
open() {
|
||||||
Main.activateWindow(this._window);
|
Main.activateWindow(this._window);
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user