[geary/mjog/misc-fixes: 1/6] Fix race when Application.Contoller's constructor opens a window



commit 7f034107b0a53fa60e4c0a5ea377f0dc33e38a66
Author: Michael Gratton <mike vee net>
Date:   Tue Nov 19 10:24:23 2019 +1100

    Fix race when Application.Contoller's constructor opens a window
    
    Don't try to open windows from the constructor since MainWindow needs
    access to the controller via the applictaion, but the application can't
    set the controller instance until is is constructed.

 src/client/application/application-client.vala     | 30 +++++++++++++++++++-
 src/client/application/application-controller.vala | 33 ----------------------
 2 files changed, 29 insertions(+), 34 deletions(-)
---
diff --git a/src/client/application/application-client.vala b/src/client/application/application-client.vala
index aa853fba..4241eed4 100644
--- a/src/client/application/application-client.vala
+++ b/src/client/application/application-client.vala
@@ -808,7 +808,23 @@ public class Application.Client : Gtk.Application {
         this.controller.register_window(window);
         window.focus_in_event.connect(on_main_window_focus_in);
         if (select_first_inbox) {
-            window.select_first_inbox(true);
+            if (!window.select_first_inbox(true)) {
+                // The first inbox wasn't selected, so the account is
+                // likely still loading folders after being
+                // opened. Add a listener to try again later.
+                try {
+                    Geary.Account first = Geary.Collection.get_first(
+                        this.engine.get_accounts()
+                    );
+                    if (first != null) {
+                        first.folders_available_unavailable.connect_after(
+                            on_folders_first_available
+                        );
+                    }
+                } catch (GLib.Error error) {
+                    debug("Error getting Inbox for first account");
+                }
+            }
         }
         return window;
     }
@@ -1093,6 +1109,18 @@ public class Application.Client : Gtk.Application {
         }
     }
 
+    private void on_folders_first_available(Geary.Account account,
+        Gee.BidirSortedSet<Geary.Folder>? available,
+        Gee.BidirSortedSet<Geary.Folder>? unavailable
+    ) {
+        if (get_active_main_window().select_first_inbox(true)) {
+            // The handler has done its job, so disconnect it
+            account.folders_available_unavailable.disconnect(
+                on_folders_first_available
+            );
+        }
+    }
+
     private bool on_main_window_focus_in(Gtk.Widget widget,
                                          Gdk.EventFocus event) {
         MainWindow? main = widget as MainWindow;
diff --git a/src/client/application/application-controller.vala 
b/src/client/application/application-controller.vala
index 909cade5..ec46ed5d 100644
--- a/src/client/application/application-controller.vala
+++ b/src/client/application/application-controller.vala
@@ -227,27 +227,6 @@ internal class Application.Controller : Geary.BaseObject {
             warning("Error loading accounts: %s", e.message);
         }
 
-        // Since the accounts may still be loading folders, when the
-        // main window first opens no folder might be available to be
-        // selected. Add look for the inbox and if not found, add a
-        // listener here as a once off for when it is loaded.
-        if (!application.get_active_main_window().select_first_inbox(true)) {
-            // Connect after so the folder is added to any
-            // open main windows first.
-            try {
-                Geary.Account first = Geary.Collection.get_first(
-                    application.engine.get_accounts()
-                );
-                if (first != null) {
-                    first.folders_available_unavailable.connect_after(
-                        on_folders_first_available
-                    );
-                }
-            } catch (GLib.Error error) {
-                debug("Error getting Inbox for first account");
-            }
-        }
-
         // Expunge any deleted accounts in the background, so we're
         // not blocking the app continuing to open.
         this.expunge_accounts.begin();
@@ -1387,18 +1366,6 @@ internal class Application.Controller : Geary.BaseObject {
         }
     }
 
-    private void on_folders_first_available(Geary.Account account,
-        Gee.BidirSortedSet<Geary.Folder>? available,
-        Gee.BidirSortedSet<Geary.Folder>? unavailable
-    ) {
-        if (application.get_active_main_window().select_first_inbox(true)) {
-            // The handler has done its job, so disconnect it
-            account.folders_available_unavailable.disconnect(
-                on_folders_first_available
-            );
-        }
-    }
-
     private bool should_notify_new_messages(Geary.Folder folder) {
         // A monitored folder must be selected to squelch notifications;
         // if conversation list is at top of display, don't display


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