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.

Drive: no alarm when Apple is busy while a folder kept here is showing

Yashwanth Kamireddic5e28b9761e9
diff --git a/.uiverify/drive-busy-quiet.mjs b/.uiverify/drive-busy-quiet.mjs
new file mode 100644
index 0000000..41e25cc
--- /dev/null
+++ b/.uiverify/drive-busy-quiet.mjs
@@ -0,0 +1,24 @@
+// Apple's Drive busy while a folder kept here is already on screen (as when Skykeep opens and
+// every app syncs at once): the folder shows, nothing is said, and it is asked again quietly.
+// A folder with nothing kept that can't be read still says so.
+import { engine } from "./engine.mjs";
+import { SERVICES, installStub } from "./stub.mjs";
+const b = await engine.launch();
+let failures = 0;
+const ok = (pass, what) => { console.log(`${pass ? "PASS" : "FAIL"} ${what}`); if (!pass) failures++; };
+const ctx = await b.newContext({ viewport: { width: 1280, height: 800 } });
+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null, driveFixture: true });
+await ctx.addInitScript(() => { window.__driveBusy = 1; });
+const page = await ctx.newPage();
+page.on("pageerror", (e) => { console.log(`FAIL page error: ${e.message}`); process.exitCode = 1; });
+await page.goto(process.env.URL ?? "http://localhost:4173", { waitUntil: "networkidle" });
+await page.locator(".nav-item", { hasText: "Drive" }).click();
+await page.waitForTimeout(800);
+ok((await page.evaluate(() => (window.__busyAsks ?? []).length)) === 1, "Apple was busy for the first ask");
+ok((await page.locator(".drive-row-hit").count()) > 0, "the folder kept here shows");
+ok((await page.locator(".toast.is-error").count()) === 0, "and nothing is said about Apple being busy");
+await page.waitForTimeout(5600);
+ok((await page.evaluate(() => window.__driveBusy)) === 0 && (await page.locator(".toast.is-error").count()) === 0, "asked again quietly, still nothing said");
+await b.close();
+console.log(failures ? `${failures} FAILED` : "all passed");
+process.exit(failures ? 1 : 0);
diff --git a/.uiverify/stub.mjs b/.uiverify/stub.mjs
index 8ead838..cd75346 100644
--- a/.uiverify/stub.mjs
+++ b/.uiverify/stub.mjs
@@ -1139,6 +1139,8 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note
case "drive_sync_folder":
// A folder deleted on another device: the backend forgets it and says so.
if (args.folderId === window.__driveGone) throw "This folder was deleted or moved on another device.";
+ // Apple busy for the next `__driveBusy` asks (a test's): refused as the backend says it.
+ if ((window.__driveBusy ?? 0) > 0) { window.__driveBusy--; (window.__busyAsks ??= []).push(args.folderId); throw "iCloud Drive is busy right now \u2014 try this one again in a minute."; }
return driveItems.length;
case "drive_download": (window.__singleDownloads ??= []).push(args.drivewsid); return "/home/user/Downloads/file.pdf";
// A folder, or a selection, into Downloads (folder_download.rs): kept going until the
diff --git a/src/screens/DriveView.tsx b/src/screens/DriveView.tsx
index 34b70b0..315fff3 100644
--- a/src/screens/DriveView.tsx
+++ b/src/screens/DriveView.tsx
@@ -104,6 +104,11 @@ const modified = (seconds: number | null, now = new Date()) => {
return dateText(d, { day: "numeric", month: "short", year: "numeric" });
};
+/** Apple busy, or the network away for a moment: a failure that passes on its own. */
+function passing(message: string): boolean {
+ return /busy|try (this one )?again in a minute|offline|can.t reach|network|timed out/i.test(message);
+}
+
/**
* Recently Deleted, as icloud.com shows it: what was deleted, when, and two ways out —
* Recover, back to where it was, and Delete Now, for good. Each leaves the list the moment it
@@ -682,7 +687,26 @@ export function DriveView() {
setItems(Array.isArray(cached) ? cached : []);
setThumbs({});
thumbsOf.current = null;
- await api.driveSyncFolder(folderId);
+ try {
+ await api.driveSyncFolder(folderId);
+ } catch (e) {
+ // Apple busy or out of reach while the folder kept here is already on screen: nothing
+ // the person asked for failed, so nothing is said. Asked again a little later, quietly;
+ // the next sync brings it anyway. Anything else (the folder gone) is said as before.
+ if (!(Array.isArray(cached) && cached.length > 0 && passing(messageOf(e)))) throw e;
+ const again = (wait: number, left: number) =>
+ window.setTimeout(async () => {
+ if (token !== openToken.current) return;
+ try {
+ await api.driveSyncFolder(folderId);
+ const fresh = await api.driveChildren(folderId);
+ if (token === openToken.current) setItems(Array.isArray(fresh) ? fresh : []);
+ } catch (e2) {
+ if (left > 0 && passing(messageOf(e2))) again(wait * 3, left - 1);
+ }
+ }, wait);
+ again(5_000, 2);
+ }
if (token !== openToken.current) return;
const fresh = await api.driveChildren(folderId);
if (token !== openToken.current) return;