[fractal/robust-prepared-handler] Set "prepared" signal handling from Login
- From: Alejandro Domínguez <aledomu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/robust-prepared-handler] Set "prepared" signal handling from Login
- Date: Fri, 16 Jul 2021 13:17:29 +0000 (UTC)
commit 4237785eeaf33c7ee8d3887b5b54287094d31d08
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 | 42 +++++++++++++++++++++++++-----------------
src/window.rs | 3 ++-
2 files changed, 27 insertions(+), 18 deletions(-)
---
diff --git a/src/login.rs b/src/login.rs
index 3c04239e..eafaf77f 100644
--- a/src/login.rs
+++ b/src/login.rs
@@ -7,6 +7,7 @@ use gtk::subclass::prelude::*;
use gtk::{self, prelude::*};
use gtk::{glib, glib::clone, CompositeTemplate};
use log::debug;
+use once_cell::OnceCell;
use url::{ParseError, Url};
mod imp {
@@ -124,23 +125,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 +177,29 @@ 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) {
+ let handler_id = OnceCell::new();
+ handler_id.set(session.connect_prepared(
+ clone!(@weak self as login, @strong handler_id => 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();
+ let this_handler = handler_id.into_inner().unwrap();
+ session.disconnect(this_handler);
+ }
+ }),
+ ));
+ }
}
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]