window: show toast instead of login dialog when offline with cached articles

This commit is contained in:
Jeena 2026-03-21 03:05:19 +00:00
parent d6858b62a7
commit 668c73c8d2

View file

@ -496,6 +496,7 @@ pub mod imp {
}
fn do_login(&self, server_url: String, username: String, password: String, store: bool) {
let is_auto = !store;
let win_weak = self.obj().downgrade();
crate::runtime::spawn(
async move { Api::login(&server_url, &username, &password).await
@ -525,8 +526,16 @@ pub mod imp {
win.imp().fetch_articles();
}
Err(e) => {
win.imp().show_login_dialog();
win.imp().show_error_dialog("Login Failed", &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_error_dialog("Login Failed", &e);
}
}
}
},