From e4b72dd089dcb525e26dbac87e2f6ca3f38fd2cc Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Thu, 7 Mar 2024 16:24:44 +0100 Subject: [PATCH 1/2] appFavorites: Display it's own notification for every pin/unpin Show a notification for each user action instead of updating the notification currently displayed when the user pins or unpins. --- js/ui/appFavorites.js | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/js/ui/appFavorites.js b/js/ui/appFavorites.js index 576df3800..6dccf0f09 100644 --- a/js/ui/appFavorites.js +++ b/js/ui/appFavorites.js @@ -1,11 +1,10 @@ // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- +import * as MessageTray from './messageTray.js'; import Shell from 'gi://Shell'; import * as ParentalControlsManager from '../misc/parentalControlsManager.js'; import * as Signals from '../misc/signals.js'; -import * as Main from './main.js'; - // In alphabetical order const RENAMED_DESKTOP_IDS = { 'baobab.desktop': 'org.gnome.baobab.desktop', @@ -161,13 +160,11 @@ class AppFavorites extends Signals.EventEmitter { if (!this._addFavorite(appId, pos)) return; - let app = Shell.AppSystem.get_default().lookup_app(appId); + const app = Shell.AppSystem.get_default().lookup_app(appId); - let msg = _('%s has been pinned to the dash.').format(app.get_name()); - Main.overview.setMessage(msg, { - forFeedback: true, - undoCallback: () => this._removeFavorite(appId), - }); + this.showNotification(_('%s has been pinned to the dash.').format(app.get_name()), + null, + () => this._removeFavorite(appId)); } addFavorite(appId) { @@ -196,11 +193,22 @@ class AppFavorites extends Signals.EventEmitter { if (!this._removeFavorite(appId)) return; - let msg = _('%s has been unpinned from the dash.').format(app.get_name()); - Main.overview.setMessage(msg, { + this.showNotification(_('%s has been unpinned from the dash.').format(app.get_name()), + null, + () => this._addFavorite(appId, pos)); + } + + showNotification(title, body, undoCallback) { + const source = MessageTray.getSystemSource(); + const notification = new MessageTray.Notification({ + source, + title, + body, + isTransient: true, forFeedback: true, - undoCallback: () => this._addFavorite(appId, pos), }); + notification.addAction(_('Undo'), () => undoCallback()); + source.addNotification(notification); } } From 3c2516bb1e474b0f3da49456c56435058b33bd84 Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Thu, 7 Mar 2024 16:29:31 +0100 Subject: [PATCH 2/2] overview: Drop unused ShellInfo object This object isn't used anymore and it's really easy to create a new system notification via the appropriate notification source. --- js/ui/overview.js | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) diff --git a/js/ui/overview.js b/js/ui/overview.js index 7e431b68e..fbfd2f2b1 100644 --- a/js/ui/overview.js +++ b/js/ui/overview.js @@ -16,9 +16,7 @@ export const ANIMATION_TIME = 250; import * as DND from './dnd.js'; import * as LayoutManager from './layout.js'; import * as Main from './main.js'; -import * as MessageTray from './messageTray.js'; import * as OverviewControls from './overviewControls.js'; -import * as Params from '../misc/params.js'; import * as SwipeTracker from './swipeTracker.js'; import * as WindowManager from './windowManager.js'; import * as WorkspaceThumbnail from './workspaceThumbnail.js'; @@ -27,36 +25,6 @@ const DND_WINDOW_SWITCH_TIMEOUT = 750; const OVERVIEW_ACTIVATION_TIMEOUT = 0.5; -class ShellInfo { - setMessage(title, options) { - options = Params.parse(options, { - undoCallback: null, - forFeedback: false, - }); - - const source = MessageTray.getSystemSource(); - let undoCallback = options.undoCallback; - let forFeedback = options.forFeedback; - - if (!this._notification) { - this._notification = new MessageTray.Notification({ - source, - isTransient: true, - forFeedback, - }); - this._notification.connect('destroy', () => delete this._notification); - } - this._notification.set({title}); - - this._notification.clearActions(); - - if (undoCallback) - this._notification.addAction(_('Undo'), () => undoCallback()); - - source.addNotification(this._notification); - } -} - const OverviewActor = GObject.registerClass( class OverviewActor extends St.BoxLayout { _init() { @@ -252,8 +220,6 @@ export class Overview extends Signals.EventEmitter { this._overview._delegate = this; Main.layoutManager.overviewGroup.add_child(this._overview); - this._shellInfo = new ShellInfo(); - Main.layoutManager.connect('monitors-changed', this._relayout.bind(this)); this._relayout(); @@ -275,18 +241,6 @@ export class Overview extends Signals.EventEmitter { this._swipeTracker = swipeTracker; } - // - // options: - // - undoCallback (function): the callback to be called if undo support is needed - // - forFeedback (boolean): whether the message is for direct feedback of a user action - // - setMessage(text, options) { - if (this.isDummy) - return; - - this._shellInfo.setMessage(text, options); - } - _changeShownState(state) { const {allowedTransitions} = OVERVIEW_SHOWN_TRANSITIONS[this._shownState];