[fractal] window: Show network state on the loading page



commit d82c1e21a35a279422913b9ddb8d6d109729df88
Author: Julian Sparber <julian sparber net>
Date:   Mon Aug 15 11:10:15 2022 +0200

    window: Show network state on the loading page

 data/resources/ui/window.ui | 18 ++++++++++++++++++
 src/window.rs               | 30 ++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
---
diff --git a/data/resources/ui/window.ui b/data/resources/ui/window.ui
index b5d8d589d..6c9f2879a 100644
--- a/data/resources/ui/window.ui
+++ b/data/resources/ui/window.ui
@@ -22,6 +22,24 @@
                         </style>
                       </object>
                     </child>
+                    <child>
+                      <object class="GtkInfoBar" id="offline_info_bar">
+                        <property name="message-type">warning</property>
+                        <child>
+                          <object class="AdwClamp">
+                            <property name="maximum-size">440</property>
+                            <property name="tightening-threshold">340</property>
+                            <property name="hexpand">true</property>
+                            <child>
+                              <object class="GtkLabel" id="offline_info_bar_label">
+                                <property name="justify">center</property>
+                                <property name="wrap">True</property>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
                     <child>
                       <object class="GtkSpinner">
                         <property name="spinning">True</property>
diff --git a/src/window.rs b/src/window.rs
index f7cbc36e0..0388aac44 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -34,6 +34,10 @@ mod imp {
         pub sessions: TemplateChild<gtk::Stack>,
         #[template_child]
         pub toast_overlay: TemplateChild<adw::ToastOverlay>,
+        #[template_child]
+        pub offline_info_bar: TemplateChild<gtk::InfoBar>,
+        #[template_child]
+        pub offline_info_bar_label: TemplateChild<gtk::Label>,
         pub account_switcher: AccountSwitcher,
     }
 
@@ -127,6 +131,13 @@ mod imp {
             }));
 
             self.account_switcher.set_pages(Some(self.sessions.pages()));
+
+            let monitor = gio::NetworkMonitor::default();
+            monitor.connect_network_changed(clone!(@weak obj => move |_, _| {
+                obj.update_network_state();
+            }));
+
+            obj.update_network_state();
         }
     }
 
@@ -325,4 +336,23 @@ impl Window {
     pub fn account_switcher(&self) -> &AccountSwitcher {
         &self.imp().account_switcher
     }
+
+    fn update_network_state(&self) {
+        let priv_ = self.imp();
+        let monitor = gio::NetworkMonitor::default();
+
+        if !monitor.is_network_available() {
+            priv_
+                .offline_info_bar_label
+                .set_label(&gettext("No network connection"));
+            priv_.offline_info_bar.set_revealed(true);
+        } else if monitor.connectivity() < gio::NetworkConnectivity::Full {
+            priv_
+                .offline_info_bar_label
+                .set_label(&gettext("No Internet connection"));
+            priv_.offline_info_bar.set_revealed(true);
+        } else {
+            priv_.offline_info_bar.set_revealed(false);
+        }
+    }
 }


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