From b2b05a977049d12f15c18173c4c8456e5613d0aa Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Tue, 9 Apr 2024 13:05:33 +0200 Subject: [PATCH] messageTray: Use display-hint property instead of individual properties This makes use of the new display-hint instead of using individual properties. --- js/gdm/loginDialog.js | 2 +- js/ui/appFavorites.js | 3 +-- js/ui/main.js | 4 ++-- js/ui/messageTray.js | 10 ++++++---- js/ui/notificationDaemon.js | 17 +++++++++++------ js/ui/screenshot.js | 4 ++-- js/ui/shellMountOperation.js | 2 +- js/ui/status/network.js | 2 +- js/ui/unlockDialog.js | 4 +++- js/ui/windowAttentionHandler.js | 2 +- 10 files changed, 29 insertions(+), 21 deletions(-) diff --git a/js/gdm/loginDialog.js b/js/gdm/loginDialog.js index 593f8f582..c9c5ae487 100644 --- a/js/gdm/loginDialog.js +++ b/js/gdm/loginDialog.js @@ -1081,7 +1081,7 @@ export const LoginDialog = GObject.registerClass({ title: _('Login Attempt Timed Out'), body: _('Login took too long, please try again'), urgency: MessageTray.Urgency.CRITICAL, - isTransient: true, + displayHint: MessageTray.DisplayHint.TRANSIENT, }); this._conflictingSessionNotification.connect('destroy', () => { this._conflictingSessionNotification = null; diff --git a/js/ui/appFavorites.js b/js/ui/appFavorites.js index 6dccf0f09..86e5743b4 100644 --- a/js/ui/appFavorites.js +++ b/js/ui/appFavorites.js @@ -204,8 +204,7 @@ class AppFavorites extends Signals.EventEmitter { source, title, body, - isTransient: true, - forFeedback: true, + displayHint: MessageTray.DisplayHint.TRANSIENT | MessageTray.DisplayHint.FORCE_IMMEDIATELY, }); notification.addAction(_('Undo'), () => undoCallback()); source.addNotification(notification); diff --git a/js/ui/main.js b/js/ui/main.js index ad0ea962f..7a7a40c48 100644 --- a/js/ui/main.js +++ b/js/ui/main.js @@ -278,7 +278,7 @@ async function _initializeUI() { source, title: _('System was put in unsafe mode'), body: _('Apps now have unrestricted access'), - isTransient: true, + displayHint: MessageTray.DisplayHint.TRANSIENT, }); notification.addAction(_('Undo'), () => (global.context.unsafe_mode = false)); @@ -620,7 +620,7 @@ export function notify(msg, details) { source, title: msg, body: details, - isTransient: true, + displayHint: MessageTray.DisplayHint.TRANSIENT, }); source.addNotification(notification); } diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index a55c57563..2edab3ced 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -466,7 +466,7 @@ export class Notification extends GObject.Object { // because it is common for such notifications to update themselves with new // information based on the action. We'd like to display the updated information // in place, rather than pop-up a new notification. - if (this.resident) + if (this.displayHint & DisplayHint.RESIDENT) return; this.destroy(); @@ -499,7 +499,7 @@ export class Notification extends GObject.Object { // because it is common for such notifications to update themselves with new // information based on the action. We'd like to display the updated information // in place, rather than pop-up a new notification. - if (this.resident) + if (this.displayHint & DisplayHint.RESIDENT) return; this.destroy(); @@ -1093,7 +1093,9 @@ export const MessageTray = GObject.registerClass({ let nextNotification = this._notificationQueue[0] || null; if (hasNotifications && nextNotification) { let limited = this._busy || Main.layoutManager.primaryMonitor.inFullscreen; - let showNextNotification = !limited || nextNotification.forFeedback || nextNotification.urgency === Urgency.CRITICAL; + let showNextNotification = !limited || + nextNotification.displayHint & DisplayHint.FORCE_IMMEDIATELY || + nextNotification.urgency === Urgency.CRITICAL; if (showNextNotification) this._showNotification(); } @@ -1284,7 +1286,7 @@ export const MessageTray = GObject.registerClass({ _hideNotificationCompleted() { let notification = this._notification; this._notification = null; - if (!this._notificationRemoved && notification.isTransient) + if (!this._notificationRemoved && notification.displayHint & DisplayHint.TRANSIENT) notification.destroy(NotificationDestroyedReason.EXPIRED); this._pointerInNotification = false; diff --git a/js/ui/notificationDaemon.js b/js/ui/notificationDaemon.js index 6081303a8..806f21cdf 100644 --- a/js/ui/notificationDaemon.js +++ b/js/ui/notificationDaemon.js @@ -247,15 +247,20 @@ class FdoNotificationDaemon { notification.urgency = MessageTray.Urgency.CRITICAL; break; } - notification.resident = !!hints.resident; + + if (hints.resident) + notification.displayHint |= MessageTray.DisplayHint.RESIDENT; + // '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 - notification.isTransient = !!hints['transient']; + if (hints['transient']) + notification.displayHint |= MessageTray.DisplayHint.TRANSIENT; - let privacyScope = hints['x-gnome-privacy-scope'] || 'user'; - notification.privacyScope = privacyScope === 'system' - ? MessageTray.PrivacyScope.SYSTEM - : MessageTray.PrivacyScope.USER; + if (hints['x-gnome-privacy-scope'] === 'system') + notification.displayHint |= MessageTray.DisplayHint.SHOW_CONTENT_ON_LOCKSCREEN; + else + // Always show the notification on the lockscreen but without any content + notification.displayHint |= MessageTray.DisplayHint.SHOW_ON_LOCKSCREEN; // Only fallback to 'app-icon' when the source doesn't have a valid app const sourceGIcon = source.app ? null : this._iconForNotificationData(appIcon); diff --git a/js/ui/screenshot.js b/js/ui/screenshot.js index c39603aca..5b966eee1 100644 --- a/js/ui/screenshot.js +++ b/js/ui/screenshot.js @@ -2092,7 +2092,7 @@ export const ScreenshotUI = GObject.registerClass({ title, // Translators: notification body when a screencast was recorded. body: this._screencastPath ? _('Click here to view the video.') : '', - isTransient: true, + displayHint: MessageTray.DisplayHint.TRANSIENT, }); if (this._screencastPath) { @@ -2337,7 +2337,7 @@ function _storeScreenshot(bytes, pixbuf) { body: _('You can paste the image from the clipboard.'), datetime: time, gicon: content, - isTransient: true, + displayHint: MessageTray.DisplayHint.TRANSIENT, }); if (!disableSaveToDisk) { diff --git a/js/ui/shellMountOperation.js b/js/ui/shellMountOperation.js index 27f12fbf9..9774faaa5 100644 --- a/js/ui/shellMountOperation.js +++ b/js/ui/shellMountOperation.js @@ -199,7 +199,7 @@ export class ShellMountOperation { source, title, body, - isTransient: true, + displayHint: MessageTray.DisplayHint.TRANSIENT, iconName: 'media-removable-symbolic', }); diff --git a/js/ui/status/network.js b/js/ui/status/network.js index 404733b74..2f256b8f5 100644 --- a/js/ui/status/network.js +++ b/js/ui/status/network.js @@ -2036,7 +2036,7 @@ class Indicator extends SystemIndicator { body: _('Activation of network connection failed'), iconName: 'network-error-symbolic', urgency: MessageTray.Urgency.HIGH, - isTransient: true, + displayHint: MessageTray.DisplayHint.TRANSIENT, }); this._notification.connect('destroy', () => (this._notification = null)); diff --git a/js/ui/unlockDialog.js b/js/ui/unlockDialog.js index f741b20a6..1233663a0 100644 --- a/js/ui/unlockDialog.js +++ b/js/ui/unlockDialog.js @@ -166,7 +166,9 @@ const NotificationsBox = GObject.registerClass({ _shouldShowDetails(source) { return source.policy.detailsInLockScreen || - source.narrowestPrivacyScope === MessageTray.PrivacyScope.SYSTEM; + source.notifications.every(n => + n.displayHint & MessageTray.DisplayHint.SHOW_CONTENT_ON_LOCKSCREEN + ); } _updateSourceBoxStyle(source, obj, box) { diff --git a/js/ui/windowAttentionHandler.js b/js/ui/windowAttentionHandler.js index e346b1cad..d045f8788 100644 --- a/js/ui/windowAttentionHandler.js +++ b/js/ui/windowAttentionHandler.js @@ -43,7 +43,7 @@ export class WindowAttentionHandler { source, title, body, - forFeedback: true, + displayHint: MessageTray.DisplayHint.FORCE_IMMEDIATELY, }); notification.connect('activated', () => { source.open();