Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Launch: a session that can't be taken up says why (a locked account), not always that Apple signed you out

Yashwanth Kamireddi8d336ea0a430
diff --git a/.uiverify/lapse-reason.mjs b/.uiverify/lapse-reason.mjs
new file mode 100644
index 0000000..aeba41e
--- /dev/null
+++ b/.uiverify/lapse-reason.mjs
@@ -0,0 +1,45 @@
+// The library is ready and the saved session can't be taken up. When Apple simply declines it,
+// the notice says "Apple signed you out." When the resume failed with a reason (a locked
+// account, say), the notice says that reason instead, and the copy on the computer stays.
+import { engine } from "./engine.mjs";
+import { SERVICES, installStub } from "./stub.mjs";
+const BASE = process.env.BASE ?? process.env.URL ?? "http://localhost:4173";
+const LOCKED =
+ "Apple has locked this Apple Account for security. Unlock it at iforgot.apple.com, then sign in here again.";
+const b = await engine.launch();
+let failures = 0;
+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };
+
+async function notice(resumeFails) {
+ const ctx = await b.newContext({ viewport: { width: 1200, height: 800 } });
+ await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null });
+ await ctx.addInitScript(({ resumeFails, LOCKED }) => {
+ const inner = window.__TAURI_INTERNALS__.invoke;
+ window.__TAURI_INTERNALS__.invoke = async (cmd, args) => {
+ if (cmd === "auth_status") return { hasStoredSession: true, signedIn: false, libraryReady: true, notKept: false };
+ if (cmd === "auth_resume") {
+ if (resumeFails) throw LOCKED;
+ return "signin";
+ }
+ return inner(cmd, args);
+ };
+ }, { resumeFails, LOCKED });
+ const page = await ctx.newPage();
+ await page.goto(BASE, { waitUntil: "networkidle" });
+ await page.waitForFunction(() => /still here/.test(document.body.innerText), null, { timeout: 8000 }).catch(() => {});
+ const text = await page.evaluate(() => document.body.innerText);
+ await ctx.close();
+ return text;
+}
+
+const declined = await notice(false);
+ok(/Apple signed you out\. Your copy on this computer is still here\./.test(declined), "a declined session says Apple signed you out");
+const locked = await notice(true);
+ok(locked.includes("Apple has locked this Apple Account for security."), "a locked account says it is locked");
+ok(locked.includes("iforgot.apple.com"), "and where to unlock it");
+ok(!locked.includes("Apple signed you out"), "and not that Apple signed you out");
+ok(locked.includes("Your copy on this computer is still here."), "the copy on this computer is still said to be there");
+
+await b.close();
+if (failures) { console.log(`${failures} failed`); process.exit(1); }
+console.log("all passed");
diff --git a/check.sh b/check.sh
index 6b83d3a..b998773 100755
--- a/check.sh
+++ b/check.sh
@@ -163,6 +163,8 @@ step "webkit: failing" env ENGINE=webkit node .uiverify/boundary.mjs
step "webkit: back" env ENGINE=webkit node .uiverify/resume.mjs
step "webkit: occasions" env ENGINE=webkit node .uiverify/occasions.mjs
step "webkit: drive nav" env ENGINE=webkit node .uiverify/drive-nav.mjs
+step "sign-in keyring" node .uiverify/signin-keyring.mjs
+step "lapse reason" node .uiverify/lapse-reason.mjs
printf '\n'
if [ "$fail" -eq 0 ]; then printf '\033[32mAll checks passed.\033[0m\n'; else printf '\033[31mSome checks failed.\033[0m\n'; fi
diff --git a/src/App.tsx b/src/App.tsx
index cacddd3..6a9bdbe 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useState } from "react";
-import { SignIn } from "./screens/SignIn";
+import { SignIn, sentence } from "./screens/SignIn";
import { CodeEntry } from "./screens/CodeEntry";
import { Library } from "./screens/Library";
import { ImportSheet } from "./components/ImportSheet";
@@ -58,7 +58,12 @@ export default function App() {
// line over it, as a lapse does.
const resumed = api.resume();
setPhase("library");
- const next = await resumed.catch(() => "signin" as const);
+ // A resume that failed says why (a locked account, say); only Apple declining the
+ // session is "signed you out".
+ const next = await resumed.catch((err) => {
+ if (!cancelled) setWhy(messageOf(err));
+ return "signin" as const;
+ });
if (cancelled) return;
if (next === "code") setPhase("code");
else if (next === "signin") setLapsed(true);
@@ -107,13 +112,13 @@ export default function App() {
useEffect(() => {
if (!lapsed || phase !== "library") return undefined;
const id = toast({
- message: "Apple signed you out. Your copy on this computer is still here.",
+ message: `${why ? sentence(why) : "Apple signed you out."} Your copy on this computer is still here.`,
tone: "error",
duration: null,
action: { label: "Sign In", run: () => setPhase("signin") },
});
return () => dismissToast(id);
- }, [lapsed, phase]);
+ }, [lapsed, phase, why]);
// Signed out, the window starts over: nothing of the account is left in its memory either —
// no picture, no list, no cached answer — for whoever signs in next.