[fractal/multi-account: 1/5] Make "prepared" signal handling more robust
- From: Alejandro Domínguez <aledomu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/multi-account: 1/5] Make "prepared" signal handling more robust
- Date: Wed, 14 Jul 2021 17:37:06 +0000 (UTC)
commit ab8e6a91fc79c2c9681da9d3b2e471105f73d941
Author: Alejandro Domínguez <adomu net-c com>
Date: Wed Jul 14 19:32:31 2021 +0200
Make "prepared" signal handling more robust
src/login.rs | 36 +++++++++++++++++++-----------------
src/session/mod.rs | 1 +
src/window.rs | 3 ++-
3 files changed, 22 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/session/mod.rs b/src/session/mod.rs
index 73eb6847..f8b8557f 100644
--- a/src/session/mod.rs
+++ b/src/session/mod.rs
@@ -418,6 +418,7 @@ impl Session {
}
pub fn connect_prepared<F: Fn(&Self) + 'static>(&self, f: F) -> glib::SignalHandlerId {
+ log::debug!("Prepared!");
self.connect_local("prepared", true, move |values| {
let obj = values[0].get::<Self>().unwrap();
diff --git a/src/window.rs b/src/window.rs
index d51a4282..91c85dee 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 login = &imp::Window::from_instance(self).login.get();
for stored_session in sessions {
let session = Session::new();
+ login.set_handler_for_prepared_session(&session);
session.login_with_previous_session(stored_session);
- self.add_session(&session);
}
self.switch_to_sessions_page();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]