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



commit e586f8fcf2958e41d3382c74a396bd2e373bf34f
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 |   26 ++++++++++++++++++++++++++
 src/mainWindow.js             |   39 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 64 insertions(+), 1 deletions(-)
---
diff --git a/data/resources/main-window.ui b/data/resources/main-window.ui
index 9a6fbdf..84c8f1d 100644
--- a/data/resources/main-window.ui
+++ b/data/resources/main-window.ui
@@ -9,6 +9,32 @@
       <class name="polari-user-list"/>
     </style>
   </object>
+  <object class="GtkMessageDialog" id="closeConfirmationDialog">
+    <property name="message-type">question</property>
+    <property name="text" translatable="yes">Run Polari in the Background?</property>
+    <property name="secondary-text" translatable="yes">Polari will continue to run when closed and will be 
automatically started on login.</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 0f690f9..32f94de 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',
@@ -191,9 +192,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();
         });
@@ -244,6 +255,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]