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: slideshow
Yashwanth Kamireddicd1384e9c0e9
diff --git a/.uiverify/photos-show.mjs b/.uiverify/photos-show.mjsnew file mode 100644index 0000000..a1a644d--- /dev/null+++ b/.uiverify/photos-show.mjs@@ -0,0 +1,52 @@+// A slideshow, as Photos plays one: started from a photo it begins there and goes on by+// itself; from a selection it shows just those; Space pauses, the arrows step, Escape ends+// it and leaves the screen as it was.+import { engine } from "./engine.mjs";+import { SERVICES, installStub, openScreen } 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 });+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" });+await openScreen(page, "Photos");+await page.waitForTimeout(400);+let failures = 0;+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };+const count = () => page.locator(".px-show-count").innerText();++await page.locator(".px-tile").nth(1).click({ button: "right" });+await page.locator(".row-menu").getByText("Start Slideshow").click();+await page.waitForTimeout(200);+ok((await page.locator(".px-show").count()) === 1 && (await count()) === "2 of 5", `it begins at the photo it was started from "${await count()}"`);+await page.waitForTimeout(4400);+ok((await count()) === "3 of 5", `and goes on by itself "${await count()}"`);+await page.keyboard.press(" ");+await page.waitForTimeout(4400);+ok((await count()) === "3 of 5" && (await page.getByRole("button", { name: "Play" }).count()) === 1, "Space pauses it");+await page.keyboard.press("ArrowRight");+ok((await count()) === "4 of 5", "the right arrow steps on");+await page.keyboard.press("ArrowLeft");+await page.keyboard.press("ArrowLeft");+ok((await count()) === "2 of 5", "and the left back");+await page.keyboard.press("Escape");+await page.waitForTimeout(200);+ok((await page.locator(".px-show").count()) === 0 && (await page.locator(".px-tile").count()) === 5, "Escape ends it, the library as it was");++await page.locator(".px-tile").nth(0).click();+await page.locator(".px-tile").nth(3).click({ modifiers: ["Control"] });+await page.locator(".px-tile").nth(3).click({ button: "right" });+await page.locator(".row-menu").getByText("Start Slideshow").click();+await page.waitForTimeout(200);+ok(/of 2$/.test(await count()), `from a selection it shows just those "${await count()}"`);+await page.keyboard.press("Escape");+await page.locator(".px-tile").nth(2).dblclick();+await page.waitForTimeout(600);+await page.getByRole("button", { name: "Start Slideshow" }).click();+await page.waitForTimeout(200);+ok((await page.locator(".px-show").count()) === 1, "the viewer starts one too");+await page.keyboard.press("Escape");+await page.waitForTimeout(200);+ok((await page.locator(".px-viewer").count()) === 1, "and Escape ends the slideshow, not the photo behind it");+await b.close();+process.exitCode = failures ? 1 : (process.exitCode ?? 0);diff --git a/check.sh b/check.shindex d25406e..b039ba7 100755--- a/check.sh+++ b/check.sh@@ -60,6 +60,7 @@ step "photos at scale" node .uiverify/photos-scale.mjsstep "photos drag" node .uiverify/photos-drag.mjsstep "photos keys" node .uiverify/photos-keys.mjsstep "photos sort" node .uiverify/photos-sort.mjs+step "slideshow" node .uiverify/photos-show.mjsstep "notes delete" node .uiverify/notes-delete.mjsstep "empty today" node .uiverify/reminders-empty.mjsstep "calendar keys" node .uiverify/calendar-keys.mjs@@ -103,6 +104,7 @@ step "webkit: at scale" env ENGINE=webkit node .uiverify/photos-scale.mjsstep "webkit: drag" env ENGINE=webkit node .uiverify/photos-drag.mjsstep "webkit: keys" env ENGINE=webkit node .uiverify/photos-keys.mjsstep "webkit: sort" env ENGINE=webkit node .uiverify/photos-sort.mjs+step "webkit: slideshow" env ENGINE=webkit node .uiverify/photos-show.mjsstep "webkit: delete" env ENGINE=webkit node .uiverify/notes-delete.mjsstep "webkit: row hover" env ENGINE=webkit node .uiverify/row-hover.mjsstep "webkit: fold" env ENGINE=webkit node .uiverify/sidebar-fold.mjsdiff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsxindex 67b3431..da45291 100644--- a/src/screens/PhotosView.tsx+++ b/src/screens/PhotosView.tsx@@ -7,7 +7,7 @@ import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useStatimport { listen } from "@tauri-apps/api/event";import { getCurrentWebview } from "@tauri-apps/api/webview";import { open as openFileDialog } from "@tauri-apps/plugin-dialog";-import { ChevronLeft, ChevronRight, CopyMinus, CopyPlus, Download, Clock, Heart, ImagePlus, Images, Info, Minus, Play, Plus, RotateCcw, Scan, Trash2, EyeOff, ArrowDownUp, Video, X, type LucideIcon } from "lucide-react";+import { ChevronLeft, ChevronRight, CopyMinus, CopyPlus, Download, Clock, Heart, ImagePlus, Images, Info, Minus, Play, Plus, RotateCcw, Scan, Trash2, EyeOff, ArrowDownUp, MonitorPlay, Video, X, type LucideIcon } from "lucide-react";import {api,messageOf,@@ -22,6 +22,7 @@ import { useSync } from "../lib/sync";import { Notice } from "../components/Notice";import { UploadTray } from "../components/UploadTray";import { RowMenu, type MenuEntry } from "../components/RowMenu";+import { Slideshow } from "./photos/Slideshow";/** The sidebar, in Photos' order, each with the symbol Photos gives it. */const VIEWS: { key: PhotoView; label: string; Icon: LucideIcon }[] = [@@ -245,6 +246,8 @@ export function PhotosView() {const [open, setOpen] = useState<number | null>(null);const [info, setInfo] = useState(false);const [saved, setSaved] = useState<string | null>(null);+ /** A slideshow playing: what it shows, and where it begins. */+ const [show, setShow] = useState<{ list: Photo[]; start: number } | null>(null);/** Photos selected in the grid, as on a Mac: a click selects, a double-click opens. */const [chosen, setChosen] = useState<Set<string>>(new Set());const anchor = useRef<number | null>(null);@@ -809,6 +812,14 @@ export function PhotosView() {return () => window.removeEventListener("keydown", onKey);});+ // A slideshow of what is selected when that is more than one photo, else of the whole view+ // from this photo on, as Photos starts one.+ const startShow = (from: Photo) => {+ const list = selected.length > 1 && chosen.has(from.id) ? selected : (photos ?? []);+ setMenu(null);+ setShow({ list, start: Math.max(0, list.findIndex((p) => p.id === from.id)) });+ };+const albumEntries = (ids: string[]): MenuEntry[] => [...albums.filter(([a]) => a.id !== album?.id && !a.id.startsWith("new:")).map(([a]) => ({ label: a.name, run: () => void addTo(a, ids) })),...(albums.length ? [null] : []),@@ -838,6 +849,7 @@ export function PhotosView() {: [{ label: anyPlain ? "Favorite" : "Unfavorite", run: () => void changeAll(group, "favorite", anyPlain) },null,+ { label: "Start Slideshow", run: () => startShow(p) },{ label: "Add to Album", submenu: albumEntries(group.map((x) => x.id)) },null,view === "hidden" && !album@@ -860,6 +872,7 @@ export function PhotosView() {: [{ label: p.favorite ? "Unfavorite" : "Favorite", run: () => void change(p, "favorite", !p.favorite) },{ label: "Download", run: () => void download(p) },+ { label: "Start Slideshow", run: () => startShow(p) },null,{ label: "Add to Album", submenu: albumEntries([p.id]) },null,@@ -1391,6 +1404,9 @@ export function PhotosView() {)}</div><div className="px-capsule">+ <button className="px-cap" aria-label="Start Slideshow" title="Start Slideshow" onClick={() => startShow(shown)}>+ <MonitorPlay size={17} />+ </button><button className="px-cap" aria-label="Download" title="Download the original" onClick={() => void download(shown)}><Download size={17} /></button>@@ -1486,6 +1502,7 @@ export function PhotosView() {</p>)}{menu && <RowMenu at={menu.at} entries={menu.entries} onClose={() => setMenu(null)} />}+ {show && <Slideshow photos={show.list} start={show.start} onClose={() => setShow(null)} />}<UploadTray uploads={[...uploads.values()]} onDismiss={dismissUploads} cancel={api.photosUploadCancel} /></div>);diff --git a/src/screens/photos/Slideshow.tsx b/src/screens/photos/Slideshow.tsxnew file mode 100644index 0000000..d4818e7--- /dev/null+++ b/src/screens/photos/Slideshow.tsx@@ -0,0 +1,114 @@+/**+ * A slideshow, as Photos plays one: the photos one after another on black, each easing slowly+ * larger while it shows and fading into the next. Space pauses, the arrows step, Escape ends.+ * The controls sit in a glass capsule that fades away while the pointer is still.+ *+ * Only opacity and transform move — the compositor's work — and the next picture is fetched+ * while the one before it shows, so a change never waits on a download.+ */+import { useCallback, useEffect, useRef, useState } from "react";+import { ChevronLeft, ChevronRight, Pause, Play, X } from "lucide-react";+import { pictureSrc, type Photo } from "../../lib/ipc";++const HOLD = 4000;+const FADE = 900;++export function Slideshow({ photos, start, onClose }: { photos: Photo[]; start: number; onClose: () => void }) {+ const [at, setAt] = useState(Math.max(0, Math.min(start, photos.length - 1)));+ const [playing, setPlaying] = useState(true);+ const [awake, setAwake] = useState(true);+ const still = typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;+ const go = useCallback((by: number) => setAt((i) => (i + by + photos.length) % photos.length), [photos.length]);++ // On, one after another; round again at the end, as Photos loops a slideshow.+ useEffect(() => {+ if (!playing || photos.length < 2) return undefined;+ const t = window.setTimeout(() => go(1), HOLD);+ return () => window.clearTimeout(t);+ }, [at, playing, go, photos.length]);++ // The next picture is fetched now, so it is there when its turn comes.+ useEffect(() => {+ const next = photos[(at + 1) % photos.length];+ if (next) new Image().src = pictureSrc(next.id, "medium");+ }, [at, photos]);++ useEffect(() => {+ const onKey = (e: KeyboardEvent) => {+ if (e.key === "Escape") onClose();+ else if (e.key === " ") setPlaying((p) => !p);+ else if (e.key === "ArrowRight") go(1);+ else if (e.key === "ArrowLeft") go(-1);+ else return;+ e.preventDefault();+ e.stopPropagation();+ };+ // Before the screen's own keys, which would otherwise step the photo behind or close it.+ window.addEventListener("keydown", onKey, true);+ return () => window.removeEventListener("keydown", onKey, true);+ }, [go, onClose]);++ // The controls show when the pointer moves and go once it rests.+ const idle = useRef<number | null>(null);+ const wake = () => {+ setAwake(true);+ if (idle.current !== null) window.clearTimeout(idle.current);+ idle.current = window.setTimeout(() => setAwake(false), 2200);+ };+ useEffect(() => {+ wake();+ return () => {+ if (idle.current !== null) window.clearTimeout(idle.current);+ };+ }, []); // eslint-disable-line react-hooks/exhaustive-deps++ // The one showing and the one before it, so the old fades out over the new.+ const [before, setBefore] = useState<number | null>(null);+ const shown = useRef(at);+ useEffect(() => {+ if (shown.current === at) return undefined;+ setBefore(shown.current);+ shown.current = at;+ const t = window.setTimeout(() => setBefore(null), FADE);+ return () => window.clearTimeout(t);+ }, [at]);++ const photo = photos[at];+ if (!photo) return null;+ return (+ <div+ className={`px-show${awake ? " is-awake" : ""}${still ? " is-still" : ""}`}+ role="dialog"+ aria-label="Slideshow"+ onMouseMove={wake}+ onClick={wake}+ >+ {before !== null && photos[before] && (+ <img key={`b${photos[before].id}`} className="px-slide is-leaving" src={pictureSrc(photos[before].id, "medium")} alt="" />+ )}+ <img+ key={`a${photo.id}-${at}`}+ className={`px-slide${playing ? "" : " is-paused"}`}+ src={pictureSrc(photo.id, "medium")}+ alt={photo.filename ?? "Photo"}+ />+ <div className="px-show-bar px-capsule" role="toolbar" aria-label="Slideshow controls">+ <button className="px-cap" aria-label="Previous" onClick={() => go(-1)}>+ <ChevronLeft size={18} />+ </button>+ <button className="px-cap" aria-label={playing ? "Pause" : "Play"} onClick={() => setPlaying((p) => !p)}>+ {playing ? <Pause size={17} fill="currentColor" strokeWidth={0} /> : <Play size={17} fill="currentColor" strokeWidth={0} />}+ </button>+ <button className="px-cap" aria-label="Next" onClick={() => go(1)}>+ <ChevronRight size={18} />+ </button>+ <span className="px-show-count" aria-live="polite">+ {at + 1} of {photos.length}+ </span>+ <button className="px-cap" aria-label="End Slideshow" title="End Slideshow (Esc)" onClick={onClose}>+ <X size={17} />+ </button>+ </div>+ </div>+ );+}diff --git a/src/styles/photos.css b/src/styles/photos.cssindex a5b2e97..f9011a2 100644--- a/src/styles/photos.css+++ b/src/styles/photos.css@@ -404,3 +404,38 @@font: 600 12px/22px system-ui, sans-serif;text-align: center;}++/* ---- slideshow: black, each photo easing larger while it shows and fading into the next --- */+.px-show { position: fixed; inset: 0; z-index: 80; background: #000; color: #fff; overflow: hidden; cursor: none; }+.px-show.is-awake { cursor: default; }+.px-slide {+ position: absolute;+ inset: 0;+ width: 100%;+ height: 100%;+ object-fit: contain;+ transform-origin: 50% 45%;+ animation: px-arrive 900ms ease-out both, px-drift 4900ms linear both;+ will-change: transform, opacity;+}+.px-slide.is-leaving { animation: none; transform: scale(1.06); z-index: -1; }+.px-slide.is-paused { animation-play-state: paused; }+@keyframes px-arrive { from { opacity: 0; } to { opacity: 1; } }+@keyframes px-drift { from { transform: scale(1); } to { transform: scale(1.06); } }+.px-show.is-still .px-slide { animation: none; }+.px-show-bar {+ position: absolute;+ left: 50%;+ bottom: 28px;+ transform: translateX(-50%);+ align-items: center;+ background: rgba(40, 40, 44, 0.62);+ box-shadow: inset 0 0.5px 0 rgba(255, 255, 255, 0.18), 0 10px 30px rgba(0, 0, 0, 0.5);+ color: #fff;+ opacity: 0;+ transition: opacity 260ms ease;+}+.px-show.is-awake .px-show-bar { opacity: 1; }+.px-show-bar .px-cap { color: #fff; }+.px-show-bar .px-cap:hover { background: rgba(255, 255, 255, 0.14); }+.px-show-count { padding: 0 10px; font-size: var(--t-13); font-variant-numeric: tabular-nums; color: rgba(255, 255, 255, 0.75); }