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 suites: the Library's levels, and on fifty thousand photos
Yashwanth Kamireddi2d2dd50d8aa8
diff --git a/.uiverify/photos-levels-scale.mjs b/.uiverify/photos-levels-scale.mjsnew file mode 100644index 0000000..f49492e--- /dev/null+++ b/.uiverify/photos-levels-scale.mjs@@ -0,0 +1,142 @@+// Years and Months on a library of fifty thousand photos over twenty years: each level is up in+// a frame or two, holds a tile a year or a month (never a box a photo), fetches pictures only for+// the tiles near the screen, scrolls without a long frame, and All Photos comes back as it was —+// the grid kept, not built again — or lands exactly on a month twenty years down.+//+// Headless WebKit paints in software, every frame on the CPU: its bounds are looser, as in+// photos-scroll, and guard against a level that freezes, not against its software paint.+import http from "node:http";+import { engine, engineName } from "./engine.mjs";+import { SERVICES, installStub, openScreen } from "./stub.mjs";+const b = await engine.launch();+const SWITCH = engineName === "chromium" ? 250 : 600;+const BOUND = engineName === "chromium" ? 120 : 900;+// Photo-like pictures made once by the engine's own canvas and served from here, as+// photos-scroll serves them: a page.route per picture is a round trip through the driver, and+// that was what got measured.+const maker = await b.newPage();+const pics = await maker.evaluate(() => Array.from({ length: 12 }, (_, i) => {+ const c = document.createElement("canvas"); c.width = 384; c.height = 288;+ const g = c.getContext("2d");+ const grad = g.createLinearGradient(0, 0, 384, 288);+ grad.addColorStop(0, `hsl(${i * 30} 70% 60%)`); grad.addColorStop(1, `hsl(${i * 30 + 120} 60% 35%)`);+ g.fillStyle = grad; g.fillRect(0, 0, 384, 288);+ return c.toDataURL("image/jpeg", 0.8).split(",")[1];+}));+await maker.close();+const bufs = pics.map((p) => Buffer.from(p, "base64"));+const served = [];+const server = http.createServer((q, r) => {+ const path = decodeURIComponent(q.url);+ served.push(path);+ const n = Number(path.match(/q(\d+)/)?.[1] ?? 0);+ r.writeHead(200, { "content-type": "image/jpeg", "cache-control": "max-age=3600", "access-control-allow-origin": "*" });+ r.end(bufs[n % bufs.length]);+}).listen(0);+const ctx = await b.newContext({ viewport: { width: 1280, height: 800 } });+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null });+await ctx.addInitScript((base) => { window.__picBase = base; }, `http://127.0.0.1:${server.address().port}`);+await ctx.addInitScript(() => {+ const P = (id, t) => ({ id, master: `m${id}`, takenAt: t, addedAt: t, kind: "image", width: 4032, height: 3024, duration: null,+ filename: `IMG_${id}.JPG`, size: 2400000, uti: "public.jpeg", favorite: false, hidden: false, deleted: false, deletedAt: null, subtype: 0, changeTag: null });+ window.__photos = Array.from({ length: 50000 }, (_, i) => P(`q${i}`, 1792000000 - i * 12600));+});+const page = await ctx.newPage();+page.on("pageerror", (e) => { console.log(`FAIL page error: ${e.message}`); process.exitCode = 1; });+await page.goto("http://localhost:4173", { waitUntil: "networkidle" });+let failures = 0;+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };+await openScreen(page, "Photos");+await page.locator(".px-tile").first().waitFor();+await page.waitForTimeout(600);+// The stub's own answer made before anything is measured (it walks fifty thousand in script,+// where the app's library answers from SQLite).+const months = await page.evaluate(() => window.__TAURI_INTERNALS__.invoke("photos_months").then((m) => m.length));+const years = await page.evaluate(() => new Set(window.__photos.map((p) => new Date(p.takenAt * 1000).getFullYear())).size);++// A tile on the grid, marked: still the same element after Years and back means it was kept.+await page.evaluate(() => { document.querySelector(".px-tile").__kept = true; });+const tilesBefore = await page.locator(".px-tile").count();++/** A click on the switch until its level is drawn and two frames are painted. */+const timed = (name, sel) => page.evaluate(async ([name, sel]) => {+ const t = performance.now();+ [...document.querySelectorAll(".px-levels button")].find((x) => x.textContent === name).click();+ while (!document.querySelector(sel)) await new Promise((r) => requestAnimationFrame(r));+ await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));+ return performance.now() - t;+}, [name, sel]);++const yearsMs = await timed("Years", '.px-periods[data-level="years"] .px-period');+ok(yearsMs < SWITCH, `Years is up at once on fifty thousand (${Math.round(yearsMs)}ms, two frames included)`);+const yearTiles = await page.locator(".px-periods-grid").getAttribute("data-count").then(Number);+ok(yearTiles === years, `…a tile a year (${yearTiles} for ${years} years, ${await page.locator(".px-period").count()} made)`);+served.length = 0;+const monthsMs = await timed("Months", '.px-periods[data-level="months"] .px-period');+ok(monthsMs < SWITCH, `Months is up at once (${Math.round(monthsMs)}ms)`);+const tiles = await page.locator(".px-periods-grid").getAttribute("data-count").then(Number);+const made = await page.locator(".px-period").count();+ok(tiles === months && made < 60, `…a tile a month, never one a photo, only those near the screen made (${tiles} tiles for ${months} months, ${made} made)`);+await page.waitForTimeout(500);+const fetched = await page.evaluate(() => [...document.querySelectorAll(".px-period img")].filter((i) => i.complete && i.naturalWidth > 0).length);+// The tiles' own pictures (the grid's carry a version mark, "~"), asked for since Months came up.+const asked = served.filter((u) => /fit\d+/.test(u) && !u.includes("~"));+ok(fetched > 0 && asked.length <= made * 4, `…pictures fetched only for the tiles made (${asked.length} asked for, ${made} tiles)`);+ok(asked.every((u) => Number(/fit(\d+)/.exec(u)[1]) <= 1024), `…each at most 1024px, never an original (${[...new Set(asked.map((u) => /fit\d+/.exec(u)[0]))].join(", ")})`);++// All Photos again: back at once, and the grid is the one it was, kept beneath — not built anew.+const allMs = await page.evaluate(async () => {+ const t = performance.now();+ [...document.querySelectorAll(".px-levels button")].find((x) => x.textContent === "All Photos").click();+ while (document.querySelector(".px-periods")) await new Promise((r) => requestAnimationFrame(r));+ await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));+ return performance.now() - t;+});+ok(allMs < SWITCH, `All Photos is back at once (${Math.round(allMs)}ms)`);+ok(await page.evaluate(() => document.querySelector(".px-tile").__kept === true), `…the very grid it was, kept beneath (${await page.locator(".px-tile").count()} tiles, ${tilesBefore} before)`);+await timed("Months", '.px-periods[data-level="months"] .px-period');++// Flung from top to bottom at 9,000px a second, a step a frame, its pictures decoding as they+// come: no frame held.+const scroll = await page.evaluate(() => new Promise((done) => {+ const el = document.querySelector(".px-periods");+ const gaps = [];+ let last = performance.now();+ const step = (now) => {+ gaps.push(now - last);+ el.scrollTop += (9000 * (now - last)) / 1000;+ last = now;+ if (el.scrollTop + el.clientHeight < el.scrollHeight - 2) requestAnimationFrame(step);+ else {+ gaps.shift();+ gaps.sort((a, b) => a - b);+ done({ frames: gaps.length, p95: gaps[Math.floor(gaps.length * 0.95)], worst: gaps[gaps.length - 1] });+ }+ };+ requestAnimationFrame((t) => { last = t; requestAnimationFrame(step); });+}));+ok(scroll.worst < BOUND, `Months flings end to end without a held frame (${scroll.frames} frames, p95 ${Math.round(scroll.p95)}ms, longest ${Math.round(scroll.worst)}ms, bound ${BOUND})`);++// A month nineteen years down (a year above the last, which cannot scroll to the top): All+// Photos lands exactly on it.+const oldest = page.locator(".px-period").nth(-13);+const label = await oldest.locator("strong").textContent();+const t = Date.now();+// Clicked where it is (a pointer click at a point lands on whichever tile a scroll brought there).+await oldest.evaluate((el) => el.click());+await page.waitForFunction(() => document.querySelector('.px-levels [aria-pressed="true"]')?.textContent === "All Photos");+const landMs = Date.now() - t;+await page.waitForTimeout(300);+const top = await page.evaluate(() => {+ const el = document.querySelector(".px-scroll");+ const edge = el.getBoundingClientRect().top + parseFloat(getComputedStyle(el).scrollPaddingTop) + 4;+ return [...el.querySelectorAll(".px-month")].find((s) => s.getBoundingClientRect().bottom > edge)?.dataset.month ?? null;+});+ok(top === label, `a month twenty years down opens All Photos exactly there (${top} for ${label}, ${landMs}ms)`);+// Its photos come in where it landed.+await page.waitForFunction((l) => document.querySelector(`.px-month[data-month="${l}"] .px-tile`), label, { timeout: 5000 }).catch(() => {});+ok(await page.locator(`.px-month[data-month="${label}"] .px-tile`).count() > 0, "…and its photos are built there");++await b.close();+server.close();+process.exitCode = failures ? 1 : (process.exitCode ?? 0);diff --git a/.uiverify/photos-levels.mjs b/.uiverify/photos-levels.mjsnew file mode 100644index 0000000..08cd523--- /dev/null+++ b/.uiverify/photos-levels.mjs@@ -0,0 +1,170 @@+// Years, Months and All Photos, as Photos on a Mac steps through its Library: the switch in the+// toolbar (Library only), a year opening its months, a month opening All Photos at that month,+// Escape and Ctrl+[ stepping back out, the keys between tiles, the level kept, and a sync+// bringing a new month into Months as it lands.+import { engine } from "./engine.mjs";+import { SERVICES, installStub, openScreen } from "./stub.mjs";+import { servePictures, status } from "./arrival.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 });+await servePictures(ctx);+// Three years, nine photos a month from November 2023 to October 2026 (noon, this machine's+// time, so every one is in the month it says); one favourite, in March 2025, and in April 2025+// a video in the middle of the month.+await ctx.addInitScript(() => {+ if (window.__photos) return;+ const P = (id, t, extra = {}) => ({ id, master: `m${id}`, takenAt: t, addedAt: t, kind: "image", width: 4032, height: 3024, duration: null,+ filename: `IMG_${id}.JPG`, size: 1, uti: "public.jpeg", favorite: false, hidden: false, deleted: false, deletedAt: null, subtype: 0, changeTag: null, ...extra });+ window.__mk = P;+ const out = [];+ for (let m = 0; m < 36; m++) {+ const d = new Date(2026, 9 - m, 1);+ for (let k = 0; k < 9; k++) {+ const id = `y${d.getFullYear()}m${d.getMonth() + 1}k${k}`;+ const extra = d.getFullYear() === 2025 && d.getMonth() === 2 && k === 7 ? { favorite: true }+ : d.getFullYear() === 2025 && d.getMonth() === 3 && k === 4 ? { kind: "video", duration: 4, uti: "public.mpeg-4" } : {};+ out.push(P(id, new Date(d.getFullYear(), d.getMonth(), 2 + k * 3, 12).getTime() / 1000, extra));+ }+ }+ window.__photos = out.sort((a, b) => b.takenAt - a.takenAt);+});+const page = await ctx.newPage();+page.on("pageerror", (e) => { console.log(`FAIL page error: ${e.message}`); process.exitCode = 1; });+await page.goto("http://localhost:4173", { waitUntil: "networkidle" });+let failures = 0;+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };+await openScreen(page, "Photos");+await page.locator(".px-tile").first().waitFor();++const seg = (name) => page.locator(".px-levels").getByRole("button", { name, exact: true });+const pressed = async () => (await page.locator('.px-levels [aria-pressed="true"]').textContent())?.trim();+// What the grid shows at its top, under the floating bar: the month whose photos are there.+const gridTop = () => page.evaluate(() => {+ const el = document.querySelector(".px-scroll");+ const edge = el.getBoundingClientRect().top + parseFloat(getComputedStyle(el).scrollPaddingTop) + 4;+ const sec = [...el.querySelectorAll(".px-month")].find((s) => s.getBoundingClientRect().bottom > edge);+ return sec?.dataset.month ?? null;+});+// The row at the top of Years or Months, under the floating bar: its tiles' names.+const periodTop = () => page.evaluate(() => {+ const el = document.querySelector(".px-periods");+ const edge = el.getBoundingClientRect().top + parseFloat(getComputedStyle(el).scrollPaddingTop);+ const row = [...el.querySelectorAll(".px-period")].filter((t) => Math.abs(t.getBoundingClientRect().top - edge) < 8);+ return row.map((t) => t.querySelector("strong").textContent);+});++// The switch: the Library's, with All Photos to begin with.+ok(await page.locator(".px-levels").count() === 1, "the Library has the Years, Months and All Photos switch");+ok(await pressed() === "All Photos", `…on All Photos to begin with (${await pressed()})`);++// Years: a tile a year, newest first, each with its count; the grid's own controls go.+await seg("Years").click();+await page.locator('.px-periods[data-level="years"] .px-period').first().waitFor();+const years = await page.locator(".px-period strong").allTextContents();+ok(years.join(",") === "2026,2025,2024,2023", `Years shows a tile a year, newest first (${years.join(", ")})`);+const y2025 = await page.locator('.px-period[data-period="2025"]').getAttribute("aria-label");+ok(y2025 === "2025, 107 Photos, 1 Video", `…each saying what it holds (${y2025})`);+ok(await page.locator('.px-period[data-period="2025"] img').getAttribute("src").then((s) => s.includes("y2025m3k7")), "…2025 shown by its favourite");+ok(await page.locator(".px-scroll").evaluate((e) => getComputedStyle(e).display) === "none" && await page.locator(".px-tile").count() > 0, "the grid stays beneath, kept but out of the layout");+ok(await page.getByRole("button", { name: "Zoom In" }).count() === 0 && await page.getByRole("button", { name: "Show Whole Photos" }).count() === 0, "the grid's zoom and shape controls go while Years shows");+ok(await page.getByRole("button", { name: "Add Photos" }).count() === 1, "…Add Photos stays");++// A year opens Months at that year: its newest month at the top, focused.+await page.locator('.px-period[data-period="2025"]').click();+await page.locator('.px-periods[data-level="months"]').waitFor();+ok(await pressed() === "Months", "a year opens Months");+ok((await periodTop()).includes("December 2025"), `…its row at the top, with that year's newest month (${(await periodTop()).join(", ")})`);+ok(await page.evaluate(() => document.activeElement?.dataset.period) === "2025-12", "…which takes the keys");+const apr = page.locator('.px-period[data-period="2025-4"]');+ok(!(await apr.locator("img").first().getAttribute("src")).includes("y2025m4k4"), "a month is shown by a still, not the video in its middle");+ok(await apr.locator("img").count() === 4, `…with three more of its photos beside it (${await apr.locator("img").count()} pictures)`);+const sizes = await page.evaluate(() => [...document.querySelectorAll(".px-period img")].map((i) => Number(/fit(\d+)/.exec(i.getAttribute("src"))?.[1] ?? 0)));+ok(Math.max(...sizes) <= 512, `…its pictures thumbnails, never originals (largest ${Math.max(...sizes)}px)`);++// The arrows go between tiles as they are laid out.+const across = await page.evaluate(() => getComputedStyle(document.querySelector(".px-periods-grid")).gridTemplateColumns.split(" ").length);+await page.keyboard.press("ArrowRight");+ok(await page.evaluate(() => document.activeElement?.dataset.period) === "2025-11", "the right arrow goes to the next month");+await page.keyboard.press("ArrowDown");+const down = await page.evaluate(() => document.activeElement?.dataset.period);+ok(down === `2025-${11 - across}`, `…the down arrow a row down (${down}, ${across} across)`);+await page.keyboard.press("ArrowUp");+await page.keyboard.press("ArrowLeft");+ok(await page.evaluate(() => document.activeElement?.dataset.period) === "2025-12", "…and back");++// Enter opens the month: All Photos at December 2025.+await page.keyboard.press("Enter");+await page.waitForFunction(() => document.querySelector('.px-levels [aria-pressed="true"]')?.textContent === "All Photos");+await page.waitForTimeout(150);+ok(await gridTop() === "December 2025", `a month opens All Photos at that month (${await gridTop()})`);+ok(await page.locator(".px-scroll").evaluate((e) => getComputedStyle(e).display) !== "none" && await page.locator(".px-periods").count() === 0, "…the grid shown, the tiles gone");++// Escape steps out to Months, at the month the grid was at; Ctrl+[ steps out to Years.+await page.locator(".px-scroll").evaluate((e) => (e.scrollTop += 900));+await page.waitForTimeout(300);+// The month the title names, as the grid reads its top.+const there = await page.locator(".px-heading .px-span").textContent();+const scrolled = await page.locator(".px-scroll").evaluate((e) => e.scrollTop);+await page.evaluate(() => document.activeElement?.blur());+await page.keyboard.press("Escape");+await page.locator('.px-periods[data-level="months"]').waitFor();+ok((await periodTop()).includes(there) && await page.evaluate(() => document.activeElement?.querySelector("strong")?.textContent) === there,+ `Escape steps out to Months, at the month the grid was at (${there}; top row ${(await periodTop()).join(", ")})`);+// And back, to exactly where the grid was.+await seg("All Photos").click();+await page.waitForTimeout(100);+const back = await page.locator(".px-scroll").evaluate((e) => e.scrollTop);+ok(Math.abs(back - scrolled) < 2, `…All Photos again comes back exactly where it was (${back} for ${scrolled})`);+await page.keyboard.press("Control+BracketLeft");+await page.locator('.px-periods[data-level="months"]').waitFor();+await page.keyboard.press("Control+BracketLeft");+await page.locator('.px-periods[data-level="years"]').waitFor();+ok(await pressed() === "Years", "Ctrl+[ steps out to Months, then to Years");+const yearTop = await page.evaluate(() => document.activeElement?.dataset.period);+ok(yearTop === there.split(" ").pop(), `…at the year it was in (${yearTop})`);+await page.keyboard.press("Escape");+await page.waitForTimeout(100);+ok(await pressed() === "Years", "Escape in Years stays in Years");++// With a selection in All Photos, Escape lets the selection go first.+await seg("All Photos").click();+await page.locator(".px-tile").nth(2).click();+await page.keyboard.press("Escape");+await page.waitForTimeout(100);+ok(await pressed() === "All Photos" && await page.locator('.px-tile[aria-selected="true"]').count() === 0, "Escape with photos selected lets them go, and stays");++// The switch from the keys: Tab to it, Enter on Months.+await seg("Months").focus();+await page.keyboard.press("Enter");+await page.locator('.px-periods[data-level="months"]').waitFor();+ok(await pressed() === "Months", "the switch answers the keys");+// Ctrl+A in Months chooses nothing behind it.+await page.keyboard.press("Control+a");+ok(await page.locator('.px-tile[aria-selected="true"]').count() === 0, "Ctrl+A in Months selects nothing behind it");++// A sync bringing a new month: it shows in Months as it lands.+await page.evaluate(() => {+ const t = new Date(2026, 10, 3, 12).getTime() / 1000;+ window.__photos = [window.__mk("nov1", t), window.__mk("nov2", t + 60), ...window.__photos];+});+await page.evaluate((payload) => window.__emit("quince://synced", payload), status(["photos"]));+await page.locator('.px-period[data-period="2026-11"]').waitFor({ timeout: 5000 }).catch(() => {});+ok(await page.locator('.px-period[data-period="2026-11"]').getAttribute("aria-label").catch(() => null) === "November 2026, 2 Photos", "a month brought by a sync shows in Months as it lands");++// Only the Library has the levels: Favorites is its grid.+await page.locator(".px-side").getByRole("button", { name: /Favorites/ }).first().click();+await page.waitForFunction(() => document.querySelector(".px-heading h1")?.textContent?.includes("Favorites"));+ok(await page.locator(".px-levels").count() === 0 && await page.locator(".px-periods").count() === 0, "Favorites has no levels: its own grid");+await page.locator(".px-side").getByRole("button", { name: /Library/ }).first().click();+await page.locator('.px-periods[data-level="months"]').waitFor();+ok(await pressed() === "Months", "back in the Library, Months as it was left");++// Kept on this machine.+await page.reload({ waitUntil: "networkidle" });+await openScreen(page, "Photos");+await page.locator('.px-periods[data-level="months"]').waitFor({ timeout: 5000 }).catch(() => {});+ok(await pressed() === "Months", "the level is kept for next time");++await b.close();+process.exitCode = failures ? 1 : (process.exitCode ?? 0);diff --git a/.uiverify/stub.mjs b/.uiverify/stub.mjsindex 5258770..befa61b 100644--- a/.uiverify/stub.mjs+++ b/.uiverify/stub.mjs@@ -689,6 +689,32 @@ export function installStub({ screen, services, twoFactor, calendarFixture, notelast: taken.length ? Math.max(...taken) : null,};}+ // The library's months, as quince-core photo_months chooses them: counted, with a+ // favourite (or else the still nearest the middle) as the key and three spread through.+ case "photos_months": {+ (window.__monthReads ??= []).push(Date.now());+ // Worked out once per fixture: on fifty thousand, the stub's own work showed as the app's.+ if (window.__monthsOf?.all === window.__photos) return window.__monthsOf.months;+ const self = window.__TAURI_INTERNALS__.invoke;+ const lib = (await self("photos_list", { view: "library" })).sort((a, b) => a.takenAt - b.takenAt || (a.id < b.id ? -1 : 1));+ const groups = new Map();+ for (const p of lib) {+ const d = new Date(p.takenAt * 1000);+ const k = d.getFullYear() * 100 + d.getMonth() + 1;+ if (!groups.has(k)) groups.set(k, []);+ groups.get(k).push(p);+ }+ const months = [...groups.entries()].sort((a, b) => b[0] - a[0]).map(([k, ps]) => {+ const n = ps.length;+ const mid = ps[Math.floor(n / 2)].takenAt;+ const score = (p) => (p.favorite ? 0 : 4e12) + (p.kind === "video" ? 2e12 : 0) + Math.abs(p.takenAt - mid);+ const key = ps.reduce((best, p) => (score(p) < score(best) ? p : best));+ const more = n >= 4 ? [...new Set([Math.floor((3 * n) / 4), Math.floor(n / 2), Math.floor(n / 4)].map((i) => ps[i].id))].filter((id) => id !== key.id) : [];+ return { year: Math.floor(k / 100), month: k % 100, count: n, videos: ps.filter((p) => p.kind === "video").length, key: key.id, keyFavorite: !!key.favorite, more };+ });+ window.__monthsOf = { all: window.__photos, months };+ return months;+ }case "photos_get": {(window.__gets ??= []).push(args.ids.length);const all = window.__photos ?? [];