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 jumping into folders nobody opened; new folders and uploads show at once

Yashwanth Kamireddi60237992bf9b
diff --git a/.uiverify/drive-nav.mjs b/.uiverify/drive-nav.mjs
new file mode 100644
index 0000000..ef29a30
--- /dev/null
+++ b/.uiverify/drive-nav.mjs
@@ -0,0 +1,58 @@
+// Opening a folder shows that folder — never the last one's rows while it loads.
+//
+// A folder not seen before kept the previous level's rows on screen through a slow fetch, so
+// a click there opened a folder from the level just left: Drive "went to random folders".
+import { engine } from "./engine.mjs";
+import { SERVICES, installStub } from "./stub.mjs";
+
+const b = await engine.launch();
+const ctx = await b.newContext({ viewport: { width: 1280, height: 800 } });
+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null,
+ calendarFixture: false, notesFixture: false, contactsFixture: false, driveFixture: true, remindersFixture: false });
+// Downloads has not been visited, and Apple takes its time answering for it.
+await ctx.addInitScript(() => {
+ const internals = window.__TAURI_INTERNALS__;
+ const invoke = internals.invoke;
+ internals.invoke = async (cmd, args) => {
+ if (cmd === "drive_create_folder") { await new Promise((r) => setTimeout(r, 1200)); return null; }
+ if (args?.folderId === "FOLDER::a") {
+ if (cmd === "drive_children") return window.__downloadsArrived ? [
+ { drivewsid: "FILE::x", parentId: "FOLDER::a", name: "Ticket", extension: "pdf", kind: "FILE",
+ size: 1000, childCount: null, createdAt: 1, modifiedAt: 1, etag: null }] : [];
+ if (cmd === "drive_sync_folder") {
+ await new Promise((r) => setTimeout(r, 1500));
+ window.__downloadsArrived = true;
+ return 1;
+ }
+ }
+ return invoke(cmd, args);
+ };
+});
+const page = await ctx.newPage();
+await page.goto("http://localhost:4173", { waitUntil: "networkidle" });
+await page.locator(".nav-item", { hasText: "iCloud Drive" }).click();
+await page.waitForTimeout(400);
+
+let failures = 0;
+const ok = (pass, yes, no) => { console.log(pass ? `PASS ${yes}` : `FAIL ${no}`); if (!pass) failures++; };
+
+await page.locator(".drive-row-hit", { hasText: "Downloads" }).click();
+await page.waitForTimeout(300);
+const during = await page.locator(".drive-name").allInnerTexts();
+ok(!during.includes("Keynote") && !during.includes("Semester Plan.pdf"),
+ "while a folder loads, the last folder's rows are not shown", `shown while loading: ${JSON.stringify(during)}`);
+await page.waitForTimeout(1700);
+const after = await page.locator(".drive-name").allInnerTexts();
+ok(after.length === 1 && after[0].startsWith("Ticket"), "and then its own rows arrive", `then: ${JSON.stringify(after)}`);
+// A new folder shows at once, marked as being made, while Apple takes its time.
+await page.locator(".crumb").first().click();
+await page.waitForTimeout(400);
+await page.getByRole("button", { name: "New Folder" }).click();
+await page.keyboard.type("Trips");
+await page.keyboard.press("Enter");
+await page.waitForTimeout(200);
+const making = await page.locator(".drive-row.is-busy").allInnerTexts();
+ok(making.some((t) => t.includes("Trips") && t.includes("Creating")), "a new folder shows at once, being made",
+ `straight after Return: ${JSON.stringify(making)}`);
+await b.close();
+process.exitCode = failures === 0 ? 0 : 1;
diff --git a/check.sh b/check.sh
index 1a6367e..c42e82f 100755
--- a/check.sh
+++ b/check.sh
@@ -45,6 +45,7 @@ step "narrow windows" node .uiverify/compact.mjs
step "a screen failing" node .uiverify/boundary.mjs
step "coming back" node .uiverify/resume.mjs
step "birthdays, holidays" node .uiverify/occasions.mjs
+step "drive folders" node .uiverify/drive-nav.mjs
# The same screens in WebKit, the engine Quince draws in. Chromium above catches most things;
# this catches what only WebKit does — pointer capture, blur on removal, its own layout.
@@ -60,6 +61,7 @@ step "webkit: narrow" env ENGINE=webkit node .uiverify/compact.mjs
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
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/screens/DriveView.tsx b/src/screens/DriveView.tsx
index ee102a7..6c6223a 100644
--- a/src/screens/DriveView.tsx
+++ b/src/screens/DriveView.tsx
@@ -77,7 +77,10 @@ export function DriveView() {
// Show what is stored first, then fetch — a folder visited before opens instantly.
const cached = await api.driveChildren(folderId);
if (token !== openToken.current) return;
- if (Array.isArray(cached) && cached.length > 0) setItems(cached);
+ // Always this folder's own rows, even none: keeping the last folder's rows on screen
+ // while a slow fetch ran meant a click landed on a row from the level just left, and
+ // Drive seemed to jump into folders nobody opened.
+ setItems(Array.isArray(cached) ? cached : []);
await api.driveSyncFolder(folderId);
if (token !== openToken.current) return;
const fresh = await api.driveChildren(folderId);
@@ -201,6 +204,13 @@ export function DriveView() {
/** Every file sent from this window, until the tray is closed. */
const [uploads, setUploads] = useState<Map<string, UploadEvent>>(new Map());
const [uploadMenu, setUploadMenu] = useState(false);
+ /**
+ * What has been asked for here and is not back from Apple yet, drawn at once as rows of
+ * its own: a folder being created, files going up. Nothing showed until Apple answered —
+ * seconds later — so a press seemed to do nothing, and then a folder appeared from nowhere.
+ */
+ const [pending, setPending] = useState<{ key: string; folder: string; name: string; doing: string }[]>([]);
+ const settle = (key: string) => setPending((p) => p.filter((x) => !x.key.startsWith(key)));
useEffect(() => {
let stop: (() => void) | undefined;
@@ -244,12 +254,23 @@ export function DriveView() {
// Never blocks the window: browse, open another folder, start another upload.
const batch = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`;
const into = here.id;
+ setPending((p) => [
+ ...p,
+ ...paths.map((path, i) => ({
+ key: `${batch}:${i}`,
+ folder: into,
+ name: path.split(/[\\/]/).filter(Boolean).pop() ?? path,
+ doing: "Uploading…",
+ })),
+ ]);
try {
await api.driveUpload(batch, into, paths);
// What failed is named in the tray, file by file; the folder is re-read either way.
if (into === here.id) await refresh();
} catch (e) {
setError(messageOf(e));
+ } finally {
+ settle(batch);
}
},
[here.id, refresh]
@@ -324,6 +345,8 @@ export function DriveView() {
}
folderPending.current = true;
setError(null);
+ const key = `folder-${Date.now()}`;
+ setPending((p) => [...p, { key, folder: here.id, name, doing: "Creating…" }]);
try {
await api.driveCreateFolder(here.id, name);
await refresh();
@@ -331,6 +354,7 @@ export function DriveView() {
setError(messageOf(e));
} finally {
folderPending.current = false;
+ settle(key);
}
}, [newFolderName, here.id, refresh, items]);
@@ -409,6 +433,20 @@ export function DriveView() {
)}
<ul className="drive-rows">
+ {pending
+ .filter((p) => p.folder === here.id && !items.some((i) => driveName(i) === p.name))
+ .map((p) => (
+ <li key={p.key} className="drive-row is-busy" aria-busy="true">
+ <span className="drive-row-hit">
+ <span className="drive-badge" aria-hidden="true">
+ <span className="drive-spinner" />
+ </span>
+ <span className="drive-name">{p.name}</span>
+ <span className="drive-meta">{p.doing}</span>
+ <span className="drive-meta" />
+ </span>
+ </li>
+ ))}
{creatingFolder && (
<li>
<form
@@ -539,7 +577,10 @@ export function DriveView() {
})}
</ul>
- {loaded && items.length === 0 && !creatingFolder && !error && (
+ {items.length === 0 && !creatingFolder && !error && (loading || !loaded) && (
+ <p className="cal-empty" aria-live="polite">Opening {here.name}…</p>
+ )}
+ {loaded && !loading && items.length === 0 && !creatingFolder && !error && (
<p className="cal-empty">This folder is empty.</p>
)}