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
Hidden asks for the Apple Account password, as icloud.com does; locked in the app as well as the window
Yashwanth Kamireddi6f6d1c9dd3a3
diff --git a/.uiverify/photos-hidden-lock.mjs b/.uiverify/photos-hidden-lock.mjsindex 3e93fa3..02d6593 100644--- a/.uiverify/photos-hidden-lock.mjs+++ b/.uiverify/photos-hidden-lock.mjs@@ -1,7 +1,8 @@-// 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.+// The Hidden album is locked, as icloud.com locks it: opened, it shows that it is locked and+// one button to view it — nothing of it read, no tiles, no count. The button asks for the Apple+// Account password; a wrong one says so and stays locked. Viewed, it locks again (in the app as+// well as the window) 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.mjsimport { engine } from "./engine.mjs";@@ -25,7 +26,13 @@ const tiles = () => page.locator(".px-tile").evaluateAll((t) => t.map((x) => x.dconst 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 sheet = page.getByRole("dialog", { name: "View Hidden Photos" });+const unlock = async () => {+ await view.click();+ await sheet.getByLabel("Password").fill("right");+ await page.keyboard.press("Enter");+ 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 });@@ -43,9 +50,20 @@ ok(await hiddenRow.locator(".px-count").count() === 0, "Hidden shows no count wh// 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(/password/i.test(await lockedPanel.innerText()), `saying what it needs (${(await lockedPanel.innerText()).replace(/\s+/g, " ")})`);ok(await hiddenReads() === 0, "and nothing of it is read while it is locked");+// A wrong password: said so, the field cleared for another try, and still locked.+await view.click();+await sheet.getByLabel("Password").fill("wrong");+await page.keyboard.press("Enter");+await page.waitForTimeout(250);+ok(/isn't right/.test(await sheet.innerText()) && (await sheet.getByLabel("Password").inputValue()) === "" && await hiddenReads() === 0,+ "a wrong password says so, clears the field, and reads nothing");+await page.keyboard.press("Escape");+await page.waitForTimeout(150);+ok(await sheet.count() === 0 && await isLocked(), "Escape leaves it locked");+// Viewed.await unlock();ok((await tiles()).includes("p2") && await lockedPanel.count() === 0, "View Hidden Photos shows them");@@ -56,6 +74,7 @@ await page.locator(".px-source", { hasText: "Library" }).first().click();await page.waitForTimeout(250);await openHidden();ok(await isLocked(), "leaving the album locks it again");+ok(await page.evaluate(() => window.__hiddenCalls.at(-1) === "lock" && !window.__hiddenOpen), "in the app as well, not only the window");// The window out of sight (minimised, closed to the tray): locked again.await unlock();diff --git a/.uiverify/stub.mjs b/.uiverify/stub.mjsindex ddeef9c..ba912d6 100644--- a/.uiverify/stub.mjs+++ b/.uiverify/stub.mjs@@ -665,9 +665,18 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note}// Paged: the index (ids, grouping dates, marks), the first page, and photos by id — each// made from the same lists the whole-list commands answer, sorted as the backend sorts.+ // Hidden, as the app keeps it: unlocked with the Apple Account password ("right" here),+ // refused until then; a wrong one said so. Every lock and unlock is noted.+ case "photos_unlock_hidden":+ (window.__hiddenCalls ??= []).push("unlock");+ if (args.password !== "right") throw "That password isn't right.";+ window.__hiddenOpen = true;+ return null;+ case "photos_lock_hidden": (window.__hiddenCalls ??= []).push("lock"); window.__hiddenOpen = false; return null;case "photos_index": case "photos_page": {const self = window.__TAURI_INTERNALS__.invoke;const src = args.source;+ if (src.view === "hidden" && !window.__hiddenOpen) throw "The Hidden album is locked.";let list = src.view ? await self("photos_list", { view: src.view }): src.album ? await self("photos_in_album", { album: src.album }): src.query ? await self("photos_search", { query: src.query })diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rsindex 8538310..6238550 100644--- a/src-tauri/src/main.rs+++ b/src-tauri/src/main.rs@@ -7306,6 +7306,8 @@ fn main() {photos::photos_set_flag,photos::photos_burst,photos::photos_shared_albums,+ photos::photos_unlock_hidden,+ photos::photos_lock_hidden,photos::photos_prepare,photos::photos_index,photos::photos_months,diff --git a/src-tauri/src/photos.rs b/src-tauri/src/photos.rsindex b435592..25763e7 100644--- a/src-tauri/src/photos.rs+++ b/src-tauri/src/photos.rs@@ -20,11 +20,91 @@ const LINK_LIFE: Duration = Duration::from_secs(45 * 60);/// Every master's links seen this run, and when.static LINKS: Mutex<Option<HashMap<String, (Links, Instant)>>> = Mutex::new(None);-/// Every link let go of: they were the last account's.+/// Every link let go of: they were the last account's. Hidden locks with them.pub fn forget_links() {*LINKS.lock().unwrap_or_else(std::sync::PoisonError::into_inner) = None;+ lock_hidden();+}++/// The Hidden album, unlocked with the Apple ID password (as icloud.com asks for it) — for+/// this run, until the window locks it again (leaving Hidden, the window out of sight) or the+/// account changes. Until then nothing of Hidden is handed to the window at all: its lock is+/// not only the window's to keep.+static HIDDEN_OPEN: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);++/// Wrong passwords in a row, and until when another is not taken: a few tries, then a wait+/// that doubles, so nobody at an unlocked computer can go through guesses (and none of them+/// reaches Apple fast enough to count against the account).+static HIDDEN_TRIES: Mutex<(u32, Option<Instant>)> = Mutex::new((0, None));++fn lock_hidden() {+ HIDDEN_OPEN.store(false, std::sync::atomic::Ordering::SeqCst);+}++/// Hidden's photos are asked for: only once it is unlocked.+fn hidden_allowed(source: &quince_core::photos::Source) -> UiResult<()> {+ let hidden = matches!(source, quince_core::photos::Source::View(View::Hidden));+ if hidden && !HIDDEN_OPEN.load(std::sync::atomic::Ordering::SeqCst) {+ return Err("The Hidden album is locked.".into());+ }+ Ok(())+}++/// How long the next try waits after `wrong` wrong passwords in a row: none for the first+/// three, then 30 seconds, doubling to at most ten minutes.+fn hidden_wait(wrong: u32) -> Duration {+ if wrong < 3 {+ return Duration::ZERO;+ }+ Duration::from_secs((30u64 << (wrong - 3).min(5)).min(600))+}++/// The Hidden album unlocked with the account's Apple ID password. Wrong: said so, and after a+/// few, a wait before the next.+#[tauri::command]+pub async fn photos_unlock_hidden(password: String, auth: State<'_, Auth>) -> UiResult<()> {+ let waiting = {+ let tries = HIDDEN_TRIES+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner);+ tries+ .1+ .and_then(|until| until.checked_duration_since(Instant::now()))+ };+ if let Some(left) = waiting {+ let s = left.as_secs().max(1);+ return Err(format!(+ "Too many tries. Try again in {s} second{}.",+ if s == 1 { "" } else { "s" }+ ));+ }+ let right = auth+ .client+ .lock()+ .await+ .check_password(&password)+ .await+ .map_err(|e| e.to_string())?;+ let mut tries = HIDDEN_TRIES+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner);+ if right {+ *tries = (0, None);+ HIDDEN_OPEN.store(true, std::sync::atomic::Ordering::SeqCst);+ return Ok(());+ }+ tries.0 = tries.0.saturating_add(1);+ let wait = hidden_wait(tries.0);+ tries.1 = (!wait.is_zero()).then(|| Instant::now() + wait);+ Err("That password isn't right.".into())+}++/// The Hidden album locked again: the window left it, or went out of sight.+#[tauri::command]+pub fn photos_lock_hidden() {+ lock_hidden();}/// Links a pass brought, kept for the pictures it will be asked for.@@ -1209,6 +1289,7 @@ pub fn content_type(bytes: &[u8], size: Size) -> &'static str {/// A view's photos, newest first.#[tauri::command]pub async fn photos_list(view: View, data: State<'_, Data>) -> UiResult<Vec<Photo>> {+ hidden_allowed(&quince_core::photos::Source::View(view))?;data.0.read(|library| library.photos(view)).await@@ -1224,6 +1305,7 @@ pub async fn photos_index(order: Option<quince_core::photos::Order>,data: State<'_, Data>,) -> UiResult<quince_core::photos::PhotoIndex> {+ hidden_allowed(&source)?;data.0.read(|library| library.photo_index(&source, order)).await@@ -1251,6 +1333,7 @@ pub async fn photos_page(limit: usize,data: State<'_, Data>,) -> UiResult<Vec<Photo>> {+ hidden_allowed(&source)?;data.0.read(|library| library.photo_page(&source, order, after.as_ref(), limit)).await@@ -3065,6 +3148,31 @@ mod link_tests {#[cfg(test)]mod tests {++ /// Hidden's photos are handed out only while it is unlocked, and locking it (the window+ /// leaving it, or the account changing) takes that back; nothing else is held back.+ #[test]+ fn hidden_is_handed_out_only_while_unlocked() {+ use quince_core::photos::Source;+ super::lock_hidden();+ assert!(super::hidden_allowed(&Source::View(View::Hidden)).is_err());+ assert!(super::hidden_allowed(&Source::View(View::Library)).is_ok());+ assert!(super::hidden_allowed(&Source::Shared("SC".into())).is_ok());+ super::HIDDEN_OPEN.store(true, std::sync::atomic::Ordering::SeqCst);+ assert!(super::hidden_allowed(&Source::View(View::Hidden)).is_ok());+ super::forget_links();+ assert!(+ super::hidden_allowed(&Source::View(View::Hidden)).is_err(),+ "an account change locks it"+ );+ }++ /// Three tries free, then a wait that doubles and stops at ten minutes.+ #[test]+ fn wrong_passwords_wait_longer_each_time() {+ let secs: Vec<u64> = (0..12).map(|n| super::hidden_wait(n).as_secs()).collect();+ assert_eq!(secs, [0, 0, 0, 30, 60, 120, 240, 480, 600, 600, 600, 600]);+ }use super::*;/// Copy on Linux answers a paste only with the PNG, and only when a picture was askeddiff --git a/src/lib/ipc.ts b/src/lib/ipc.tsindex e924a6f..71e09d3 100644--- a/src/lib/ipc.ts+++ b/src/lib/ipc.ts@@ -294,6 +294,9 @@ export const api = {invoke<void>("photos_prepare", { shown }),/** Shared albums, made or joined, newest first — from Apple each time. */photosSharedAlbums: () => invoke<SharedAlbum[]>("photos_shared_albums"),+ /** The Hidden album unlocked with the Apple ID password; refused with why (wrong, or a wait). */+ photosUnlockHidden: (password: string) => invoke<void>("photos_unlock_hidden", { password }),+ photosLockHidden: () => invoke<void>("photos_lock_hidden"),/** Every photo of one burst, in the order they were shot. */photosBurst: (burst: string) => invoke<Photo[]>("photos_burst", { burst }),/** Favorite, Delete (to Recently Deleted) or Recover; answers the photo as Apple now has it. */diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsxindex e85b736..a71e8fa 100644--- a/src/screens/PhotosView.tsx+++ b/src/screens/PhotosView.tsx@@ -33,6 +33,7 @@ import { dismissToast, toast, toastSaved, useErrorToast, useToastClearance } froimport { UploadPanel } from "./photos/UploadPanel";import { RowMenu, type MenuEntry } from "../components/RowMenu";import { Portal } from "../components/Portal";+import { useModalFocus } from "../lib/focus";import { Slideshow } from "./photos/Slideshow";import { useConfirm } from "../components/Confirm";import { VideoPlayer } from "./photos/VideoPlayer";@@ -1054,6 +1055,13 @@ export function PhotosView() {useEffect(() => {if (hiddenLocked) setOpen(null);}, [hiddenLocked]);+ // Locked here, locked in the app too: nothing of Hidden is handed out until it is unlocked+ // again with the password.+ useEffect(() => {+ if (!hiddenOpen) void api.photosLockHidden().catch(() => {});+ }, [hiddenOpen]);+ /** The password sheet that unlocks Hidden is open. */+ const [unlocking, setUnlocking] = useState(false);const seen = useRef(revision);if (active) seen.current = revision;const due = seen.current;@@ -3544,11 +3552,20 @@ export function PhotosView() {<EmptyStateclassName="px-empty px-locked"icon={<Lock size={28} strokeWidth={1.6} />}- action={{ label: "View Hidden Photos", run: () => setHiddenOpen(true) }}+ action={{ label: "View Hidden Photos", run: () => setUnlocking(true) }}>- The Hidden album is locked.+ Enter your Apple Account password to view this album.</EmptyState>)}+ {unlocking && hiddenLocked && (+ <UnlockSheet+ onCancel={() => setUnlocking(false)}+ onUnlocked={() => {+ setUnlocking(false);+ setHiddenOpen(true);+ }}+ />+ )}{!hiddenLocked && photos && photos.length === 0 && !drawn.query && (<Arriving service="photos" what="photos" className="px-empty" />)}@@ -4214,3 +4231,85 @@ export function PhotosView() {</div>);}++/**+ * The Apple Account password asked for before Hidden shows, as icloud.com asks for it. Checked+ * by the app (against the password it keeps, else with Apple); a wrong one says so here and+ * the field is cleared for another try.+ */+function UnlockSheet({ onCancel, onUnlocked }: { onCancel: () => void; onUnlocked: () => void }) {+ const sheetRef = useRef<HTMLFormElement | null>(null);+ useModalFocus(sheetRef);+ const field = useRef<HTMLInputElement | null>(null);+ const [password, setPassword] = useState("");+ const [busy, setBusy] = useState(false);+ const [problem, setProblem] = useState<string | null>(null);+ useEffect(() => field.current?.focus(), []);+ const go = async () => {+ if (!password || busy) return;+ setBusy(true);+ setProblem(null);+ try {+ await api.photosUnlockHidden(password);+ onUnlocked();+ } catch (e) {+ setProblem(messageOf(e));+ setPassword("");+ setBusy(false);+ field.current?.focus();+ }+ };+ return (+ <Portal>+ <div className="modal-veil" onClick={onCancel}>+ <form+ ref={sheetRef}+ className="modal-sheet confirm px-unlock"+ role="dialog"+ aria-modal="true"+ aria-label="View Hidden Photos"+ onClick={(e) => e.stopPropagation()}+ onSubmit={(e) => {+ e.preventDefault();+ void go();+ }}+ onKeyDown={(e) => {+ if (e.key === "Escape") {+ e.stopPropagation();+ onCancel();+ }+ }}+ >+ <h2>View Hidden Photos</h2>+ <p>Enter the password for your Apple Account.</p>+ <input+ ref={field}+ className="field"+ type="password"+ autoComplete="current-password"+ placeholder="Password"+ aria-label="Password"+ aria-invalid={problem ? true : undefined}+ aria-describedby={problem ? "px-unlock-problem" : undefined}+ value={password}+ disabled={busy}+ onChange={(e) => setPassword(e.target.value)}+ />+ {problem && (+ <p id="px-unlock-problem" className="px-unlock-problem" role="alert">+ {problem}+ </p>+ )}+ <div className="confirm-actions">+ <button type="button" className="quiet" onClick={onCancel}>+ Cancel+ </button>+ <button type="submit" className="primary confirm-answer" disabled={!password || busy}>+ {busy ? "Checking…" : "View Album"}+ </button>+ </div>+ </form>+ </div>+ </Portal>+ );+}diff --git a/src/styles/photos.css b/src/styles/photos.cssindex e0f8615..715cefa 100644--- a/src/styles/photos.css+++ b/src/styles/photos.css@@ -692,6 +692,9 @@@media (max-width: 1000px) { .px-search { width: 140px; } }.px-naming { width: 100%; }.px-shared-name { width: 100%; min-height: 34px; font-size: var(--t-15); }+/* Hidden's password sheet: the field the sheet's width, and a wrong password said under it. */+.px-unlock .field { width: 100%; min-height: 34px; font-size: var(--t-15); }+.px-unlock .px-unlock-problem { color: var(--danger); font-size: var(--t-13); margin: 6px 0 0; }.px-dl-pics { display: flex; justify-content: center; gap: 4px; }.px-dl-pics img { width: 58px; height: 58px; border-radius: 8px; object-fit: cover; background: color-mix(in srgb, var(--text) 8%, transparent); }.px-dl-count { margin: 6px 0 14px; text-align: center; font-size: var(--t-13); font-weight: 600; }