[geary: 4/66] Track all windows going out of focus



commit 7684c33830ab5a286e5095164987b5335ff92726
Author: Chris Heywood <15127-creywood users noreply gitlab gnome org>
Date:   Wed Jan 8 11:00:01 2020 +0100

    Track all windows going out of focus

 src/client/application/application-controller.vala | 28 ++++++++++++++++++++++
 .../application/application-main-window.vala       |  9 +++++++
 src/client/composer/composer-window.vala           |  9 +++++++
 3 files changed, 46 insertions(+)
---
diff --git a/src/client/application/application-controller.vala 
b/src/client/application/application-controller.vala
index 87f70a446..17b232952 100644
--- a/src/client/application/application-controller.vala
+++ b/src/client/application/application-controller.vala
@@ -18,6 +18,7 @@ internal class Application.Controller : Geary.BaseObject {
 
     private const uint MAX_AUTH_ATTEMPTS = 3;
 
+    private const uint CLEANUP_WORK_AFTER_IDLE_BACKGROUND_MINUTES = 60 * 24;
 
     /** Determines if conversations can be trashed from the given folder. */
     public static bool does_folder_support_trash(Geary.Folder? target) {
@@ -91,6 +92,9 @@ internal class Application.Controller : Geary.BaseObject {
     // Requested mailto composers not yet fullfulled
     private Gee.List<string?> pending_mailtos = new Gee.ArrayList<string>();
 
+    // Timeout to do work in idle after all windows have been sent to the background
+    private Geary.TimeoutManager all_windows_backgrounded_timeout = null;
+
 
     /**
      * Emitted when an account is added or is enabled.
@@ -1393,6 +1397,30 @@ internal class Application.Controller : Geary.BaseObject {
         }
     }
 
+    // Track a window receiving focus, for idle background work
+    public void window_focus_in() {
+        if (this.all_windows_backgrounded_timeout != null) {
+            this.all_windows_backgrounded_timeout.reset();
+            this.all_windows_backgrounded_timeout = null;
+        }
+    }
+
+    // Track a window going unfocused, for idle background work
+    public void window_focus_out() {
+        this.all_windows_backgrounded_timeout = new 
Geary.TimeoutManager.seconds(CLEANUP_WORK_AFTER_IDLE_BACKGROUND_MINUTES * 60, on_unfocused_idle);
+        this.all_windows_backgrounded_timeout.start();
+    }
+
+    private void on_unfocused_idle() {
+        // Schedule later, catching cases where work should occur later while still in background
+        this.all_windows_backgrounded_timeout = null;
+        window_focus_out();
+
+        debug("Checking for backgrounded idle work");
+        foreach (AccountContext context in this.accounts.values) {
+        }
+    }
+
     /** Displays a composer on the last active main window. */
     internal void show_composer(Composer.Widget composer,
                                 Gee.Collection<Geary.EmailIdentifier>? refers_to,
diff --git a/src/client/application/application-main-window.vala 
b/src/client/application/application-main-window.vala
index d605e027d..b57537d12 100644
--- a/src/client/application/application-main-window.vala
+++ b/src/client/application/application-main-window.vala
@@ -496,6 +496,15 @@ public class Application.MainWindow :
         // Window actions
         add_action_entries(MainWindow.WINDOW_ACTIONS, this);
 
+        this.focus_in_event.connect((w, e) => {
+            application.controller.window_focus_in();
+            return true;
+        });
+        this.focus_out_event.connect((w, e) => {
+            application.controller.window_focus_out();
+            return true;
+        });
+
         setup_layout(application.config);
         on_change_orientation();
 
diff --git a/src/client/composer/composer-window.vala b/src/client/composer/composer-window.vala
index 1608fbd0b..3f4c6f7ac 100644
--- a/src/client/composer/composer-window.vala
+++ b/src/client/composer/composer-window.vala
@@ -48,6 +48,15 @@ public class Composer.Window : Gtk.ApplicationWindow, Container {
             set_titlebar(this.composer.header);
         }
 
+        this.focus_in_event.connect((w, e) => {
+            application.controller.window_focus_in();
+            return true;
+        });
+        this.focus_out_event.connect((w, e) => {
+            application.controller.window_focus_out();
+            return true;
+        });
+
         show();
         set_position(Gtk.WindowPosition.CENTER);
     }


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