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.

Photos: a slideshow over the viewer has the screen to itself

Yashwanth Kamireddi33911127c7b9
diff --git a/.uiverify/photos-show-over.mjs b/.uiverify/photos-show-over.mjs
new file mode 100644
index 0000000..eb3ed89
--- /dev/null
+++ b/.uiverify/photos-show-over.mjs
@@ -0,0 +1,69 @@
+// A slideshow started from the viewer has the screen to itself: a film open behind it stops
+// playing, and the viewer's own keys (F favourites, H hides, Delete deletes) do nothing to the
+// photo behind while the show is up — they used to act on it, unseen.
+//
+// URL=http://localhost:4203 ENGINE=webkit node .uiverify/photos-show-over.mjs
+import http from "node:http";
+import fs from "node:fs";
+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++; };
+// The app's loopback video server, as photos-video.mjs plays it.
+const clip = new URL("./clip.webm", import.meta.url);
+const len = fs.statSync(clip).size;
+const server = http.createServer((req, res) => {
+ if (!req.url.startsWith("/v/p3/")) return void res.writeHead(404).end();
+ const m = /bytes=(\d*)-(\d*)/.exec(req.headers.range ?? "");
+ const first = m && m[1] ? +m[1] : 0;
+ const last = m && m[2] ? Math.min(+m[2], len - 1) : len - 1;
+ res.writeHead(m ? 206 : 200, { "Content-Type": "video/webm", "Accept-Ranges": "bytes", "Content-Length": last - first + 1, "Content-Range": `bytes ${first}-${last}/${len}` });
+ fs.createReadStream(clip, { start: first, end: last }).pipe(res);
+});
+await new Promise((r) => server.listen(0, "127.0.0.1", r));
+const ctx = await b.newContext({ viewport: { width: 1280, height: 800 } });
+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null });
+await ctx.addInitScript((v) => { window.__videoBase = v; }, `http://127.0.0.1:${server.address().port}/v`);
+const page = await ctx.newPage();
+page.on("pageerror", (e) => ok(false, `page error: ${e.message}`));
+await page.goto(BASE, { waitUntil: "networkidle" });
+await openScreen(page, "Photos");
+await page.waitForTimeout(500);
+await page.locator('.px-tile[data-id="p2"]').dblclick();
+await page.waitForTimeout(300);
+await page.getByRole("button", { name: "Start Slideshow" }).click();
+await page.locator(".px-show").waitFor();
+await page.waitForTimeout(200);
+for (const key of ["f", "h", "Delete", "i"]) await page.keyboard.press(key);
+await page.waitForTimeout(300);
+const flags = await page.evaluate(() => window.__flags ?? []);
+ok(flags.length === 0, `keys pressed during the show change nothing behind it ${JSON.stringify(flags)}`);
+ok((await page.locator(".confirm, [role=alertdialog]").count()) === 0, "and ask nothing");
+ok((await page.locator(".px-show").count()) === 1, "the show is still up");
+await page.keyboard.press("Escape");
+await page.waitForTimeout(200);
+ok((await page.locator(".px-show").count()) === 0 && (await page.locator(".px-viewer").count()) === 1, "Escape ends the show, back to the viewer");
+
+// A film open in the viewer is stopped by a show started over it.
+await page.reload({ waitUntil: "networkidle" });
+await openScreen(page, "Photos");
+await page.waitForTimeout(500);
+await page.locator('.px-tile[data-id="p3"]').dblclick();
+await page.waitForTimeout(800);
+const film = page.locator(".px-viewer video");
+if ((await film.count()) === 0) ok(false, "the film opens in the viewer");
+else {
+ await film.first().evaluate((v) => { v.muted = true; return v.play().catch(() => {}); });
+ await page.waitForTimeout(200);
+ ok(!(await film.first().evaluate((v) => v.paused)), "the film plays in the viewer");
+ await page.getByRole("button", { name: "Start Slideshow" }).click();
+ await page.locator(".px-show").waitFor();
+ await page.waitForTimeout(300);
+ ok(await film.first().evaluate((v) => v.paused), "and is stopped when a show starts over it");
+}
+await b.close();
+server.close();
+console.log(failures ? `\n${failures} FAILED` : "\nall passed");
+process.exit(failures ? 1 : 0);
diff --git a/src/screens/photos/Slideshow.tsx b/src/screens/photos/Slideshow.tsx
index 7580dc1..df407ed 100644
--- a/src/screens/photos/Slideshow.tsx
+++ b/src/screens/photos/Slideshow.tsx
@@ -309,7 +309,13 @@ export function Slideshow({
else if (e.key === " ") toggle();
else if (e.key === "ArrowRight") void go(1);
else if (e.key === "ArrowLeft") void go(-1);
- else return;
+ else {
+ // Every other key stops here too: the viewer and the grid behind took F, H and Delete
+ // as their own and changed the photo under the show, unseen. Its default still
+ // happens — Tab still moves along the show's own controls.
+ e.stopPropagation();
+ return;
+ }
e.preventDefault();
e.stopPropagation();
};
@@ -318,6 +324,14 @@ export function Slideshow({
return () => window.removeEventListener("keydown", onKey, true);
}, [go, toggle, onClose]); // eslint-disable-line react-hooks/exhaustive-deps
+ // A film playing in the viewer behind stops as the show begins: it went on, heard and
+ // unseen, under the show.
+ useEffect(() => {
+ document.querySelectorAll<HTMLVideoElement>("video").forEach((v) => {
+ if (!v.closest(".px-show")) v.pause();
+ });
+ }, []);
+
// The controls show when the pointer moves and go once it rests.
const idle = useRef<number | undefined>(undefined);
const wake = () => {
diff --git a/src/screens/photos/VideoPlayer.tsx b/src/screens/photos/VideoPlayer.tsx
index 8437ab9..60f7feb 100644
--- a/src/screens/photos/VideoPlayer.tsx
+++ b/src/screens/photos/VideoPlayer.tsx
@@ -141,6 +141,8 @@ export function VideoPlayer({
const key = (e: KeyboardEvent) => {
if (!live.current) return;
if (e.key !== " " || (e.target as HTMLElement | null)?.closest?.("input, textarea, [contenteditable]")) return;
+ // A slideshow over the viewer has Space for itself (Slideshow.tsx).
+ if (document.querySelector(".px-show")) return;
e.preventDefault();
e.stopPropagation();
toggle();