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
Photos: a batch from another device says "Receiving 340 photos"
Yashwanth Kamireddic6b859a5ecad
diff --git a/.uiverify/photos-arrival.mjs b/.uiverify/photos-arrival.mjsindex 9bc8c9c..704aea7 100644--- a/.uiverify/photos-arrival.mjs+++ b/.uiverify/photos-arrival.mjs@@ -122,6 +122,56 @@ const say = (r) => `remade ${r.remade}, blank ${r.blank}, lost ${r.lost}, movedawait ctx.close();}+// A batch from another device is said under the title — "Receiving 30 photos" — while its+// pictures come in, then the line goes; one photo, or the person's own upload, says nothing.+{+ const ctx = await b.newContext({ viewport: { width: 1280, height: 800 } });+ await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null });+ await ctx.addInitScript(instrument);+ await ctx.addInitScript(library);+ await ctx.addInitScript(() => {+ window.__said = [];+ new MutationObserver(() => {+ const t = document.querySelector(".px-receiving")?.textContent;+ if (t && window.__said.at(-1) !== t) window.__said.push(t);+ }).observe(document, { subtree: true, childList: true, characterData: true });+ });+ // Pictures a while in coming, as from the network: the line waits for them.+ await servePictures(ctx, { delay: 2600 });+ const page = await ctx.newPage();+ page.on("pageerror", (e) => ok(false, `page error: ${e.message}`));+ await page.goto(URL, { waitUntil: "networkidle" });+ await openScreen(page, "Photos");+ await page.locator(".px-tile img[data-in]").first().waitFor({ timeout: 15000 });+ const said = () => page.evaluate(() => window.__said.splice(0));+ const gone = () => page.waitForFunction(() => !document.querySelector(".px-receiving"), null, { timeout: 15000 }).then(() => true, () => false);++ await land(page, cfg, { changed: ["photos"], mutate: arrive(one("pS", newest + 600)) });+ ok((await said()).length === 0, "one photo arriving says nothing under the title");++ await land(page, cfg, { changed: ["photos"], mutate: arrive(many(30, newest + 50 * 86400, "pB")) });+ const landedAt = Date.now();+ const words = await said();+ ok(words.includes("Receiving 30 photos"), `thirty arriving at once say "Receiving 30 photos" (${JSON.stringify(words)})`);+ ok(/·\s*Receiving 30 photos/.test(await page.locator(".px-span").innerText()), `…after the months shown, on the title's own line (${await page.locator(".px-span").innerText()})`);+ // Still there while their pictures are on their way.+ await page.waitForTimeout(Math.max(0, 2200 - (Date.now() - landedAt)));+ const stillWaiting = await page.evaluate(() => [...document.querySelectorAll('.px-tile[data-id^="pB"] img')].some((i) => !i.dataset.in));+ ok(!stillWaiting || (await page.locator(".px-receiving").count()) === 1, "…and stays while their pictures are still coming");+ ok(await gone(), "…and goes once they are in");++ await land(page, cfg, { changed: ["photos"], mutate: arrive(`[...${many(18, newest + 60 * 86400, "pV")}].map((p, i) => i < 3 ? { ...p, kind: "video", duration: 9 } : p)`) });+ ok((await said()).includes("Receiving 18 items"), "photos and videos together are items");+ await gone();++ // The person's own upload, landing as a batch: the upload panel already speaks for it.+ await page.evaluate(() => { for (let i = 0; i < 20; i++) window.__emit("quince://photo-upload", { id: `u${i}`, batch: "b1", name: `IMG_pO${i}.JPG`, within: "", sent: 1, total: 1, folder: false, error: null, state: "done" }); });+ await page.waitForTimeout(200);+ await land(page, cfg, { changed: ["photos"], mutate: arrive(many(20, newest + 70 * 86400, "pO")) });+ ok((await said()).length === 0, "the person's own upload landing says nothing under the title");+ await ctx.close();+}+// Opening Photos and switching views never fades a tile.{const ctx = await b.newContext({ viewport: { width: 1280, height: 800 } });diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsxindex 627c6a6..f72cd8a 100644--- a/src/screens/PhotosView.tsx+++ b/src/screens/PhotosView.tsx@@ -97,6 +97,11 @@ const pickedWords = (kinds: Photo["kind"][]) => {const noun = videos === 0 ? "Photo" : videos === n ? "Video" : "Item";return `${n.toLocaleString()} ${n === 1 ? noun : `${noun}s`} Selected`;};+/** "340 photos", "12 videos", "352 items" — what a batch being received holds. */+const receivingWords = (n: number, videos: number) => {+ const noun = videos === 0 ? "photo" : videos === n ? "video" : "item";+ return `${n.toLocaleString()} ${n === 1 ? noun : `${noun}s`}`;+};type Flag = "favorite" | "deleted" | "hidden" | "expunged";@@ -230,6 +235,9 @@ const arrived = new Map<string, number>();const ARRIVALS = 12;/** How long an arrival is one: its tile is made within a frame or two of it being drawn. */const ARRIVAL_MS = 1500;+/** "Receiving 340 photos" stays at least this long, to be read, and at most this long. */+const RECEIVING_SHOWN = 1800;+const RECEIVING_MOST = 30_000;/** Whether a tile being made now is for a photo that has just arrived. */function justArrived(id: string): boolean {const at = arrived.get(id);@@ -442,7 +450,10 @@ const Tile = memo(function Tile({fadeIn(e.currentTarget, { duration: 120 });}}}- onError={under}+ onError={(e) => {+ e.currentTarget.dataset.gone = "";+ under();+ }}/>{photo.kind === "video" && (<span className="px-badge px-duration">@@ -824,6 +835,24 @@ export function PhotosView() {anchorList.current = photos;}const [uploads, setUploads] = useState<Map<string, UploadEvent>>(new Map());+ /**+ * A batch of photos from another device landing in the view (see read): which, how many of+ * them are videos, and when the last of them landed. Said under the title until the pictures+ * of those near the screen are in — at least a moment, so it is read, and never for long.+ */+ const [receiving, setReceiving] = useState<{ ids: Set<string>; videos: number; at: number } | null>(null);+ useEffect(() => {+ if (!receiving) return undefined;+ const t = window.setInterval(() => {+ const age = performance.now() - receiving.at;+ // Only tiles built (near the screen) and still waiting on their picture; one whose+ // picture cannot be made shows its thumbnail and waits no more.+ const waiting = [...(scroller.current?.querySelectorAll<HTMLImageElement>(".px-tile img:not([data-in]):not([data-gone])") ?? [])]+ .some((img) => receiving.ids.has(img.closest<HTMLElement>(".px-tile")?.dataset.id ?? ""));+ if ((!waiting && age > RECEIVING_SHOWN) || age > RECEIVING_MOST) setReceiving(null);+ }, 250);+ return () => window.clearInterval(t);+ }, [receiving]);const [dropping, setDropping] = useState(false);const [menu, setMenu] = useState<{ at: { x: number; y: number; alignRight: boolean }; entries: MenuEntry[] } | null>(null);/** An album being named in the sidebar: a new one (with the photos to put in it), or a rename. */@@ -905,6 +934,8 @@ export function PhotosView() {const order: PhotoOrder | null = want;const d = drawnNow.current;const again = photosNow.current !== null && d.view === view && d.album?.id === album?.id && d.query === searching;+ // Another place: photos being received into the last one are not this one's to speak of.+ if (!again) setReceiving(null);const index = api.photosIndex(source, order);let indexed = false;// Another place chosen: its first screen from its first page, which is small and comes at@@ -934,10 +965,21 @@ export function PhotosView() {// A few arriving where the grid was already drawn from a whole read fade in, each alone;// a batch, the person's own, or anything over a partial first page simply appears.const own = ownNames();- const arriving = before === readList.current && !before.partial && fresh.length <= ARRIVALS+ const incoming = before === readList.current && !before.partial? fresh.filter((id) => !ownIds.current.has(id) && !own.has(store.get(id)?.filename ?? "")): [];+ const arriving = fresh.length <= ARRIVALS ? incoming : [];const at = performance.now();+ // A batch from another device: the line under the title says so while its pictures come+ // in, as Photos' quiet status line does, rather than tile after tile appearing unexplained.+ // Photos landing while it is up are counted in.+ setReceiving((was) => {+ if (incoming.length <= ARRIVALS && !was) return was;+ const added = incoming.filter((id) => !was?.ids.has(id));+ if (!added.length) return was;+ const videos = (was?.videos ?? 0) + added.filter((id) => (next.marks[next.indexOf(id)] & 3) === 1).length;+ return { ids: new Set([...(was?.ids ?? []), ...added]), videos, at };+ });for (const [id, when] of arrived) if (at - when > ARRIVAL_MS) arrived.delete(id);for (const id of arriving) arrived.set(id, at);const keep = anchorOf(scroller.current);@@ -3142,7 +3184,16 @@ export function PhotosView() {? pickedWords(kindsOf(selected)): drawn.query? photos?.length === 1 ? "1 Result" : `${(photos?.length ?? 0).toLocaleString()} Results`- : (here ?? span) || undefined+ : receiving+ ? (+ <>+ {(here ?? span) && <>{here ?? span} · </>}+ <span className="px-receiving" role="status">+ Receiving {receivingWords(receiving.ids.size, receiving.videos)}+ </span>+ </>+ )+ : (here ?? span) || undefined}>{title}