window: show toast instead of login dialog when offline with cached articles
This commit is contained in:
parent
d6858b62a7
commit
668c73c8d2
1 changed files with 11 additions and 2 deletions
|
|
@ -496,6 +496,7 @@ pub mod imp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_login(&self, server_url: String, username: String, password: String, store: bool) {
|
fn do_login(&self, server_url: String, username: String, password: String, store: bool) {
|
||||||
|
let is_auto = !store;
|
||||||
let win_weak = self.obj().downgrade();
|
let win_weak = self.obj().downgrade();
|
||||||
crate::runtime::spawn(
|
crate::runtime::spawn(
|
||||||
async move { Api::login(&server_url, &username, &password).await
|
async move { Api::login(&server_url, &username, &password).await
|
||||||
|
|
@ -525,10 +526,18 @@ pub mod imp {
|
||||||
win.imp().fetch_articles();
|
win.imp().fetch_articles();
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
let has_cache = win.imp().article_store.borrow()
|
||||||
|
.as_ref().map(|s| s.n_items() > 0).unwrap_or(false);
|
||||||
|
if is_auto && has_cache {
|
||||||
|
// Offline with cached articles — just show a toast.
|
||||||
|
let toast = libadwaita::Toast::new("Offline — showing cached articles");
|
||||||
|
win.imp().toast_overlay.add_toast(toast);
|
||||||
|
} else {
|
||||||
win.imp().show_login_dialog();
|
win.imp().show_login_dialog();
|
||||||
win.imp().show_error_dialog("Login Failed", &e);
|
win.imp().show_error_dialog("Login Failed", &e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue