mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-27 16:59:56 +01:00
Cloud: a page drawn after sign-out does not ask the service again
File › Open and Save As call `start` on every frame. After a sign-out, `start` asked who is signed in and listed the root folder again. The sign-out has no answer and no order against those requests, so a provider that still held the session could answer with the departed account and its files, and the account answer also reset Share. `sign_out` now sets a flag that stops `start` from asking anything until the next `sign_in`, and the page header reads "Signed out" instead of "Connecting to your cloud account…" while it is set.
This commit is contained in:
1 parent
dbf13c292c
commit
292e4e4612
3 files changed
+56
-1
No files matched your search
@@ -235,6 +235,43 @@ fn a_late_reply_from_before_sign_out_is_dropped() {
|
||||
);
|
||||
}
|
||||
|
||||
/// File › Open calls `start` on every frame. A sign-out has no answer, so nothing orders it
|
||||
/// before a request the next frame sends. A provider that still holds the session answers that
|
||||
/// request with the departed account, and the window must not show that account or its files.
|
||||
#[test]
|
||||
fn a_page_drawn_after_sign_out_does_not_bring_the_account_back() {
|
||||
let (mut app, held, _log) = two_tabs();
|
||||
start(&mut app);
|
||||
let (_, post) = held.take(|j| matches!(j, Job::Account)).unwrap();
|
||||
post.send(Event::Account(Ok(account("Previous Person"))));
|
||||
held.take(|j| matches!(j, Job::List(_))).unwrap();
|
||||
drain(&mut app, &egui::Context::default());
|
||||
sign_out(&mut app);
|
||||
start(&mut app);
|
||||
// Whatever the frame asked is answered as a provider that has not yet ended the session would.
|
||||
while let Some((job, post)) = held.take(|j| matches!(j, Job::Account | Job::List(_))) {
|
||||
match job {
|
||||
Job::Account => post.send(Event::Account(Ok(account("Previous Person")))),
|
||||
Job::List(path) => post.send(Event::Listed { path, entries: Ok(vec![entry("/Payroll 2026.note", "p1")]) }),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
drain(&mut app, &egui::Context::default());
|
||||
let r = report(&app);
|
||||
assert!(
|
||||
r["account"].is_null() && r["entries"].as_array().is_some_and(Vec::is_empty),
|
||||
"signed out, yet account={} entries={}",
|
||||
r["account"],
|
||||
r["entries"]
|
||||
);
|
||||
sign_in(&mut app);
|
||||
let (_, post) = held.take(|j| matches!(j, Job::SignIn)).unwrap();
|
||||
post.send(Event::Account(Ok(account("Ada"))));
|
||||
drain(&mut app, &egui::Context::default());
|
||||
start(&mut app);
|
||||
assert!(held.take(|j| matches!(j, Job::List(_))).is_some(), "the next sign-in lists the root folder again");
|
||||
}
|
||||
|
||||
/// Save as a copy, then the first click on the Save As page is refused (no name typed yet). The
|
||||
/// second click, with a name, must still copy the conflicted document A, not the active tab B.
|
||||
#[test]
|
||||
|
||||
@@ -190,6 +190,11 @@ pub struct CloudFiles {
|
||||
pub account_fault: Option<Fault>,
|
||||
/// The account is asked for once per run. A frame never asks again.
|
||||
asked_account: bool,
|
||||
/// Set by [`sign_out`] and cleared by [`sign_in`]. While it is set, the
|
||||
/// pages ask the service nothing. [`Job::SignOut`] has no answer and no
|
||||
/// order against a later job, so a provider that still holds the session
|
||||
/// could answer an account or listing request with the departed account.
|
||||
signed_out: bool,
|
||||
/// The folder being browsed. Shared by the Open and Save As pages, which
|
||||
/// are never on screen together.
|
||||
pub mine: Folder,
|
||||
@@ -243,6 +248,7 @@ impl CloudFiles {
|
||||
account: None,
|
||||
account_fault: None,
|
||||
asked_account: false,
|
||||
signed_out: false,
|
||||
mine: Folder::default(),
|
||||
shared: Folder::default(),
|
||||
source: Source::default(),
|
||||
@@ -337,8 +343,10 @@ pub fn submit<A: CloudApp>(app: &A, job: Job) {
|
||||
}
|
||||
|
||||
/// Asks who is signed in, once per run, and lists the root folder.
|
||||
///
|
||||
/// After [`sign_out`] it asks nothing until the next [`sign_in`].
|
||||
pub fn start<A: CloudApp>(app: &mut A) {
|
||||
if !available(app) {
|
||||
if !available(app) || app.cloud().signed_out {
|
||||
return;
|
||||
}
|
||||
if !app.cloud().asked_account {
|
||||
@@ -368,6 +376,7 @@ pub fn sign_in<A: CloudApp>(app: &mut A) {
|
||||
// would then be swallowed by the guard that stops a frame asking twice. A
|
||||
// button that does nothing the second time reads as a broken button.
|
||||
cloud.asked_account = true;
|
||||
cloud.signed_out = false;
|
||||
cloud.link = None;
|
||||
cloud.status = Some(working);
|
||||
// A new session. A job the previous one left outstanding may never
|
||||
@@ -389,6 +398,10 @@ pub fn sign_out<A: CloudApp>(app: &mut A) {
|
||||
cloud.account = None;
|
||||
cloud.account_fault = None;
|
||||
cloud.asked_account = false;
|
||||
// File › Open and Save As call `start` on every frame. Without this, the
|
||||
// next frame would ask who is signed in and list the root folder while
|
||||
// the sign-out may still be on its way.
|
||||
cloud.signed_out = true;
|
||||
cloud.link = None;
|
||||
cloud.mine = Folder::default();
|
||||
cloud.shared = Folder::default();
|
||||
|
||||
@@ -42,6 +42,11 @@ fn header<A: CloudApp>(app: &mut A, ui: &mut Ui) {
|
||||
let line = if account.display.is_empty() { app.tr("Signed in") } else { account.display.clone() };
|
||||
dim(ui, &style, &line);
|
||||
}
|
||||
// Nothing is asked after a sign-out, so there is nothing to wait for.
|
||||
(None, None) if app.cloud().signed_out => {
|
||||
let signed_out = app.tr("Signed out");
|
||||
dim(ui, &style, &signed_out);
|
||||
}
|
||||
(None, None) => {
|
||||
let waiting = app.tr("Connecting to your cloud account…");
|
||||
dim(ui, &style, &waiting);
|
||||
|
||||
Reference in new issue
Block a user