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: Hidden, under Utilities, and Hide / Unhide
Yashwanth Kamireddie8ecda0c73fc
diff --git a/.uiverify/photos-albums.mjs b/.uiverify/photos-albums.mjsindex 6d7eb5d..05c2d72 100644--- a/.uiverify/photos-albums.mjs+++ b/.uiverify/photos-albums.mjs@@ -15,7 +15,7 @@ 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 albumNames = () => page.locator(".px-side .px-source").evaluateAll((els) => els.map((e) => e.querySelector("span")?.textContent ?? "").slice(6));+const albumNames = () => page.locator(".px-albums .px-source").evaluateAll((els) => els.map((e) => e.querySelector(".px-label")?.textContent ?? ""));await page.getByRole("button", { name: "New Album" }).click();await page.getByLabel("Album name").fill("Beach");diff --git a/.uiverify/photos.mjs b/.uiverify/photos.mjsindex 12d2b5d..c2472e5 100644--- a/.uiverify/photos.mjs+++ b/.uiverify/photos.mjs@@ -145,6 +145,24 @@ ok((await page.evaluate(() => window.__flags.length)) - sentBefore === 2 && (awaawait page.locator(".px-scroll").click({ position: { x: 600, y: 600 } });ok((await page.locator('.px-tile[aria-selected="true"]').count()) === 0, "a click on the empty space lets the selection go");+// Hide, as Photos hides: asked, out of the library, into Hidden (under Utilities), and back.+page.once("dialog", (d) => void d.accept());+await page.locator(".px-tile").nth(1).click({ button: "right" });+await page.locator(".row-menu").getByText("Hide Photo").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();+await page.waitForTimeout(250);+ok((await page.locator(".px-tile").count()) === 1, "and it is in Hidden");+await page.locator(".px-tile").first().click();+await page.keyboard.press("Control+l");+await page.waitForTimeout(300);+ok((await page.locator(".px-tile").count()) === 0 && (await page.evaluate(() => window.__flags.at(-1))).flag === "hidden",+ "Ctrl+L in Hidden unhides it");+await page.locator(".px-source", { hasText: "Library" }).click();+await page.waitForTimeout(250);+ok((await page.locator(".px-tile").count()) === 5, "and it is back in the library");+const across = async () => page.locator(".px-grid").first().evaluate((g) => getComputedStyle(g).gridTemplateColumns.split(" ").length);const before = await across();await page.getByRole("button", { name: "Zoom In" }).click();diff --git a/.uiverify/stub.mjs b/.uiverify/stub.mjsindex fbff7dc..2cefc92 100644--- a/.uiverify/stub.mjs+++ b/.uiverify/stub.mjs@@ -319,6 +319,7 @@ export function installStub({ screen, services, twoFactor, calendarFixture, noteconst views = {library: live, recents: live, favorites: live.filter((p) => p.favorite), videos: live.filter((p) => p.kind === "video"),screenshots: live.filter((p) => p.uti === "public.png"), recentlyDeleted: all.filter((p) => p.deleted),+ hidden: all.filter((p) => !p.deleted && p.hidden),};if (cmd === "photos_counts") return Object.entries(views).map(([k, v]) => [k, v.length]);return views[args.view] ?? [];@@ -355,6 +356,7 @@ export function installStub({ screen, services, twoFactor, calendarFixture, noteconst p = (window.__photos ?? []).find((x) => x.id === args.id);if (p) {if (args.flag === "favorite") p.favorite = args.on;+ if (args.flag === "hidden") p.hidden = args.on;if (args.flag === "deleted") { p.deleted = args.on; p.deletedAt = args.on ? 1792700000 : null; }}return p;diff --git a/crates/quince-core/src/photos.rs b/crates/quince-core/src/photos.rsindex 45bde1f..fd5d734 100644--- a/crates/quince-core/src/photos.rs+++ b/crates/quince-core/src/photos.rs@@ -105,6 +105,8 @@ pub enum View {Screenshots,/// Newest added first.Recents,+ /// Hidden from every other view, as Photos' Hidden album.+ Hidden,RecentlyDeleted,}@@ -214,6 +216,7 @@ impl Library {"deleted = 0 AND hidden = 0","COALESCE(added_at, taken_at) DESC",),+ View::Hidden => ("deleted = 0 AND hidden = 1", "taken_at DESC"),View::RecentlyDeleted => ("deleted = 1", "COALESCE(deleted_at, taken_at) DESC"),};let mut stmt = self.conn.prepare(&format!(@@ -240,6 +243,7 @@ impl Library {View::Favorites,View::Videos,View::Screenshots,+ View::Hidden,View::RecentlyDeleted,] {out.push((view, self.photos(view)?.len() as i64));@@ -469,6 +473,11 @@ mod tests {assert_eq!(ids(&lib, View::Favorites), ["b"]);assert_eq!(ids(&lib, View::Videos), ["c"]);assert_eq!(ids(&lib, View::RecentlyDeleted), ["d"]);+ assert_eq!(+ ids(&lib, View::Hidden),+ ["e"],+ "the hidden one, and only there"+ );// An album holds what was put in it, in its order; a deleted photo leaves it.lib.put_photos(&[photo("a", 100)]).unwrap();lib.put_album_items(&[diff --git a/probe/examples/photos_hide_roundtrip.rs b/probe/examples/photos_hide_roundtrip.rsnew file mode 100644index 0000000..ac4d922--- /dev/null+++ b/probe/examples/photos_hide_roundtrip.rs@@ -0,0 +1,64 @@+//! Live, on a wallpaper he named as a throwaway: Hide then Unhide through Quince's own+//! set_flag, each read back from Apple. Leaves the photo as it was.+use anyhow::{anyhow, Result};+use quince_icloud::photos::{self, Flag, CONTAINER, ZONE};++#[tokio::main]+async fn main() -> Result<()> {+ let asset = std::env::args().nth(1).ok_or_else(|| anyhow!("asset id"))?;+ let dir = std::path::PathBuf::from(std::env::var("HOME")?).join(".local/share/quince-probe");+ let mut client = quince_auth::Client::new(&dir)?;+ if !client.resume().await? {+ return Err(anyhow!("no session"));+ }+ let ck = client+ .session()+ .service_url("ckdatabasews")+ .ok_or_else(|| anyhow!("no ck"))?;+ let (http, p) = (client.http().clone(), client.service_params());+ let zc = quince_icloud::cloudkit::ZoneClient::new(&http, &ck, CONTAINER, p.clone());+ let hidden = |r: &serde_json::Value| r.pointer("/fields/isHidden/value").cloned();+ let before = zc+ .lookup_record(ZONE, &asset)+ .await?+ .ok_or_else(|| anyhow!("no such photo"))?;+ println!("before: isHidden={:?}", hidden(&before));+ let tag = before+ .get("recordChangeTag")+ .and_then(|t| t.as_str())+ .map(str::to_string);+ let after = photos::set_flag(+ &http,+ &ck,+ p.clone(),+ &asset,+ tag.as_deref(),+ Flag::Hidden,+ true,+ )+ .await?;+ let now = zc.lookup_record(ZONE, &asset).await?.unwrap();+ println!("hidden: isHidden={:?}", hidden(&now));+ let tag = after+ .get("recordChangeTag")+ .and_then(|t| t.as_str())+ .map(str::to_string)+ .or_else(|| {+ now.get("recordChangeTag")+ .and_then(|t| t.as_str())+ .map(str::to_string)+ });+ photos::set_flag(+ &http,+ &ck,+ p.clone(),+ &asset,+ tag.as_deref(),+ Flag::Hidden,+ false,+ )+ .await?;+ let back = zc.lookup_record(ZONE, &asset).await?.unwrap();+ println!("unhidden: isHidden={:?}", hidden(&back));+ Ok(())+}diff --git a/src/lib/ipc.ts b/src/lib/ipc.tsindex d803fcd..d7351a3 100644--- a/src/lib/ipc.ts+++ b/src/lib/ipc.ts@@ -559,7 +559,7 @@ export function pictureSrc(id: string, size: "thumb" | "medium" | "original" | "export type PhotoAlbum = { id: string; name: string; position: number; changeTag: string | null };-export type PhotoView = "library" | "favorites" | "videos" | "screenshots" | "recents" | "recentlyDeleted";+export type PhotoView = "library" | "favorites" | "videos" | "screenshots" | "recents" | "hidden" | "recentlyDeleted";export type Photo = {id: string;diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsxindex 4d4b97e..b398479 100644--- a/src/screens/PhotosView.tsx+++ b/src/screens/PhotosView.tsx@@ -7,7 +7,7 @@ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } frimport { 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, 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, Video, X, type LucideIcon } from "lucide-react";import {api,messageOf,@@ -30,6 +30,10 @@ const VIEWS: { key: PhotoView; label: string; Icon: LucideIcon }[] = [{ key: "recents", label: "Recents", Icon: Clock },{ key: "videos", label: "Videos", Icon: Video },{ key: "screenshots", label: "Screenshots", Icon: Scan },+];+/** Photos' Utilities: what is kept out of the library. */+const UTILITIES: typeof VIEWS = [+ { key: "hidden", label: "Hidden", Icon: EyeOff },{ key: "recentlyDeleted", label: "Recently Deleted", Icon: Trash2 },];@@ -58,6 +62,8 @@ const pickedWords = (list: Photo[]) => {return `${n.toLocaleString()} ${n === 1 ? noun : `${noun}s`} Selected`;};+type Flag = "favorite" | "deleted" | "hidden";+const clock = (s: number | null) => {if (!s) return "";const m = Math.floor(s / 60);@@ -242,6 +248,7 @@ export function PhotosView() {else if (e.key.toLowerCase() === "i" && !e.metaKey && !e.ctrlKey) setInfo((v) => !v);// As in Photos: "." favorites, Delete sends it to Recently Deleted.else if (e.key === "." && current && view !== "recentlyDeleted") void change(current, "favorite", !current.favorite);+ else if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "l" && current && view !== "recentlyDeleted") void change(current, "hidden", view !== "hidden");else if ((e.key === "Delete" || e.key === "Backspace") && current && album) void removeFrom([current]);else if ((e.key === "Delete" || e.key === "Backspace") && current && view !== "recentlyDeleted") void change(current, "deleted", true);else return;@@ -255,8 +262,8 @@ export function PhotosView() {* Favorite, Delete and Recover show at once, as on the phone; Apple's answer only matters if* it refuses, which puts the photo back as it was and says why.*/- const change = (p: Photo, flag: "favorite" | "deleted", on: boolean) => changeAll([p], flag, on);- const changeAll = async (list: Photo[], flag: "favorite" | "deleted", on: boolean) => {+ const change = (p: Photo, flag: Flag, on: boolean) => changeAll([p], flag, on);+ const changeAll = async (list: Photo[], flag: Flag, on: boolean) => {if (list.length === 0) return;const n = list.length;// Asked first, in icloud.com's words: a delete reaches every device.@@ -268,9 +275,21 @@ export function PhotosView() {) {return;}+ // Hiding asks too, in Photos' words: where the photos go.+ if (+ flag === "hidden" && on &&+ !window.confirm(`${n === 1 ? "Hide this photo?" : `Hide ${n} photos?`}\n\n${n === 1 ? "It" : "They"} will be hidden from your library, and can be found in the Hidden album.`)+ ) {+ return;+ }const before = photos;const ids = new Set(list.map((p) => p.id));- const leaves = flag === "deleted" && (on ? view !== "recentlyDeleted" : view === "recentlyDeleted");+ // Which changes take a photo out of the view it is in.+ const leaves =+ album ? flag !== "favorite" && on+ : flag === "deleted" ? (on ? view !== "recentlyDeleted" : view === "recentlyDeleted")+ : flag === "hidden" ? (on ? view !== "hidden" : view === "hidden")+ : !on && view === "favorites";setPhotos((all) =>leaves? (all ?? []).filter((x) => !ids.has(x.id))@@ -466,6 +485,9 @@ export function PhotosView() {} else if ((e.key === "Delete" || e.key === "Backspace") && selected.length) {if (album) void removeFrom(selected);else if (view !== "recentlyDeleted") void changeAll(selected, "deleted", true);+ } else if (ctrl && e.key.toLowerCase() === "l" && selected.length && view !== "recentlyDeleted") {+ // ⌘L in Photos: hide, or in Hidden, unhide.+ void changeAll(selected, "hidden", view !== "hidden");} else if (e.key === "." && selected.length && view !== "recentlyDeleted") {// As Photos: if any is not a favorite, all become favorites; else all stop being.void changeAll(selected, "favorite", selected.some((p) => !p.favorite));@@ -503,6 +525,9 @@ export function PhotosView() {null,{ label: "Add to Album", submenu: albumEntries(group.map((x) => x.id)) },null,+ view === "hidden" && !album+ ? { label: `Unhide ${n} Photos`, run: () => void changeAll(group, "hidden", false) }+ : { label: `Hide ${n} Photos`, run: () => void changeAll(group, "hidden", true) },album? { label: `Remove ${n} Photos from Album`, danger: true, run: () => void removeFrom(group) }: { label: `Delete ${n} Photos`, danger: true, run: () => void changeAll(group, "deleted", true) },@@ -519,6 +544,9 @@ export function PhotosView() {null,{ label: "Add to Album", submenu: albumEntries([p.id]) },null,+ view === "hidden" && !album+ ? { label: "Unhide Photo", run: () => void change(p, "hidden", false) }+ : { label: "Hide Photo", run: () => void change(p, "hidden", true) },album? { label: "Remove from Album", danger: true, run: () => void removeFrom([p]) }: { label: "Delete", danger: true, run: () => void change(p, "deleted", true) },@@ -725,32 +753,35 @@ export function PhotosView() {const title = album?.name ?? VIEWS.find((v) => v.key === view)?.label ?? "Photos";const across = ACROSS[zoom];+ const source = (v: (typeof VIEWS)[number]) => (+ <button+ key={v.key}+ className="px-source"+ aria-current={!album && view === v.key}+ onClick={() => {+ setView(v.key);+ setAlbum(null);+ setOpen(null);+ }}+ >+ <v.Icon className="px-glyph" size={16} strokeWidth={1.8} aria-hidden="true" />+ <span className="px-label">{v.label}</span>+ {counts[v.key] ? <span className="px-count">{counts[v.key]}</span> : null}+ </button>+ );+return (<div className={`px${dropping ? " is-dropping" : ""}`}><aside className="px-side" aria-label="Photos"><p className="px-side-heading">Photos</p>- {VIEWS.map((v) => (- <button- key={v.key}- className="px-source"- aria-current={!album && view === v.key}- onClick={() => {- setView(v.key);- setAlbum(null);- setOpen(null);- }}- >- <v.Icon className="px-glyph" size={16} strokeWidth={1.8} aria-hidden="true" />- <span className="px-label">{v.label}</span>- {counts[v.key] ? <span className="px-count">{counts[v.key]}</span> : null}- </button>- ))}+ {VIEWS.map(source)}<div className="px-side-row"><p className="px-side-heading">Albums</p><button className="px-side-add" aria-label="New Album" title="New Album" onClick={() => setNaming({ id: null, then: [], draft: "" })}><Plus size={14} strokeWidth={2} aria-hidden="true" /></button></div>+ <div className="px-albums" role="group" aria-label="Albums">{naming?.id === null && nameField}{albums.map(([a, n]) =>naming?.id === a.id ? (@@ -784,6 +815,9 @@ export function PhotosView() {</button>),)}+ </div>+ <p className="px-side-heading px-side-gap">Utilities</p>+ {UTILITIES.map(source)}</aside><section className="px-main" aria-label={title}>diff --git a/src/styles/photos.css b/src/styles/photos.cssindex c1a26ec..32aebd2 100644--- a/src/styles/photos.css+++ b/src/styles/photos.css@@ -50,6 +50,8 @@.px-source:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }.px-source[aria-current="true"] { background: color-mix(in srgb, var(--text) 12%, transparent); }.px-source:focus-visible { outline: 3px solid var(--accent-ring); outline-offset: -1px; }+.px-albums { display: flex; flex-direction: column; gap: 1px; }+.px-side-gap { margin-top: 14px; }.px-side-row { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }.px-side-row .px-side-heading { margin-bottom: 4px; }.px-side-add {