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: the Hidden album is locked until asked for, as in Photos

Yashwanth Kamireddi29603712b8ed
diff --git a/.uiverify/photos-hidden-lock.mjs b/.uiverify/photos-hidden-lock.mjs
new file mode 100644
index 0000000..3e93fa3
--- /dev/null
+++ b/.uiverify/photos-hidden-lock.mjs
@@ -0,0 +1,97 @@
+// The Hidden album is locked, as in Photos on a Mac and an iPhone: opened, it shows that it is
+// locked and one button to view it — nothing of it read, no tiles, no count. Viewed, it locks
+// again when it is left, when Photos or the window goes out of sight, and at every start; a
+// hidden photo open in the viewer closes as it locks.
+//
+// URL=http://localhost:4173 ENGINE=webkit node .uiverify/photos-hidden-lock.mjs
+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, notesFixture: true });
+await ctx.addInitScript(() => { window.__photoExtra = { p2: { hidden: true } }; });
+const page = await ctx.newPage();
+page.on("pageerror", (e) => { console.log(`FAIL page error: ${e.message}`); process.exitCode = 1; });
+await page.goto(process.env.URL ?? "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 hiddenRow = page.locator(".px-source", { hasText: "Hidden" });
+const lockedPanel = page.locator(".px-locked");
+const view = page.getByRole("button", { name: "View Hidden Photos" });
+const tiles = () => page.locator(".px-tile").evaluateAll((t) => t.map((x) => x.dataset.id));
+const hiddenReads = () => page.evaluate(() => (window.__indexReads ?? []).filter((s) => s.view === "hidden").length);
+const isLocked = async () => (await lockedPanel.count()) === 1 && (await view.count()) === 1 && !(await tiles()).includes("p2");
+const openHidden = async () => { await hiddenRow.click(); await page.waitForTimeout(250); };
+const unlock = async () => { await view.click(); await page.locator('.px-tile[data-id="p2"]').waitFor({ timeout: 3000 }); };
+const goAway = () => page.evaluate(() => {
+ Object.defineProperty(document, "hidden", { value: true, configurable: true });
+ Object.defineProperty(document, "visibilityState", { value: "hidden", configurable: true });
+ document.dispatchEvent(new Event("visibilitychange"));
+});
+const comeBack = () => page.evaluate(() => {
+ Object.defineProperty(document, "hidden", { value: false, configurable: true });
+ Object.defineProperty(document, "visibilityState", { value: "visible", configurable: true });
+ document.dispatchEvent(new Event("visibilitychange"));
+});
+
+ok(!(await tiles()).includes("p2"), "a hidden photo is not in the library");
+ok(await hiddenRow.locator(".px-count").count() === 0, "Hidden shows no count while it is locked");
+
+// Opened: locked, and nothing of it read.
+await openHidden();
+ok(await isLocked(), "Hidden opens locked, with one button to view it");
+ok(/locked/i.test(await lockedPanel.innerText()), `saying so (${(await lockedPanel.innerText()).replace(/\s+/g, " ")})`);
+ok(await hiddenReads() === 0, "and nothing of it is read while it is locked");
+
+// Viewed.
+await unlock();
+ok((await tiles()).includes("p2") && await lockedPanel.count() === 0, "View Hidden Photos shows them");
+ok(await hiddenRow.locator(".px-count").count() === 1, "with the count beside Hidden");
+
+// Left, and back: locked again.
+await page.locator(".px-source", { hasText: "Library" }).first().click();
+await page.waitForTimeout(250);
+await openHidden();
+ok(await isLocked(), "leaving the album locks it again");
+
+// The window out of sight (minimised, closed to the tray): locked again.
+await unlock();
+await goAway();
+await page.waitForTimeout(250);
+await comeBack();
+await page.waitForTimeout(250);
+ok(await isLocked(), "the window going out of sight locks it again");
+
+// Another screen in front, and back to Photos: locked again.
+await unlock();
+await openScreen(page, "Notes");
+await page.waitForTimeout(300);
+await openScreen(page, "Photos");
+await page.waitForTimeout(300);
+await openHidden();
+ok(await isLocked(), "another screen in front locks it again");
+
+// A hidden photo open in the viewer closes as it locks.
+await unlock();
+await page.locator('.px-tile[data-id="p2"]').dblclick();
+await page.locator(".px-viewer").waitFor({ timeout: 3000 });
+await goAway();
+await page.waitForTimeout(400);
+ok(await page.locator(".px-viewer").count() === 0, "a hidden photo open in the viewer closes as it locks");
+await comeBack();
+await page.waitForTimeout(200);
+ok(await isLocked(), "…and the album is locked behind it");
+
+// A new start: locked.
+await unlock();
+await page.reload({ waitUntil: "networkidle" });
+await openScreen(page, "Photos");
+await page.locator(".px-tile").first().waitFor();
+await openHidden();
+ok(await isLocked(), "it is locked again at every start");
+
+await b.close();
+process.exitCode = failures ? 1 : (process.exitCode ?? 0);
diff --git a/.uiverify/photos.mjs b/.uiverify/photos.mjs
index f5c993f..aac1b5c 100644
--- a/.uiverify/photos.mjs
+++ b/.uiverify/photos.mjs
@@ -172,6 +172,8 @@ await page.locator(".confirm .confirm-answer").click();
await page.waitForTimeout(300);
ok((await page.locator(".px-tile").count()) === 4, "Hide Photo takes it out of the library at once");
await page.locator(".px-source", { hasText: "Hidden" }).click();
+// Locked, as Photos keeps Hidden (photos-hidden-lock.mjs): viewed first.
+await page.getByRole("button", { name: "View Hidden Photos" }).click();
await page.waitForTimeout(250);
ok((await page.locator(".px-tile").count()) === 1, "and it is in Hidden");
await page.locator(".px-tile").first().click();
diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsx
index e0b2a08..99c7f28 100644
--- a/src/screens/PhotosView.tsx
+++ b/src/screens/PhotosView.tsx
@@ -8,7 +8,7 @@ import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useStat
import { listen } from "@tauri-apps/api/event";
import { getCurrentWebview } from "@tauri-apps/api/webview";
import { pickOpen } from "../lib/pick";
-import { ChevronLeft, ChevronRight, Ellipsis, GalleryThumbnails, CopyMinus, CopyPlus, Download, Clock, Heart, ImagePlus, Images, Info, Minus, Play, Plus, RotateCcw, Scan, Trash2, EyeOff, ArrowDownUp, MonitorPlay, Square, RectangleHorizontal, Star, Layers, SquareStack, Folder as FolderIcon, Aperture, Video, X, CalendarDays, Maximize2, Minimize2, Users, type LucideIcon } from "lucide-react";
+import { ChevronLeft, ChevronRight, Ellipsis, GalleryThumbnails, CopyMinus, CopyPlus, Download, Clock, Heart, ImagePlus, Images, Info, Minus, Play, Plus, RotateCcw, Scan, Trash2, EyeOff, Lock, ArrowDownUp, MonitorPlay, Square, RectangleHorizontal, Star, Layers, SquareStack, Folder as FolderIcon, Aperture, Video, X, CalendarDays, Maximize2, Minimize2, Users, type LucideIcon } from "lucide-react";
import {
api,
messageOf,
@@ -900,6 +900,12 @@ export function PhotosView() {
const place: PhotoView = drawn.query ? "library" : view;
const inAlbum = drawn.query ? null : album;
const [sorts, setSorts] = useState(readSorts);
+ /**
+ * The Hidden album is locked, as in Photos: shown only once asked for, and locked again when
+ * it is left, when this screen or the window goes out of sight, and at every start (kept in
+ * memory only).
+ */
+ const [hiddenOpen, setHiddenOpen] = useState(false);
const sortable = !drawn.query && !drawn.album && drawn.view !== "recentlyDeleted" && drawn.view !== "rated";
const sort = sortable ? (sorts[drawn.view] ?? defaultSort(drawn.view)) : null;
const chooseSort = (next: Sort) => {
@@ -945,6 +951,12 @@ export function PhotosView() {
const read = useCallback(async () => {
if (burstOpen.current) return;
const mine = ++reads.current;
+ // Hidden, locked: nothing of it is read, so nothing of it can be drawn.
+ if (view === "hidden" && !album && !searching && !hiddenOpen) {
+ setPhotos(new PhotoList({ ids: [], keys: [], marks: [], first: null, last: null }, store));
+ setDrawn({ view, album, query: searching });
+ return;
+ }
const source: PhotoSource = searching ? { query: searching } : album ? { album: album.id } : { view };
const order: PhotoOrder | null = want;
const d = drawnNow.current;
@@ -1017,11 +1029,27 @@ export function PhotosView() {
setAlbums((was) => (same(was, a) ? was : a));
// An album deleted elsewhere is not left open, empty.
if (album && !a.some(([x]) => x.id === album.id)) setAlbum(null);
- }, [view, album, searching, want?.by, want?.oldest]); // eslint-disable-line react-hooks/exhaustive-deps
+ }, [view, album, searching, want?.by, want?.oldest, hiddenOpen]); // eslint-disable-line react-hooks/exhaustive-deps
// A pass that lands while another screen is in front is read when this one comes back, once,
// not at every landing: a screen out of sight is still mounted (lib/screen), and each pass
// lands a service at a time.
const active = useScreenActive();
+ const hiddenLocked = view === "hidden" && !album && !searching && !hiddenOpen;
+ // Locked again once it is left — another place, an album, a search, another screen — and
+ // whenever the window goes out of sight (minimised, closed to the tray, another workspace).
+ const inHidden = view === "hidden" && !album && !searching && !albumsPage && !sharedPage && active;
+ useEffect(() => {
+ if (!inHidden) setHiddenOpen(false);
+ }, [inHidden]);
+ useEffect(() => {
+ const away = () => document.hidden && setHiddenOpen(false);
+ document.addEventListener("visibilitychange", away);
+ return () => document.removeEventListener("visibilitychange", away);
+ }, []);
+ // A hidden photo open when it locks closes with it.
+ useEffect(() => {
+ if (hiddenLocked) setOpen(null);
+ }, [hiddenLocked]);
const seen = useRef(revision);
if (active) seen.current = revision;
const due = seen.current;
@@ -2989,10 +3017,11 @@ export function PhotosView() {
const t = window.setTimeout(() => {
const box = stageBox.w ? stageBox : { w: Math.max(320, window.innerWidth - 400), h: Math.max(240, window.innerHeight - 140) };
// The view on screen has its pictures made first (Hidden is not in the library's).
- api.photosPrepare({ cell, fit, stageW: box.w, stageH: box.h, dpr, view }).catch(() => {});
+ // Hidden, locked, has none made: the library's are.
+ api.photosPrepare({ cell, fit, stageW: box.w, stageH: box.h, dpr, view: hiddenLocked ? "library" : view }).catch(() => {});
}, 400);
return () => window.clearTimeout(t);
- }, [cell, fit, open !== null, view, dpr]); // eslint-disable-line react-hooks/exhaustive-deps
+ }, [cell, fit, open !== null, view, dpr, hiddenLocked]); // eslint-disable-line react-hooks/exhaustive-deps
// A new album or folder, at the top or in a folder: named in place in the sidebar.
const startNew = (parent: string | null, folder: boolean) => {
@@ -3134,7 +3163,7 @@ export function PhotosView() {
>
<v.Icon className="px-glyph" size={16} strokeWidth={1.8} aria-hidden="true" />
<span className="source-name px-label">{v.label}</span>
- {counts[v.key] ? <span className="count px-count">{counts[v.key]}</span> : null}
+ {counts[v.key] && !(v.key === "hidden" && !hiddenOpen) ? <span className="count px-count">{counts[v.key]}</span> : null}
</button>
);
@@ -3484,10 +3513,19 @@ export function PhotosView() {
</header>
- {photos && photos.length === 0 && !drawn.query && (
+ {hiddenLocked && (
+ <EmptyState
+ className="px-empty px-locked"
+ icon={<Lock size={28} strokeWidth={1.6} />}
+ action={{ label: "View Hidden Photos", run: () => setHiddenOpen(true) }}
+ >
+ The Hidden album is locked.
+ </EmptyState>
+ )}
+ {!hiddenLocked && photos && photos.length === 0 && !drawn.query && (
<Arriving service="photos" what="photos" className="px-empty" />
)}
- {photos && photos.length === 0 && !(arriving && !drawn.query) && (
+ {!hiddenLocked && photos && photos.length === 0 && !(arriving && !drawn.query) && (
// One line, saying what the place is for, with its own symbol from the sidebar.
<EmptyState
className="px-empty"