[polari] Replace custom in-app notifications with Adw.Toast
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] Replace custom in-app notifications with Adw.Toast
- Date: Sat, 19 Mar 2022 15:19:36 +0000 (UTC)
commit 83660634d2e8d0ffa7a6e1ec53a47bdf6ebb0b9b
Author: Florian Müllner <fmuellner gnome org>
Date: Wed Feb 16 17:35:15 2022 +0100
Replace custom in-app notifications with Adw.Toast
We finally have a standard widget for in-app notifications, so use
those instead of our own (much less polished) implementation.
Part-of: <https://gitlab.gnome.org/GNOME/polari/-/merge_requests/250>
data/resources/main-window.ui | 2 +-
src/application.js | 23 ++++++++++++-----------
src/mainWindow.js | 11 +++--------
src/utils.js | 9 +++++----
4 files changed, 21 insertions(+), 24 deletions(-)
---
diff --git a/data/resources/main-window.ui b/data/resources/main-window.ui
index b64891a3..355f8d17 100644
--- a/data/resources/main-window.ui
+++ b/data/resources/main-window.ui
@@ -227,7 +227,7 @@
</object>
</child>
<child>
- <object class="GtkOverlay" id="overlay">
+ <object class="AdwToastOverlay" id="overlay">
<property name="vexpand">True</property>
<child>
<object class="Gjs_RoomStack" id="roomStack">
diff --git a/src/application.js b/src/application.js
index db2ee31a..6d348afe 100644
--- a/src/application.js
+++ b/src/application.js
@@ -498,10 +498,10 @@ class Application extends Adw.Application {
[,, server, port, room] = uri.match(IRC_SCHEMA_REGEX);
success = true;
} catch (e) {
- let label = _('Failed to open link');
- let n = new AppNotifications.MessageNotification(
- label, 'dialog-error-symbolic');
- this.active_window?.queueNotification(n);
+ const toast = new Adw.Toast({
+ title: _('Failed to open link'),
+ });
+ this.active_window?.addToast(toast);
}
return [success, server, port, room];
@@ -769,11 +769,13 @@ class Application extends Adw.Application {
this._removedAccounts.add(account);
account.visible = false;
- const label = vprintf(_('%s removed.'), account.display_name);
- const n = new AppNotifications.UndoNotification(label);
- this?.active_window.queueNotification(n);
-
- n.connect('closed', async () => {
+ const toast = new Adw.Toast({
+ title: vprintf(_('%s removed.'), account.display_name),
+ button_label: _('Undo'),
+ action_name: 'app.undo-remove-connection',
+ action_target: parameter,
+ });
+ toast.connect('dismissed', async () => {
if (!this._removedAccounts.delete(account))
return;
@@ -782,8 +784,7 @@ class Application extends Adw.Application {
Utils.clearAccountPassword(account);
Utils.clearIdentifyPassword(account);
});
- n.connect('undo',
- () => this.activate_action('undo-remove-connection', parameter));
+ this?.active_window.addToast(toast);
}
async _onUndoRemoveConnection(action, parameter) {
diff --git a/src/mainWindow.js b/src/mainWindow.js
index c7582eac..fa3bf59a 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -6,7 +6,6 @@ import Polari from 'gi://Polari';
import Tp from 'gi://TelepathyGLib';
import AccountsMonitor from './accountsMonitor.js';
-import * as AppNotifications from './appNotifications.js';
import JoinDialog from './joinDialog.js';
import RoomList_ from './roomList.js'; // used in template
import RoomManager from './roomManager.js';
@@ -133,10 +132,6 @@ class MainWindow extends Gtk.ApplicationWindow {
this._userListPopover.set_parent(this._showUserListButton);
- this._notificationQueue = new AppNotifications.NotificationQueue();
-
- this._overlay.add_overlay(this._notificationQueue);
-
const app = this.application;
if (app.isTestInstance)
this.add_css_class('test-instance');
@@ -217,10 +212,10 @@ class MainWindow extends Gtk.ApplicationWindow {
}
/**
- * @param {AppNotification} n - a notification
+ * @param {Adw.Toast} toast - a toast (cheers!)
*/
- queueNotification(n) {
- this._notificationQueue.addNotification(n);
+ addToast(toast) {
+ this._overlay.add_toast(toast);
}
_onAccountsReachableChanged() {
diff --git a/src/utils.js b/src/utils.js
index ba691219..4745c3e0 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -20,14 +20,13 @@
*
*/
+import Adw from 'gi://Adw';
import Gdk from 'gi://Gdk';
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import Gtk from 'gi://Gtk';
import Secret from 'gi://Secret';
-import { MessageNotification } from './appNotifications.js';
-
import gi from 'gi';
let Soup;
@@ -316,8 +315,10 @@ export function openURL(url) {
try {
Gtk.show_uri_full_finish(app.active_window, res);
} catch (e) {
- let n = new MessageNotification(_('Failed to open link'));
- app.active_window?.queueNotification(n);
+ const toast = new Adw.Toast({
+ title: _('Failed to open link'),
+ });
+ app.active_window?.addToast(toast);
console.debug(`Failed to open ${url}: %o`, e);
}
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]