[polari/wip/fmuellner/bg-app: 6/6] mainWindow: Offer to keep running in background on close



commit 3952cf75ba783efa717f29f19077b4f639da9f0f
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Sep 1 19:39:12 2016 +0200

    mainWindow: Offer to keep running in background on close
    
    The background mode added by the previous commit is unintrusive, but
    also hard to discover. To address this, add a one-time dialog that
    presents the available choice to the user when the main window is
    closed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=770750

 data/resources/main-window.ui |   28 ++++++++++++++++++++++++++++
 src/mainWindow.js             |   39 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 66 insertions(+), 1 deletions(-)
---
diff --git a/data/resources/main-window.ui b/data/resources/main-window.ui
index 9a6fbdf..e29cc8b 100644
--- a/data/resources/main-window.ui
+++ b/data/resources/main-window.ui
@@ -9,6 +9,34 @@
       <class name="polari-user-list"/>
     </style>
   </object>
+  <object class="GtkMessageDialog" id="closeConfirmationDialog">
+    <property name="message-type">question</property>
+    <property name="text" translatable="yes">Keep running in background?</property>
+    <property name="secondary-text" translatable="yes">
+      When running in the background, Polari will stay connected and keep sending notifications, both now 
and the next time you log in. You can change this preference from the application menu.
+    </property>
+    <property name="destroy-with-parent">true</property>
+    <property name="modal">true</property>
+    <signal name="delete-event" handler="gtk_widget_hide_on_delete"/>
+    <child type="action">
+      <object class="GtkButton" id="quitButton">
+        <property name="label" translatable="yes">_Quit</property>
+        <property name="visible">true</property>
+        <property name="use-underline">true</property>
+      </object>
+    </child>
+    <child type="action">
+      <object class="GtkButton" id="backgroundButton">
+        <property name="label" translatable="yes">_Run in background</property>
+        <property name="visible">true</property>
+        <property name="use-underline">true</property>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="close">quitButton</action-widget>
+      <action-widget response="accept">backgroundButton</action-widget>
+    </action-widgets>
+  </object>
   <template class="Gjs_MainWindow">
     <property name="title" translatable="yes">Polari</property>
     <property name="icon-name">org.gnome.Polari</property>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index cc420af..be57e06 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -99,7 +99,8 @@ const MainWindow = new Lang.Class({
                        'userListPopover',
                        'roomListRevealer',
                        'overlay',
-                       'roomStack'],
+                       'roomStack',
+                       'closeConfirmationDialog'],
     Properties: {
         subtitle: GObject.ParamSpec.string('subtitle',
                                            'subtitle',
@@ -193,9 +194,19 @@ const MainWindow = new Lang.Class({
                                   Lang.bind(this, this._updateDecorations));
         this._updateDecorations();
 
+        this._closeConfirmationDialog.transient_for = this;
+        this._closeConfirmationDialog.connect('response', (w, r) => {
+            if (r == Gtk.ResponseType.DELETE_EVENT)
+                return;
+
+            this._settings.set_boolean('run-in-background', r == Gtk.ResponseType.ACCEPT);
+            this.destroy();
+        });
+
         this.connect('window-state-event', Lang.bind(this, this._onWindowStateEvent));
         this.connect('size-allocate', Lang.bind(this, this._onSizeAllocate));
         this.connect('destroy', Lang.bind(this, this._onDestroy));
+        this.connect('delete-event', Lang.bind(this, this._onDeleteEvent));
         this.connect('notify::active-room', () => {
             this._updateUserListLabel();
         });
@@ -246,6 +257,32 @@ const MainWindow = new Lang.Class({
             this._settings.reset('last-selected-channel');
     },
 
+    _touchFile: function(file) {
+        try {
+            file.get_parent().make_directory_with_parents(null);
+        } catch(e if e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.EXISTS)) {
+            // not an error, carry on
+        }
+
+        let stream = file.create(0, null);
+        stream.close(null);
+    },
+
+    _onDeleteEvent: function() {
+        let f = Gio.File.new_for_path(GLib.get_user_cache_dir() +
+                                      '/polari/close-confirmation-shown');
+        try {
+            this._touchFile(f);
+        } catch(e) {
+            if (e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.EXISTS))
+                return false; // the dialog has been shown
+            log('Failed to mark confirmation dialog as shown: ' + e.message);
+        }
+
+        this._closeConfirmationDialog.show();
+        return true;
+    },
+
     _onAccountsChanged: function(am) {
         let hasAccounts = this._accountsMonitor.enabledAccounts.length > 0;
         this._roomListRevealer.reveal_child = hasAccounts;


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