Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.
Rust apple-notesapple-reminderscloudkitcrdtdesktop-appicloudicloud-calendaricloud-driveicloud-notesicloud-photosiphonelinuxlinux-desktoplocal-firstoffline-firstprivacyrusttauritauri-appwindows
Drive: two downloads at once each keep their spinner
Yashwanth Kamireddice9d599857a1
diff --git a/.uiverify/drive-two-downloads.mjs b/.uiverify/drive-two-downloads.mjsnew file mode 100644index 0000000..a19d6e2--- /dev/null+++ b/.uiverify/drive-two-downloads.mjs@@ -0,0 +1,48 @@+// Two files downloading at once each show they are downloading until their own download ends:+// the second took the first's spinner, and the first finishing cleared the second's.+//+// URL=http://localhost:4203 ENGINE=webkit node .uiverify/drive-two-downloads.mjs+import { engine, engineName } from "./engine.mjs";+import { SERVICES, installStub, openScreen } from "./stub.mjs";+const BASE = process.env.URL ?? "http://localhost:4173";+const b = await engine.launch();+let failures = 0;+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${engineName} ${m}`); if (!p) failures++; };+const ctx = await b.newContext({ viewport: { width: 1200, height: 800 } });+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null, driveFixture: true });+await ctx.addInitScript(() => {+ const wrap = () => {+ const t = window.__TAURI_INTERNALS__;+ if (!t || t.__dl) return;+ const inner = t.invoke;+ window.__finish = {};+ t.invoke = async (cmd, args) => {+ if (cmd === "drive_children") return [+ { drivewsid: "FILE::com.apple.CloudDocs::A", parentId: null, name: "Alpha", extension: "pdf", kind: "FILE", size: 10, childCount: null, createdAt: 1700000000, modifiedAt: 1700000000, etag: null },+ { drivewsid: "FILE::com.apple.CloudDocs::B", parentId: null, name: "Beta", extension: "pdf", kind: "FILE", size: 10, childCount: null, createdAt: 1700000000, modifiedAt: 1700000000, etag: null },+ ];+ if (cmd === "drive_download") return new Promise((r) => { window.__finish[args.drivewsid] = () => r(`/home/test/Downloads/${args.drivewsid}.pdf`); });+ return inner(cmd, args);+ };+ t.__dl = true;+ };+ wrap(); document.addEventListener("DOMContentLoaded", wrap);+});+const page = await ctx.newPage();+page.on("pageerror", (e) => ok(false, `page error: ${e.message}`));+await page.goto(BASE, { waitUntil: "networkidle" });+await openScreen(page, "Drive");+await page.waitForTimeout(400);+const busy = () => page.locator(".drive-row.is-busy .drive-name").allInnerTexts();+await page.locator(".drive-row-hit", { hasText: "Alpha" }).dblclick();+await page.locator(".drive-row-hit", { hasText: "Beta" }).dblclick();+await page.waitForTimeout(200);+const keys = await page.evaluate(() => Object.keys(window.__finish));+ok(keys.length === 2, `both are downloading ${JSON.stringify(keys)}`);+ok(JSON.stringify((await busy()).sort()) === JSON.stringify(["Alpha.pdf", "Beta.pdf"]), `and both say so ${JSON.stringify(await busy())}`);+await page.evaluate(() => window.__finish["FILE::com.apple.CloudDocs::A"]());+await page.waitForTimeout(200);+ok(JSON.stringify(await busy()) === JSON.stringify(["Beta.pdf"]), `the first done, the second still says so ${JSON.stringify(await busy())}`);+await b.close();+console.log(failures ? `\n${failures} FAILED` : "\nall passed");+process.exit(failures ? 1 : 0);diff --git a/src/screens/DriveView.tsx b/src/screens/DriveView.tsxindex 8e672cd..ab41bf4 100644--- a/src/screens/DriveView.tsx+++ b/src/screens/DriveView.tsx@@ -510,7 +510,18 @@ export function DriveView() {const [loaded, setLoaded] = useState(false);const [error, setError] = useState<string | null>(null);useErrorToast(error, () => setError(null));- const [busyGuid, setBusyGuid] = useState<string | null>(null);+ // Every item with something under way — two downloads at once each keep their spinner: one+ // value, the second took the first's, and the first one ending cleared the second's.+ const [busyIds, setBusyIds] = useState<ReadonlySet<string>>(new Set());+ const markBusy = useCallback((id: string, on: boolean) => {+ setBusyIds((was) => {+ if (was.has(id) === on) return was;+ const next = new Set(was);+ if (on) next.add(id);+ else next.delete(id);+ return next;+ });+ }, []);/** A file just saved to Downloads, and where — shown for a moment, then cleared. */const [renaming, setRenaming] = useState<string | null>(null);const [creatingFolder, setCreatingFolder] = useState(false);@@ -731,16 +742,16 @@ export function DriveView() {}, [due, refresh]);const download = useCallback(async (item: DriveItem) => {- setBusyGuid(item.drivewsid);+ markBusy(item.drivewsid, true);setError(null);try {toastSaved(await api.driveDownload(item.drivewsid));} catch (e) {setError(messageOf(e));} finally {- setBusyGuid(null);+ markBusy(item.drivewsid, false);}- }, []);+ }, [markBusy]);const rename = useCallback(@@ -753,7 +764,7 @@ export function DriveView() {setError(problem);return;}- setBusyGuid(item.drivewsid);+ markBusy(item.drivewsid, true);setError(null);// The new name shows the moment Return is pressed; Apple's answer confirms or undoes it.const ext = item.extension ? `.${item.extension}` : "";@@ -768,10 +779,10 @@ export function DriveView() {setItems((rows) => rows.map((r) => (r.drivewsid === item.drivewsid ? item : r)));setError(messageOf(e));} finally {- setBusyGuid(null);+ markBusy(item.drivewsid, false);}},- [refresh, items]+ [refresh, items, markBusy]);/**@@ -932,7 +943,7 @@ export function DriveView() {itemsRef.current = items;const settle = (key: string) => setPending((p) => p.filter((x) => !x.key.startsWith(key)));const writingRef = useRef(false);- writingRef.current = busyGuid !== null || renaming !== null || pending.length > 0;+ writingRef.current = busyIds.size > 0 || renaming !== null || pending.length > 0;// At most one re-read of the open folder every couple of seconds while files land.const landedTimer = useRef<number | null>(null);@@ -1293,7 +1304,7 @@ export function DriveView() {e.preventDefault();setPeeking(false);openItem(primary);- } else if (k === "F2" && primary && pickedItems.length === 1 && busyGuid !== primary.drivewsid) {+ } else if (k === "F2" && primary && pickedItems.length === 1 && !busyIds.has(primary.drivewsid)) {e.preventDefault();setPeeking(false);setRenaming(primary.drivewsid);@@ -1551,7 +1562,7 @@ export function DriveView() {<DriveRowkey={item.drivewsid}item={item}- busy={busyGuid === item.drivewsid}+ busy={busyIds.has(item.drivewsid)}selected={picked.includes(item.drivewsid)}menuOpen={menu?.item.drivewsid === item.drivewsid}dropTarget={dropOn === item.drivewsid}@@ -1626,7 +1637,7 @@ export function DriveView() {<QuickLookitem={primary}thumb={thumbs[primary.drivewsid]}- busy={busyGuid === primary.drivewsid}+ busy={busyIds.has(primary.drivewsid)}onOpen={() => { setPeeking(false); openItem(primary); }}onClose={() => setPeeking(false)}/>