[geary/mjog/misc-fixes: 23/27] Fix notifications not being shown



commit 516db957e1546ddacecdf3dbbca3ee20f9506ed8
Author: Michael Gratton <mike vee net>
Date:   Sat Jan 25 14:42:04 2020 +1100

    Fix notifications not being shown

 src/client/accounts/accounts-editor-list-pane.vala | 15 ++++++-----
 .../application/application-main-window.vala       | 14 ++++++----
 .../components/components-in-app-notification.vala | 30 ++++++++++++----------
 3 files changed, 34 insertions(+), 25 deletions(-)
---
diff --git a/src/client/accounts/accounts-editor-list-pane.vala 
b/src/client/accounts/accounts-editor-list-pane.vala
index fc16da49..a0a65b52 100644
--- a/src/client/accounts/accounts-editor-list-pane.vala
+++ b/src/client/accounts/accounts-editor-list-pane.vala
@@ -243,12 +243,15 @@ internal class Accounts.EditorListPane : Gtk.Grid, EditorPane, CommandPane {
 
     private void on_execute(Application.Command command) {
         if (command.executed_label != null) {
-            int notification_time =
-                command.executed_notification_brief ?
-                    editor.application.config.brief_notification_duration : 0;
-            Components.InAppNotification ian =
-                new Components.InAppNotification(
-                    command.executed_label, notification_time);
+            uint notification_time =
+                Components.InAppNotification.DEFAULT_DURATION;
+            if (command.executed_notification_brief) {
+                notification_time =
+                    this.editor.application.config.brief_notification_duration;
+            }
+            Components.InAppNotification ian = new Components.InAppNotification(
+                command.executed_label, notification_time
+            );
             ian.set_button(_("Undo"), Action.Edit.prefix(Action.Edit.UNDO));
             this.editor.add_notification(ian);
         }
diff --git a/src/client/application/application-main-window.vala 
b/src/client/application/application-main-window.vala
index 285d5224..e88d23fc 100644
--- a/src/client/application/application-main-window.vala
+++ b/src/client/application/application-main-window.vala
@@ -2041,11 +2041,15 @@ public class Application.MainWindow :
     private void on_command_redo(Command command) {
         update_command_actions();
         if (command.executed_label != null) {
-            int notification_time =
-                command.executed_notification_brief ?
-                    application.config.brief_notification_duration : 0;
-            Components.InAppNotification ian =
-                new Components.InAppNotification(command.executed_label, notification_time);
+            uint notification_time =
+                Components.InAppNotification.DEFAULT_DURATION;
+            if (command.executed_notification_brief) {
+                notification_time =
+                    application.config.brief_notification_duration;
+            }
+            Components.InAppNotification ian = new Components.InAppNotification(
+                command.executed_label, notification_time
+            );
             ian.set_button(_("Undo"), Action.Edit.prefix(Action.Edit.UNDO));
             add_notification(ian);
         }
diff --git a/src/client/components/components-in-app-notification.vala 
b/src/client/components/components-in-app-notification.vala
index fd5a7797..090fd88c 100644
--- a/src/client/components/components-in-app-notification.vala
+++ b/src/client/components/components-in-app-notification.vala
@@ -12,32 +12,29 @@
 [GtkTemplate (ui = "/org/gnome/Geary/components-in-app-notification.ui")]
 public class Components.InAppNotification : Gtk.Revealer {
 
-    /** Length of the default timeout to close the notification. */
-    public const uint DEFAULT_KEEPALIVE = 5;
+    /** Default length of time to show the notification. */
+    public const uint DEFAULT_DURATION = 5;
 
     [GtkChild]
     private Gtk.Label message_label;
+
     [GtkChild]
     private Gtk.Button action_button;
 
+    private uint duration;
+
     /**
      * Creates an in-app notification.
      *
      * @param message The message that should be displayed.
-     * @param keepalive The amount of seconds that the notification should stay visible.
+     * @param duration The length of time to show the notification,
+     * in seconds.
      */
-    public InAppNotification(string message, uint keepalive = -1) {
-        if (keepalive == 0) {
-            this.message_label.label = "";
-            return;   // skip the notification
-        }
-        if (keepalive == -1)
-            keepalive = DEFAULT_KEEPALIVE;
+    public InAppNotification(string message,
+                             uint duration = DEFAULT_DURATION) {
         this.transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN;
         this.message_label.label = message;
-
-        // Close after the given amount of time.
-        Timeout.add_seconds(keepalive, () => { close(); return false; });
+        this.duration = duration;
     }
 
     /**
@@ -50,9 +47,14 @@ public class Components.InAppNotification : Gtk.Revealer {
     }
 
     public override void show() {
-        if (this.message_label.label != "") {
+        if (this.duration > 0) {
             base.show();
             this.reveal_child = true;
+
+            // Close after the given amount of time
+            GLib.Timeout.add_seconds(
+                this.duration, () => { close(); return false; }
+            );
         }
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]