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: no flash as a photo closes, no light band as the window resizes
Yashwanth Kamireddidabf057f1a6d
diff --git a/.uiverify/photos-close.mjs b/.uiverify/photos-close.mjsnew file mode 100644index 0000000..2792a1e--- /dev/null+++ b/.uiverify/photos-close.mjs@@ -0,0 +1,66 @@+// Closing a photo never flashes it: frame by frame the photo only shrinks back into its tile,+// and no frame after it arrives shows it larger again before the viewer is gone. (WebKit drew+// the photo at full size for one frame as the animation ended — a whole-window flash.)+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++; };++for (const round of [1, 2]) {+ await page.locator(".px-tile").nth(round).dblclick();+ await page.waitForTimeout(700);+ const trace = await page.evaluate(() => new Promise((resolve) => {+ const frames = [];+ const tick = () => {+ const v = document.querySelector(".px-viewer");+ const p = document.querySelector(".px-pan, .px-video");+ if (!v || !p) { frames.push(null); return resolve(frames); }+ const shown = getComputedStyle(v).visibility !== "hidden";+ frames.push(shown ? Math.round(p.getBoundingClientRect().width) : 0);+ if (frames.length < 120) requestAnimationFrame(tick); else resolve(frames);+ };+ window.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));+ requestAnimationFrame(tick);+ }));+ const seen = trace.filter((w) => w !== null && w > 0);+ const grew = seen.some((w, i) => i > 0 && w > seen[i - 1] + 1);+ ok(!grew && trace.at(-1) === null, `close ${round}: the photo only shrinks, then the viewer is gone — no frame drawn larger ${JSON.stringify(seen)}`);+ await page.waitForTimeout(300);+}+// The window's own colour follows what fills its edges, so a resize shows no lighter band.+const rgb = (sel) => page.evaluate((s) => /(\d+), (\d+), (\d+)/.exec(getComputedStyle(document.querySelector(s)).backgroundColor).slice(1).join(","), sel);+const body = await rgb("body");+ok((await page.evaluate(() => window.__tints?.at(-1))) === body, `the window is the app's colour ${body}`);+await page.locator(".px-tile").nth(1).dblclick();+await page.waitForTimeout(600);+const backdrop = await rgb(".px-backdrop");+ok((await page.evaluate(() => window.__tints.at(-1))) === backdrop, `the viewer's own colour while a photo is open ${backdrop}`);+await page.keyboard.press("Escape");+await page.waitForTimeout(600);+ok((await page.evaluate(() => window.__tints.at(-1))) === body, "and the app's colour again once it closes");++// Opened again at once after a close: shown, not left hidden.+await page.locator(".px-tile").nth(1).dblclick();+await page.waitForTimeout(600);+ok(await page.locator(".px-viewer").evaluate((v) => getComputedStyle(v).visibility === "visible" && getComputedStyle(v.querySelector(".px-backdrop")).opacity === "1"), "a photo opened again is fully shown");+// In dark, the viewer's near-black: the band a resize shows is never lighter than the photo's surround.+const dark = await b.newContext({ viewport: { width: 1280, height: 800 }, colorScheme: "dark" });+await dark.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null });+const dp = await dark.newPage();+await dp.goto("http://localhost:4173", { waitUntil: "networkidle" });+await openScreen(dp, "Photos");+await dp.waitForTimeout(400);+await dp.locator(".px-tile").nth(1).dblclick();+await dp.waitForTimeout(600);+const tint = await dp.evaluate(() => window.__tints.at(-1));+ok(tint.split(",").every((v) => Number(v) < 20), `in dark, the window goes near-black with the viewer ${tint}`);+await b.close();+process.exitCode = failures ? 1 : (process.exitCode ?? 0);diff --git a/.uiverify/stub.mjs b/.uiverify/stub.mjsindex 6d1ea6f..d54d8c2 100644--- a/.uiverify/stub.mjs+++ b/.uiverify/stub.mjs@@ -429,6 +429,7 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note}case "photo_play": (window.__plays ??= []).push(args); return null;case "video_base": return window.__videoBase ?? null;+ case "window_tint": (window.__tints ??= []).push(args.rgb.join(",")); return null;case "photo_download": (window.__downloads ??= []).push(args); return `/home/test/Downloads/IMG_${args.id}.JPG`;// Each file is answered at once with where it stands; a test plays the rest in with __emit.case "photos_upload": {diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rsindex ab88ea6..daf9723 100644--- a/src-tauri/src/main.rs+++ b/src-tauri/src/main.rs@@ -3488,6 +3488,15 @@ fn smooth_video() {}}+/// The window's own colour, set to what the page paints at its edges (see src/lib/tint.ts):+/// what shows for the frames a resize runs ahead of the page.+#[tauri::command]+fn window_tint(window: tauri::WebviewWindow, rgb: [u8; 3]) -> UiResult<()> {+ window+ .set_background_color(Some(tauri::window::Color(rgb[0], rgb[1], rgb[2], 255)))+ .map_err(|e| e.to_string())+}+/// Whether this session runs under a tiling Wayland compositor, which manages windows itself.fn tiling_compositor() -> bool {let set = |k: &str| std::env::var_os(k).is_some_and(|v| !v.is_empty());@@ -3808,6 +3817,7 @@ fn main() {photos::photo_play,photos::photos_set_flag,video::video_base,+ window_tint,photos::photos_upload,photos::photos_upload_cancel,photos::photos_album_create,diff --git a/src/lib/tint.ts b/src/lib/tint.tsnew file mode 100644index 0000000..48765b2--- /dev/null+++ b/src/lib/tint.ts@@ -0,0 +1,30 @@+/**+ * The window's own colour, kept the colour of what fills its edges. A window being resized is+ * drawn larger by the system a few frames before the page is drawn at its new size, and what+ * shows in between is the window's colour: left to the toolkit's grey, that was a light band+ * flashing beside the near-black photo viewer — the flicker on every resize.+ */+import { invoke } from "@tauri-apps/api/core";++let last = "";++/** Tint the window the background colour `el` is painted. */+export function tintFrom(el: Element | null) {+ if (!el) return;+ const m = /rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(getComputedStyle(el).backgroundColor);+ if (!m) return;+ const key = `${m[1]},${m[2]},${m[3]}`;+ if (key === last) return;+ last = key;+ invoke("window_tint", { rgb: [Number(m[1]), Number(m[2]), Number(m[3])] }).catch(() => {+ last = "";+ });+}++/** The app's own background, at start and whenever the appearance changes. */+export function keepTinted() {+ const now = () => tintFrom(document.body);+ now();+ window.matchMedia?.("(prefers-color-scheme: dark)").addEventListener?.("change", now);+ new MutationObserver(now).observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme", "class", "style"] });+}diff --git a/src/main.tsx b/src/main.tsxindex 5310445..e677fe7 100644--- a/src/main.tsx+++ b/src/main.tsx@@ -8,9 +8,11 @@ import "./styles/calendar.css";import "./styles/notes.css";import "./styles/photos.css";import { applyTheme, storedTheme } from "./lib/theme";+import { keepTinted } from "./lib/tint";// Before the first paint, so the window opens in the appearance chosen.applyTheme(storedTheme());+keepTinted();/** Every link goes the one way out: as a navigation, which the window refuses and hands todiff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsxindex 6faa5bb..df32413 100644--- a/src/screens/PhotosView.tsx+++ b/src/screens/PhotosView.tsx@@ -25,6 +25,7 @@ import { RowMenu, type MenuEntry } from "../components/RowMenu";import { Portal } from "../components/Portal";import { Slideshow } from "./photos/Slideshow";import { useAsk } from "./photos/Ask";+import { tintFrom } from "../lib/tint";import { DownloadOptions, type Want } from "./photos/DownloadOptions";import { AdjustDate } from "./photos/AdjustDate";@@ -603,6 +604,8 @@ export function PhotosView() {const from = origin.current;origin.current = null;const el = viewer.current;+ // A viewer hidden as its last close ended, opened again before it went: shown again.+ if (el) el.style.visibility = "";if (!from || !el || still() || typeof el.animate !== "function") return;// The photo's whole frame moves — the screen-sized picture and the whole one over it// together. Moving the one alone, the whole one (already on disk) stood full size over@@ -610,11 +613,19 @@ export function PhotosView() {const img = el.querySelector<HTMLElement>(".px-pan, .px-video");const t = img && toTile(img, from);if (img && t) img.animate([{ transform: t }, { transform: "none" }], { duration: 460, easing: spring() });- for (const part of el.querySelectorAll<HTMLElement>(".px-backdrop, .px-viewer-bar, .px-nav, .px-info")) {+ for (const part of el.querySelectorAll<HTMLElement>(".px-backdrop, .px-viewer-bar, .px-nav, .px-info, .px-strip")) {part.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 160, easing: "ease-out" });}}, [open !== null]); // eslint-disable-line react-hooks/exhaustive-deps+ // The window takes the viewer's near-black while it is open, and the app's colour again+ // after: a resize then never shows a lighter band beside the photo.+ useLayoutEffect(() => {+ if (open === null) return undefined;+ tintFrom(viewer.current?.querySelector(".px-backdrop") ?? null);+ return () => tintFrom(document.body);+ }, [open !== null]); // eslint-disable-line react-hooks/exhaustive-deps+const close = useCallback(() => {const el = viewer.current;const current = open !== null ? photos?.[open] : null;@@ -630,13 +641,27 @@ export function PhotosView() {}closing.current = true;const done = () => {- if (!closingRun.current) return;+ const run = closingRun.current;+ if (!run) return;closingRun.current = null;closing.current = false;+ // Hidden in the same moment the animations end, with their last frame kept as real+ // styles: an ended animation let WebKit draw the photo at full size for one frame+ // before the viewer went — a whole-window flash on every close.+ if (el) {+ for (const a of run.anims) {+ try {+ a.commitStyles();+ } catch {+ // An element already gone has nothing to keep.+ }+ }+ el.style.visibility = "hidden";+ }setOpen(null);};const t = seen && img ? toTile(img, box) : null;- const parts = [...el.querySelectorAll<HTMLElement>(".px-backdrop, .px-viewer-bar, .px-nav, .px-info")];+ const parts = [...el.querySelectorAll<HTMLElement>(".px-backdrop, .px-viewer-bar, .px-nav, .px-info, .px-strip")];const anims = parts.map((part) => part.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 140, easing: "ease-in", fill: "forwards" }));const last = t && img? img.animate([{ transform: "none" }, { transform: t }], { duration: 340, easing: spring(), fill: "forwards" })