[polari] mainWindow: Show a clear indication when offline



commit e93c92926bcc204541d02671dbd7fbde5f5e2e9e
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Apr 19 11:09:11 2019 +0200

    mainWindow: Show a clear indication when offline
    
    Polari is almost entirely useless without an internet connection, yet
    our current indication that connectivity has been lost is so subtle
    that it is easily missed.
    
    To address this, try harder to get the user's attention by popping up
    an info bar that outlines the problem.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=760833

 data/resources/main-window.ui | 36 +++++++++++++++++++++++++++++++++++-
 src/mainWindow.js             | 17 +++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletion(-)
---
diff --git a/data/resources/main-window.ui b/data/resources/main-window.ui
index d534947..bf89864 100644
--- a/data/resources/main-window.ui
+++ b/data/resources/main-window.ui
@@ -208,8 +208,38 @@
       </object>
     </child>
     <child>
-      <object class="GtkBox">
+      <object class="GtkGrid">
         <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkInfoBar" id="offlineInfoBar">
+            <property name="visible">True</property>
+            <property name="revealed">False</property>
+            <child internal-child="content_area">
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Offline</property>
+                    <attributes>
+                      <attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
+                    </attributes>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Go online to chat and receive 
messages.</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="width">2</property>
+          </packing>
+        </child>
         <child>
           <object class="GtkRevealer" id="roomListRevealer">
             <property name="visible">True</property>
@@ -257,6 +287,10 @@
               </object>
             </child>
           </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">1</property>
+          </packing>
         </child>
       </object>
     </child>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 1419306..962a70d 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -84,6 +84,7 @@ var MainWindow = GObject.registerClass({
         'showUserListButton',
         'userListPopover',
         'roomListRevealer',
+        'offlineInfoBar',
         'overlay',
         'roomStack',
     ],
@@ -139,6 +140,12 @@ var MainWindow = GObject.registerClass({
         if (GLib.get_application_name().toLowerCase().includes('snapshot'))
             this.get_style_context().add_class('snapshot');
 
+        this._networkMonitor = Gio.NetworkMonitor.get_default();
+        this._networkChangedId = this._networkMonitor.connect(
+            'network-changed',
+            this._onNetworkChanged.bind(this));
+        this._onNetworkChanged();
+
         this._roomStack.connect('size-allocate', () => {
             this.notify('view-height');
         });
@@ -221,6 +228,12 @@ var MainWindow = GObject.registerClass({
         return this._roomStack.get_allocated_height() - this._roomStack.entry_area_height;
     }
 
+    _onNetworkChanged() {
+        let { networkAvailable } = this._networkMonitor;
+        this._offlineInfoBar.revealed =
+            this._networkMonitor.state_valid && !networkAvailable;
+    }
+
     _onWindowStateEvent(widget, event) {
         let state = event.get_window().get_state();
 
@@ -256,6 +269,10 @@ var MainWindow = GObject.registerClass({
         this._roomManager.disconnect(this._roomsLoadedId);
         this._roomManager.disconnect(this._roomRemovedId);
 
+        if (this._networkChangedId)
+            this._networkMonitor.disconnect(this._networkChangedId);
+        this._networkChangedId = 0;
+
         this._overlay.remove(this.application.notificationQueue);
         this._overlay.remove(this.application.commandOutputQueue);
     }


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