[fractal/robust-prepared-handler: 2/2] Set "prepared" signal handling from Login




commit 5012ad99647f73b513bc8d8b18d401d241a312ee
Author: Alejandro Domínguez <adomu net-c com>
Date:   Thu Jul 15 17:01:43 2021 +0200

    Set "prepared" signal handling from Login
    
    The handling of the "prepared" signal for each Session
    was set only for new logins, but not for restored logins.
    Here the setup is done from Login in its own method and
    called where it's needed.

 src/login.rs  | 36 +++++++++++++++++++-----------------
 src/window.rs |  3 ++-
 2 files changed, 21 insertions(+), 18 deletions(-)
---
diff --git a/src/login.rs b/src/login.rs
index 3c04239e..abdc7710 100644
--- a/src/login.rs
+++ b/src/login.rs
@@ -124,23 +124,7 @@ impl Login {
         self.freeze();
 
         let session = Session::new();
-
-        session.connect_prepared(clone!(@weak self as obj, @strong session => move |_| {
-            if let Some(error) = session.get_error() {
-                let error_message = &imp::Login::from_instance(&obj).error_message;
-                // TODO: show more specific error
-                error_message.set_text(&gettext("⚠️ The Login failed."));
-                error_message.show();
-                debug!("Failed to create a new session: {:?}", error);
-
-                obj.unfreeze();
-            } else {
-                debug!("A new session was prepared");
-                obj.emit_by_name("new-session", &[&session]).unwrap();
-                obj.clean();
-            }
-        }));
-
+        self.set_handler_for_prepared_session(&session);
         session.login_with_password(
             build_homeserver_url(homeserver.as_str()).unwrap(),
             username,
@@ -192,6 +176,24 @@ impl Login {
     pub fn default_widget(&self) -> gtk::Widget {
         imp::Login::from_instance(&self).next_button.get().upcast()
     }
+
+    pub fn set_handler_for_prepared_session(&self, session: &Session) {
+        session.connect_prepared(clone!(@weak self as login => move |session| {
+            if let Some(error) = session.get_error() {
+                let error_message = &imp::Login::from_instance(&login).error_message;
+                // TODO: show more specific error
+                error_message.set_text(&gettext("⚠️ The Login failed."));
+                error_message.show();
+                debug!("Failed to create a new session: {:?}", error);
+
+                login.unfreeze();
+            } else {
+                debug!("A new session was prepared");
+                login.emit_by_name("new-session", &[&session]).unwrap();
+                login.clean();
+            }
+        }));
+    }
 }
 
 fn build_homeserver_url(server: &str) -> Result<Url, ParseError> {
diff --git a/src/window.rs b/src/window.rs
index 453a7bb6..dc01a3c3 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -130,10 +130,11 @@ impl Window {
     fn restore_sessions(&self) {
         match secret::restore_sessions() {
             Ok(sessions) => {
+                let priv_ = &imp::Window::from_instance(self);
                 for stored_session in sessions {
                     let session = Session::new();
+                    priv_.login.set_handler_for_prepared_session(&session);
                     session.login_with_previous_session(stored_session);
-                    self.add_session(&session);
                 }
 
                 if sessions.len() > 0 {


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