diff --git a/js/ui/components/autorunManager.js b/js/ui/components/autorunManager.js index 1b8f71895..40dd5858d 100644 --- a/js/ui/components/autorunManager.js +++ b/js/ui/components/autorunManager.js @@ -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); diff --git a/js/ui/components/networkAgent.js b/js/ui/components/networkAgent.js index bab13b184..aad9ecf4f 100644 --- a/js/ui/components/networkAgent.js +++ b/js/ui/components/networkAgent.js @@ -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', () => { diff --git a/js/ui/extensionSystem.js b/js/ui/extensionSystem.js index a74e08bac..8e4af6f15 100644 --- a/js/ui/extensionSystem.js +++ b/js/ui/extensionSystem.js @@ -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); diff --git a/js/ui/main.js b/js/ui/main.js index a090a76ae..8a3c177d9 100644 --- a/js/ui/main.js +++ b/js/ui/main.js @@ -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); } diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index 11e57150b..9d9aaaef0 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -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) { diff --git a/js/ui/notificationDaemon.js b/js/ui/notificationDaemon.js index ed3f58720..a3b46b863 100644 --- a/js/ui/notificationDaemon.js +++ b/js/ui/notificationDaemon.js @@ -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; diff --git a/js/ui/overview.js b/js/ui/overview.js index 32a9df89d..b16f5a26b 100644 --- a/js/ui/overview.js +++ b/js/ui/overview.js @@ -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); diff --git a/js/ui/screenshot.js b/js/ui/screenshot.js index d19c6e7b9..d65dc82f3 100644 --- a/js/ui/screenshot.js +++ b/js/ui/screenshot.js @@ -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. diff --git a/js/ui/shellMountOperation.js b/js/ui/shellMountOperation.js index 9188410a5..24a38c8b6 100644 --- a/js/ui/shellMountOperation.js +++ b/js/ui/shellMountOperation.js @@ -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'; diff --git a/js/ui/status/network.js b/js/ui/status/network.js index 86cfa95f8..ae25af6f3 100644 --- a/js/ui/status/network.js +++ b/js/ui/status/network.js @@ -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); diff --git a/js/ui/status/thunderbolt.js b/js/ui/status/thunderbolt.js index 96d84d368..e70ca2435 100644 --- a/js/ui/status/thunderbolt.js +++ b/js/ui/status/thunderbolt.js @@ -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', () => { diff --git a/js/ui/windowAttentionHandler.js b/js/ui/windowAttentionHandler.js index ee701394c..7c3e53fbf 100644 --- a/js/ui/windowAttentionHandler.js +++ b/js/ui/windowAttentionHandler.js @@ -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); } } diff --git a/tests/shell/basic.js b/tests/shell/basic.js index 5310a31b2..712091f4d 100644 --- a/tests/shell/basic.js +++ b/tests/shell/basic.js @@ -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);