messageTray: Only take params in Notification
constructor
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3173>
This commit is contained in:
parent
251a5e9d20
commit
d54219c098
@ -187,10 +187,10 @@ class AutorunDispatcher {
|
||||
return;
|
||||
|
||||
const source = MessageTray.getSystemSource();
|
||||
const notification = new MessageTray.Notification(
|
||||
const notification = new MessageTray.Notification({
|
||||
source,
|
||||
mount.get_name()
|
||||
);
|
||||
title: mount.get_name(),
|
||||
});
|
||||
notification.connect('activate', () => {
|
||||
const app = Gio.app_info_get_default_for_type('inode/directory', false);
|
||||
startAppForMount(app, mount);
|
||||
|
@ -782,7 +782,7 @@ class NetworkAgent {
|
||||
}
|
||||
|
||||
const source = MessageTray.getSystemSource();
|
||||
const notification = new MessageTray.Notification(source, title, body);
|
||||
const notification = new MessageTray.Notification({source, title, body});
|
||||
notification.iconName = 'dialog-password-symbolic';
|
||||
|
||||
notification.connect('activated', () => {
|
||||
|
@ -349,9 +349,11 @@ export class ExtensionManager extends Signals.EventEmitter {
|
||||
let source = new ExtensionUpdateSource();
|
||||
Main.messageTray.add(source);
|
||||
|
||||
let notification = new MessageTray.Notification(source,
|
||||
_('Extension Updates Available'),
|
||||
_('Extension updates are ready to be installed.'));
|
||||
const notification = new MessageTray.Notification({
|
||||
source,
|
||||
title: _('Extension Updates Available'),
|
||||
body: _('Extension updates are ready to be installed.'),
|
||||
});
|
||||
notification.connect('activated',
|
||||
() => source.open());
|
||||
source.addNotification(notification);
|
||||
|
@ -274,9 +274,11 @@ async function _initializeUI() {
|
||||
return; // assume user action
|
||||
|
||||
const source = MessageTray.getSystemSource();
|
||||
const notification = new MessageTray.Notification(source,
|
||||
_('System was put in unsafe mode'),
|
||||
_('Apps now have unrestricted access'));
|
||||
const notification = new MessageTray.Notification({
|
||||
source,
|
||||
title: _('System was put in unsafe mode'),
|
||||
body: _('Apps now have unrestricted access'),
|
||||
});
|
||||
notification.addAction(_('Undo'),
|
||||
() => (global.context.unsafe_mode = false));
|
||||
notification.setTransient(true);
|
||||
@ -614,7 +616,11 @@ export function loadTheme() {
|
||||
*/
|
||||
export function notify(msg, details) {
|
||||
const source = MessageTray.getSystemSource();
|
||||
let notification = new MessageTray.Notification(source, msg, details);
|
||||
const notification = new MessageTray.Notification({
|
||||
source,
|
||||
title: msg,
|
||||
body: details,
|
||||
});
|
||||
notification.setTransient(true);
|
||||
source.addNotification(notification);
|
||||
}
|
||||
|
@ -351,28 +351,13 @@ class Action extends GObject.Object {
|
||||
});
|
||||
|
||||
export class Notification extends GObject.Object {
|
||||
_init(source, title, banner, params) {
|
||||
super._init({source});
|
||||
constructor(params) {
|
||||
super(params);
|
||||
|
||||
this.title = title;
|
||||
this.urgency = Urgency.NORMAL;
|
||||
// 'transient' is a reserved keyword in JS, so we have to use an alternate variable name
|
||||
this.isTransient = false;
|
||||
this.privacyScope = PrivacyScope.USER;
|
||||
this.forFeedback = false;
|
||||
this.body = null;
|
||||
this.useBodyMarkup = false;
|
||||
this.sound = null;
|
||||
this._soundPlayed = false;
|
||||
this.actions = [];
|
||||
this.setResident(false);
|
||||
this._actions = [];
|
||||
|
||||
// If called with only one argument we assume the caller
|
||||
// will call .update() later on. This is the case of
|
||||
// NotificationDaemon, which wants to use the same code
|
||||
// for new and updated notifications
|
||||
if (arguments.length !== 1)
|
||||
this.update(title, banner, params);
|
||||
if (!this.datetime)
|
||||
this.datetime = GLib.DateTime.new_now_local();
|
||||
}
|
||||
|
||||
// update:
|
||||
@ -415,6 +400,10 @@ export class Notification extends GObject.Object {
|
||||
this.emit('updated', params.clear);
|
||||
}
|
||||
|
||||
get actions() {
|
||||
return this._actions;
|
||||
}
|
||||
|
||||
get iconName() {
|
||||
if (this.gicon instanceof Gio.ThemedIcon)
|
||||
return this.gicon.iconName;
|
||||
@ -472,18 +461,18 @@ export class Notification extends GObject.Object {
|
||||
|
||||
this.destroy();
|
||||
});
|
||||
this.actions.push(action);
|
||||
this._actions.push(action);
|
||||
this.emit('action-added', action);
|
||||
}
|
||||
|
||||
clearActions() {
|
||||
if (this.actions.length === 0)
|
||||
if (this._actions.length === 0)
|
||||
return;
|
||||
|
||||
this.actions.forEach(action => {
|
||||
this._actions.forEach(action => {
|
||||
this.emit('action-removed', action);
|
||||
});
|
||||
this.actions = [];
|
||||
this._actions = [];
|
||||
}
|
||||
|
||||
setUrgency(urgency) {
|
||||
|
@ -175,7 +175,7 @@ class FdoNotificationDaemon {
|
||||
? this._getSourceForApp(sender, app)
|
||||
: this._getSourceForPidAndName(sender, pid, appName);
|
||||
|
||||
notification = new MessageTray.Notification(source);
|
||||
notification = new MessageTray.Notification({source});
|
||||
this._notifications.set(id, notification);
|
||||
notification.connect('destroy', (n, reason) => {
|
||||
this._notifications.delete(id);
|
||||
@ -405,8 +405,8 @@ const PRIORITY_URGENCY_MAP = {
|
||||
|
||||
const GtkNotificationDaemonNotification = GObject.registerClass(
|
||||
class GtkNotificationDaemonNotification extends MessageTray.Notification {
|
||||
_init(source, id, notification) {
|
||||
super._init(source);
|
||||
constructor(source, id, notification) {
|
||||
super({source});
|
||||
this._serialized = GLib.Variant.new('a{sv}', notification);
|
||||
this.id = id;
|
||||
|
||||
|
@ -39,7 +39,10 @@ class ShellInfo {
|
||||
let forFeedback = options.forFeedback;
|
||||
|
||||
if (!this._notification) {
|
||||
this._notification = new MessageTray.Notification(source, text, null);
|
||||
this._notification = new MessageTray.Notification({
|
||||
source,
|
||||
title: text,
|
||||
});
|
||||
this._notification.setTransient(true);
|
||||
this._notification.setForFeedback(forFeedback);
|
||||
this._notification.connect('destroy', () => delete this._notification);
|
||||
|
@ -2087,12 +2087,12 @@ export const ScreenshotUI = GObject.registerClass({
|
||||
title: _('Screenshot'),
|
||||
iconName: 'screencast-recorded-symbolic',
|
||||
});
|
||||
const notification = new MessageTray.Notification(
|
||||
const notification = new MessageTray.Notification({
|
||||
source,
|
||||
title,
|
||||
// Translators: notification body when a screencast was recorded.
|
||||
this._screencastPath ? _('Click here to view the video.') : ''
|
||||
);
|
||||
body: this._screencastPath ? _('Click here to view the video.') : '',
|
||||
});
|
||||
notification.setTransient(true);
|
||||
|
||||
if (this._screencastPath) {
|
||||
@ -2329,14 +2329,15 @@ function _storeScreenshot(bytes, pixbuf) {
|
||||
title: _('Screenshot'),
|
||||
iconName: 'screenshot-recorded-symbolic',
|
||||
});
|
||||
const notification = new MessageTray.Notification(
|
||||
const notification = new MessageTray.Notification({
|
||||
source,
|
||||
// Translators: notification title.
|
||||
_('Screenshot captured'),
|
||||
title: _('Screenshot captured'),
|
||||
// Translators: notification body when a screenshot was captured.
|
||||
_('You can paste the image from the clipboard.'),
|
||||
{datetime: time, gicon: content}
|
||||
);
|
||||
body: _('You can paste the image from the clipboard.'),
|
||||
datetime: time,
|
||||
gicon: content,
|
||||
});
|
||||
|
||||
if (!disableSaveToDisk) {
|
||||
// Translators: button on the screenshot notification.
|
||||
|
@ -195,7 +195,7 @@ export class ShellMountOperation {
|
||||
this._notification?.destroy();
|
||||
|
||||
const source = MessageTray.getSystemSource();
|
||||
this._notification = new MessageTray.Notification(source, title, body);
|
||||
this._notification = new MessageTray.Notification({source, title, body});
|
||||
|
||||
this._notification.setTransient(true);
|
||||
this._notification.iconName = 'media-removable-symbolic';
|
||||
|
@ -2030,9 +2030,11 @@ class Indicator extends SystemIndicator {
|
||||
this._notification?.destroy();
|
||||
|
||||
const source = MessageTray.getSystemSource();
|
||||
this._notification = new MessageTray.Notification(source,
|
||||
_('Connection failed'),
|
||||
_('Activation of network connection failed'));
|
||||
this._notification = new MessageTray.Notification({
|
||||
source,
|
||||
title: _('Connection failed'),
|
||||
body: _('Activation of network connection failed'),
|
||||
});
|
||||
this._notification.iconName = 'network-error-symbolic';
|
||||
this._notification.setUrgency(MessageTray.Urgency.HIGH);
|
||||
this._notification.setTransient(true);
|
||||
|
@ -258,7 +258,7 @@ class Indicator extends SystemIndicator {
|
||||
this._notification.destroy();
|
||||
|
||||
const source = MessageTray.getSystemSource();
|
||||
this._notification = new MessageTray.Notification(source, title, body);
|
||||
this._notification = new MessageTray.Notification({source, title, body});
|
||||
this._notification.iconName = 'thunderbolt-symbolic';
|
||||
this._notification.setUrgency(MessageTray.Urgency.HIGH);
|
||||
this._notification.connect('destroy', () => {
|
||||
|
@ -37,9 +37,9 @@ export class WindowAttentionHandler {
|
||||
let source = new WindowAttentionSource(app, window);
|
||||
Main.messageTray.add(source);
|
||||
|
||||
let [title, banner] = this._getTitleAndBanner(app, window);
|
||||
let [title, body] = this._getTitleAndBanner(app, window);
|
||||
|
||||
let notification = new MessageTray.Notification(source, title, banner);
|
||||
let notification = new MessageTray.Notification({source, title, body});
|
||||
notification.connect('activated', () => {
|
||||
source.open();
|
||||
});
|
||||
@ -48,8 +48,8 @@ export class WindowAttentionHandler {
|
||||
source.addNotification(notification);
|
||||
|
||||
window.connectObject('notify::title', () => {
|
||||
[title, banner] = this._getTitleAndBanner(app, window);
|
||||
notification.update(title, banner);
|
||||
[title, body] = this._getTitleAndBanner(app, window);
|
||||
notification.update(title, body);
|
||||
}, source);
|
||||
}
|
||||
}
|
||||
|
@ -56,8 +56,10 @@ export async function run() {
|
||||
source.connect('notification-request-banner',
|
||||
() => Scripting.scriptEvent('notificationShowDone'));
|
||||
|
||||
const notification = new MessageTray.Notification(source,
|
||||
'A test notification');
|
||||
const notification = new MessageTray.Notification({
|
||||
source,
|
||||
title: 'A test notification',
|
||||
});
|
||||
source.addNotification(notification);
|
||||
await Scripting.sleep(400);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user