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: Title and Caption, as icloud.com's Info has them

Yashwanth Kamireddi14f8c5994326
diff --git a/.uiverify/photos-caption.mjs b/.uiverify/photos-caption.mjs
index f7a4ac5..d5b60b2 100644
--- a/.uiverify/photos-caption.mjs
+++ b/.uiverify/photos-caption.mjs
@@ -1,6 +1,7 @@
-// A caption, as Photos' Info has one: typed in place, saved on Return, kept when the photo is
-// opened again; the keys typed into it are words (an "f" does not favorite); Escape puts it
-// back and leaves the photo open.
+// Title and caption, as Photos' Info has them (Apple's captionEnc and extendedDescEnc): typed in
+// place, both saved together when the words are left — going from one to the other is not
+// leaving — kept when the photo opens again; the letters typed are words, not the photo's keys;
+// Escape puts back what was there and leaves the photo open.
import { engine } from "./engine.mjs";
import { SERVICES, installStub, openScreen } from "./stub.mjs";
const b = await engine.launch();
@@ -13,33 +14,37 @@ 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 sent = () => page.evaluate(() => window.__texts ?? []);
await page.locator(".px-tile").nth(1).dblclick();
await page.waitForTimeout(600);
await page.keyboard.press("i");
-const field = page.getByLabel("Caption");
-ok((await field.getAttribute("placeholder")) === "Add a Caption", "Info offers Add a Caption");
-await field.click();
-await page.keyboard.type("Ferry at half five, fish and hills");
+ok((await page.getByLabel("Title").getAttribute("placeholder")) === "Add a Title" &&
+ (await page.getByLabel("Caption").getAttribute("placeholder")) === "Add a Caption", "Info offers Add a Title and Add a Caption");
+await page.getByLabel("Title").click();
+await page.keyboard.type("Ferry");
ok((await page.evaluate(() => (window.__flags ?? []).length)) === 0 && (await page.locator(".px-viewer").count()) === 1,
"the letters typed are words, not the photo's keys");
+await page.getByLabel("Caption").click();
+ok((await sent()).length === 0, "going from the title to the caption saves nothing yet");
+await page.keyboard.type("Half five, fish and hills");
await page.keyboard.press("Enter");
await page.waitForTimeout(200);
-ok(JSON.stringify(await page.evaluate(() => window.__captions?.at(-1))) === JSON.stringify({ id: "p2", caption: "Ferry at half five, fish and hills" }),
- "Return saves it to iCloud");
+ok(JSON.stringify((await sent()).at(-1)) === JSON.stringify({ id: "p2", title: "Ferry", caption: "Half five, fish and hills" }) && (await sent()).length === 1,
+ "leaving them saves both, once");
await page.keyboard.press("Escape");
await page.waitForTimeout(650);
await page.locator(".px-tile").nth(1).dblclick();
await page.waitForTimeout(600);
-// Info stays open from one photo to the next, as in Photos.
ok((await page.locator(".px-info").count()) === 1, "Info is still open on the next photo opened");
-ok((await page.getByLabel("Caption").inputValue()) === "Ferry at half five, fish and hills", "and it is there when the photo is opened again");
-await page.getByLabel("Caption").click();
+ok((await page.getByLabel("Title").inputValue()) === "Ferry" && (await page.getByLabel("Caption").inputValue()) === "Half five, fish and hills",
+ "and both are there when the photo opens again");
+await page.getByLabel("Title").click();
await page.keyboard.type(" — not this");
await page.keyboard.press("Escape");
await page.waitForTimeout(200);
-ok((await page.getByLabel("Caption").inputValue()) === "Ferry at half five, fish and hills" && (await page.locator(".px-viewer").count()) === 1,
+ok((await page.getByLabel("Title").inputValue()) === "Ferry" && (await page.locator(".px-viewer").count()) === 1,
"Escape puts it back and keeps the photo open");
-ok((await page.evaluate(() => window.__captions.length)) === 1, "and sends nothing");
+ok((await sent()).length === 1, "and sends nothing");
await b.close();
process.exitCode = failures ? 1 : (process.exitCode ?? 0);
diff --git a/.uiverify/stub.mjs b/.uiverify/stub.mjs
index 55c9779..21116d4 100644
--- a/.uiverify/stub.mjs
+++ b/.uiverify/stub.mjs
@@ -365,10 +365,10 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note
}
return p;
}
- case "photo_set_caption": {
- (window.__captions ??= []).push(args);
+ case "photo_set_text": {
+ (window.__texts ??= []).push(args);
const p = (window.__photos ?? []).find((x) => x.id === args.id);
- if (p) p.caption = args.caption || null;
+ if (p) { p.title = args.title || null; p.caption = args.caption || null; }
return p;
}
case "photo_play": (window.__plays ??= []).push(args); return null;
diff --git a/crates/quince-core/src/photos.rs b/crates/quince-core/src/photos.rs
index 68da02a..dfe9d75 100644
--- a/crates/quince-core/src/photos.rs
+++ b/crates/quince-core/src/photos.rs
@@ -67,7 +67,10 @@ pub struct Photo {
/// In Recently Deleted: when Apple deletes it for good, unix seconds (`dateExpunged`).
#[serde(default)]
pub expunge_at: Option<i64>,
- /// The caption typed for it in Photos (`captionEnc`).
+ /// Its title, as typed in Photos' Info (`captionEnc` — Apple's name for the title).
+ #[serde(default)]
+ pub title: Option<String>,
+ /// Its caption, the longer words under the title (`extendedDescEnc`).
#[serde(default)]
pub caption: Option<String>,
/// Photos' subtype: 1 and 3 mark screenshots and the like (`assetSubtypeV2`).
@@ -120,7 +123,7 @@ pub enum View {
}
const COLUMNS: &str = "id, master, taken_at, added_at, kind, width, height, duration, filename, \
- size, uti, favorite, hidden, deleted, deleted_at, subtype, change_tag, expunge_at, caption";
+ size, uti, favorite, hidden, deleted, deleted_at, subtype, change_tag, expunge_at, title, caption";
fn row_to_photo(r: &rusqlite::Row<'_>) -> rusqlite::Result<Photo> {
Ok(Photo {
@@ -142,7 +145,8 @@ fn row_to_photo(r: &rusqlite::Row<'_>) -> rusqlite::Result<Photo> {
subtype: r.get(15)?,
change_tag: r.get(16)?,
expunge_at: r.get(17)?,
- caption: r.get(18)?,
+ title: r.get(18)?,
+ caption: r.get(19)?,
})
}
@@ -154,8 +158,8 @@ impl Library {
let mut stmt = tx.prepare(
"INSERT INTO photos (id, master, taken_at, added_at, kind, width, height, duration,
filename, size, uti, favorite, hidden, deleted, deleted_at,
- subtype, change_tag, expunge_at, caption)
- VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19)
+ subtype, change_tag, expunge_at, title, caption)
+ VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19, ?20)
ON CONFLICT(id) DO UPDATE SET
master = excluded.master, taken_at = excluded.taken_at,
added_at = excluded.added_at, kind = excluded.kind, width = excluded.width,
@@ -164,7 +168,8 @@ impl Library {
favorite = excluded.favorite, hidden = excluded.hidden,
deleted = excluded.deleted, deleted_at = excluded.deleted_at,
subtype = excluded.subtype, change_tag = excluded.change_tag,
- expunge_at = excluded.expunge_at, caption = excluded.caption",
+ expunge_at = excluded.expunge_at, title = excluded.title,
+ caption = excluded.caption",
)?;
for p in photos {
stmt.execute(params![
@@ -186,6 +191,7 @@ impl Library {
p.subtype,
p.change_tag,
p.expunge_at,
+ p.title,
p.caption
])?;
}
@@ -497,6 +503,7 @@ mod tests {
subtype: 0,
change_tag: None,
expunge_at: None,
+ title: None,
caption: None,
}
}
diff --git a/crates/quince-core/src/schema.rs b/crates/quince-core/src/schema.rs
index 79642f0..7331a44 100644
--- a/crates/quince-core/src/schema.rs
+++ b/crates/quince-core/src/schema.rs
@@ -455,4 +455,11 @@ pub const MIGRATIONS: &[&str] = &[
r#"
ALTER TABLE photo_uploads ADD COLUMN album TEXT;
"#,
+ // What was kept as the caption is Photos' title (`captionEnc`); the caption proper is
+ // `extendedDescEnc`. Photos is read again so each has its own.
+ r#"
+ ALTER TABLE photos RENAME COLUMN caption TO title;
+ ALTER TABLE photos ADD COLUMN caption TEXT;
+ UPDATE sync_state SET token = NULL WHERE service = 'photos';
+ "#,
];
diff --git a/crates/quince-icloud/src/photos.rs b/crates/quince-icloud/src/photos.rs
index 6591755..8b321b5 100644
--- a/crates/quince-icloud/src/photos.rs
+++ b/crates/quince-icloud/src/photos.rs
@@ -158,7 +158,8 @@ pub fn photo_of(asset: &Value, master: &Value) -> Option<Photo> {
.filter(|&d| d == 1)
.and(millis(asset, "recordModificationDate")),
subtype: field::int(asset, "assetSubtypeV2").unwrap_or(0),
- caption: decoded(asset, "captionEnc"),
+ title: decoded(asset, "captionEnc"),
+ caption: decoded(asset, "extendedDescEnc"),
expunge_at: (field::int(asset, "isDeleted") == Some(1))
.then(|| millis(asset, "dateExpunged"))
.flatten(),
@@ -184,7 +185,8 @@ fn with_asset(mut p: Photo, asset: &Value) -> Photo {
} else {
None
};
- p.caption = decoded(asset, "captionEnc");
+ p.title = decoded(asset, "captionEnc");
+ p.caption = decoded(asset, "extendedDescEnc");
p.expunge_at = if p.deleted {
millis(asset, "dateExpunged").or(p.expunge_at)
} else {
@@ -367,14 +369,16 @@ pub async fn set_flag(
.await
}
-/// A photo's caption set, as icloud.com sets it: `captionEnc`, base64 of its UTF-8 bytes,
-/// against the asset's change tag. An empty caption clears it. Answers the asset as it now is.
-pub async fn set_caption(
+/// A photo's title and caption set, as icloud.com's Info sets them: the title is `captionEnc`
+/// and the caption `extendedDescEnc` (Apple's names), each base64 of its UTF-8 bytes, against
+/// the asset's change tag. Empty clears one. Answers the asset as it now is.
+pub async fn set_title_and_caption(
http: &reqwest::Client,
ckdatabasews_root: &str,
params: Vec<(String, String)>,
asset: &str,
change_tag: Option<&str>,
+ title: &str,
caption: &str,
) -> Result<Value> {
let client = ZoneClient::new(http, ckdatabasews_root, CONTAINER, params);
@@ -384,7 +388,10 @@ pub async fn set_caption(
asset,
"CPLAsset",
change_tag,
- serde_json::json!({ "captionEnc": { "value": album_name(caption) } }),
+ serde_json::json!({
+ "captionEnc": { "value": album_name(title) },
+ "extendedDescEnc": { "value": album_name(caption) },
+ }),
)
.await
}
diff --git a/probe/examples/photos_peek.rs b/probe/examples/photos_peek.rs
index 9b5a04f..5907b5c 100644
--- a/probe/examples/photos_peek.rs
+++ b/probe/examples/photos_peek.rs
@@ -23,7 +23,13 @@ async fn main() -> Result<()> {
.await?
.ok_or_else(|| anyhow!("gone"))?;
for (k, v) in r["fields"].as_object().unwrap() {
- if k.contains("ate") || k.starts_with("is") {
+ if k.contains("ate")
+ || k.starts_with("is")
+ || k.ends_with("Enc")
+ || k.contains("ating")
+ || k.contains("eyword")
+ || k.contains("ocation")
+ {
println!("{k} = {}", v["value"]);
}
}
diff --git a/probe/examples/photos_caption_roundtrip.rs b/probe/examples/photos_text_roundtrip.rs
similarity index 62%
rename from probe/examples/photos_caption_roundtrip.rs
rename to probe/examples/photos_text_roundtrip.rs
index 1983745..7fb626a 100644
--- a/probe/examples/photos_caption_roundtrip.rs
+++ b/probe/examples/photos_text_roundtrip.rs
@@ -1,5 +1,6 @@
-//! Live, on a wallpaper he named as a throwaway: a caption set through Quince's own
-//! set_caption, read back from Apple, then cleared. Leaves the photo as it was.
+//! Live, on a wallpaper he named as a throwaway: a title and a caption set through Quince's
+//! own set_title_and_caption (captionEnc and extendedDescEnc), read back from Apple, then
+//! cleared. Leaves the photo as it was.
use anyhow::{anyhow, Result};
use base64::Engine;
use quince_icloud::photos::{self, CONTAINER, ZONE};
@@ -18,8 +19,8 @@ async fn main() -> Result<()> {
.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 caption = |r: &serde_json::Value| {
- r.pointer("/fields/captionEnc/value")
+ let text = |r: &serde_json::Value, f: &str| {
+ r.pointer(&format!("/fields/{f}/value"))
.and_then(|v| v.as_str())
.map(|v| {
String::from_utf8_lossy(
@@ -30,29 +31,34 @@ async fn main() -> Result<()> {
.into_owned()
})
};
+ let show = |r: &serde_json::Value| {
+ format!(
+ "title={:?} caption={:?}",
+ text(r, "captionEnc"),
+ text(r, "extendedDescEnc")
+ )
+ };
let before = zc
.lookup_record(ZONE, &asset)
.await?
.ok_or_else(|| anyhow!("gone"))?;
- println!("before: {:?}", caption(&before));
+ println!("before: {}", show(&before));
let tag = before.get("recordChangeTag").and_then(|t| t.as_str());
- let after = photos::set_caption(
+ photos::set_title_and_caption(
&http,
&ck,
p.clone(),
&asset,
tag,
- "Spring bloom — Quince test ✿",
+ "Spring bloom",
+ "Quince test — a caption ✿",
)
.await?;
let now = zc.lookup_record(ZONE, &asset).await?.unwrap();
- println!("set: {:?}", caption(&now));
- let tag = after
- .get("recordChangeTag")
- .and_then(|t| t.as_str())
- .or_else(|| now.get("recordChangeTag").and_then(|t| t.as_str()));
- photos::set_caption(&http, &ck, p.clone(), &asset, tag, "").await?;
+ println!("set: {}", show(&now));
+ let tag = now.get("recordChangeTag").and_then(|t| t.as_str());
+ photos::set_title_and_caption(&http, &ck, p.clone(), &asset, tag, "", "").await?;
let back = zc.lookup_record(ZONE, &asset).await?.unwrap();
- println!("clear: {:?}", caption(&back));
+ println!("clear: {}", show(&back));
Ok(())
}
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 5e7d7ad..5f262ed 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -3768,7 +3768,7 @@ fn main() {
photos::photos_album_delete,
photos::photos_album_add,
photos::photos_album_remove,
- photos::photo_set_caption,
+ photos::photo_set_text,
photos::photo_download,
note_table_add_row,
note_table_remove,
diff --git a/src-tauri/src/photos.rs b/src-tauri/src/photos.rs
index 730769c..111e607 100644
--- a/src-tauri/src/photos.rs
+++ b/src-tauri/src/photos.rs
@@ -457,10 +457,11 @@ pub async fn photo_set_flag(
Ok(updated)
}
-/// A photo's caption, as typed in its Info: Apple's answer taken at once. Empty clears it.
+/// A photo's title and caption, as typed in its Info: Apple's answer taken at once. Empty clears one.
#[tauri::command]
-pub async fn photo_set_caption(
+pub async fn photo_set_text(
id: String,
+ title: String,
caption: String,
auth: State<'_, Auth>,
data: State<'_, Data>,
@@ -473,18 +474,20 @@ pub async fn photo_set_caption(
.photo(&id)
.map_err(|e| e.to_string())?
.ok_or("That photo is no longer in the library.")?;
- let caption = caption.trim().to_string();
+ let (title, caption) = (title.trim().to_string(), caption.trim().to_string());
let (http, root, params) = crate::cloudkit_context(&auth).await?;
- let answer = quince_icloud::photos::set_caption(
+ let answer = quince_icloud::photos::set_title_and_caption(
&http,
&root,
params,
&id,
photo.change_tag.as_deref(),
+ &title,
&caption,
)
.await
.map_err(|e| e.to_string())?;
+ photo.title = (!title.is_empty()).then_some(title);
photo.caption = (!caption.is_empty()).then_some(caption);
photo.change_tag = answer
.get("recordChangeTag")
diff --git a/src/lib/ipc.ts b/src/lib/ipc.ts
index b36541c..e0b7823 100644
--- a/src/lib/ipc.ts
+++ b/src/lib/ipc.ts
@@ -99,7 +99,8 @@ export const api = {
invoke<Photo>("photo_set_flag", { id, flag, on }),
/** The original saved to Downloads; answers where. */
photoDownload: (id: string) => invoke<string>("photo_download", { id }),
- photoSetCaption: (id: string, caption: string) => invoke<Photo>("photo_set_caption", { id, caption }),
+ /** Title and caption together, as Info saves them. */
+ photoSetText: (id: string, title: string, caption: string) => invoke<Photo>("photo_set_text", { id, title, caption }),
/** Photos and videos (or folders of them) into the library. Answers the batch; progress
* arrives as PHOTO_UPLOAD events, in the same shape as Drive's. */
/** Into the library, and into `album` too when one is open. */
@@ -582,7 +583,8 @@ export type Photo = {
deletedAt: number | null;
/** In Recently Deleted: when Apple deletes it for good, unix seconds. */
expungeAt?: number | null;
- /** The caption typed for it in Photos. */
+ /** Its title and caption, as typed in Photos' Info. */
+ title?: string | null;
caption?: string | null;
subtype: number;
changeTag: string | null;
diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsx
index 8f423bb..5b7464e 100644
--- a/src/screens/PhotosView.tsx
+++ b/src/screens/PhotosView.tsx
@@ -1015,13 +1015,38 @@ export function PhotosView() {
/>
);
- const caption = async (p: Photo, words: string) => {
- const next = words.trim();
- if (next === (p.caption ?? "")) return;
+ /*
+ * Title and caption, as Photos' Info has them: typed in place, Return (in the title) or
+ * leaving them saves both at once — moving from one to the other is not leaving — and Escape
+ * puts back what was there. Shown at once; put back if iCloud refuses.
+ */
+ const titleField = useRef<HTMLInputElement | null>(null);
+ const captionField = useRef<HTMLTextAreaElement | null>(null);
+ const grow = (el: HTMLTextAreaElement) => {
+ el.style.height = "auto";
+ el.style.height = `${el.scrollHeight}px`;
+ };
+ const wordKeys = (e: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>, was: string | null | undefined) => {
+ if (e.key === "Enter" && (e.currentTarget.tagName === "INPUT" || !e.shiftKey)) {
+ e.preventDefault();
+ e.currentTarget.blur();
+ } else if (e.key === "Escape") {
+ e.currentTarget.value = was ?? "";
+ e.currentTarget.blur();
+ e.stopPropagation();
+ }
+ };
+ const wordsLeft = (p: Photo, e: React.FocusEvent) => {
+ if (e.currentTarget.contains(e.relatedTarget as Node | null)) return;
+ void words(p, titleField.current?.value ?? p.title ?? "", captionField.current?.value ?? p.caption ?? "");
+ };
+ const words = async (p: Photo, title: string, caption: string) => {
+ const [t, c] = [title.trim(), caption.trim()];
+ if (t === (p.title ?? "") && c === (p.caption ?? "")) return;
const before = photos;
- setPhotos((all) => (all ?? []).map((x) => (x.id === p.id ? { ...x, caption: next || null } : x)));
+ setPhotos((all) => (all ?? []).map((x) => (x.id === p.id ? { ...x, title: t || null, caption: c || null } : x)));
try {
- await api.photoSetCaption(p.id, next);
+ await api.photoSetText(p.id, t, c);
} catch (e) {
setPhotos(before);
setError(messageOf(e));
@@ -1508,24 +1533,31 @@ export function PhotosView() {
<dl className="px-info">
{/* As in Photos' Info: the caption first, typed in place, and kept on every
device; Return or leaving the field saves it, Escape puts it back. */}
- <dd className="px-caption-row">
+ <dd className="px-caption-row" onBlur={(e) => wordsLeft(shown, e)}>
<input
- key={shown.id}
+ key={`t${shown.id}`}
+ ref={titleField}
+ className="px-title-field"
+ aria-label="Title"
+ placeholder="Add a Title"
+ defaultValue={shown.title ?? ""}
+ maxLength={255}
+ readOnly={view === "recentlyDeleted"}
+ onKeyDown={(e) => wordKeys(e, shown.title)}
+ />
+ <textarea
+ key={`c${shown.id}`}
+ ref={captionField}
className="px-caption"
aria-label="Caption"
placeholder="Add a Caption"
defaultValue={shown.caption ?? ""}
maxLength={2000}
+ rows={1}
readOnly={view === "recentlyDeleted"}
- onKeyDown={(e) => {
- if (e.key === "Enter") e.currentTarget.blur();
- else if (e.key === "Escape") {
- e.currentTarget.value = shown.caption ?? "";
- e.currentTarget.blur();
- e.stopPropagation();
- }
- }}
- onBlur={(e) => void caption(shown, e.currentTarget.value)}
+ onInput={(e) => grow(e.currentTarget)}
+ onFocus={(e) => grow(e.currentTarget)}
+ onKeyDown={(e) => wordKeys(e, shown.caption)}
/>
</dd>
<dt>Name</dt>
diff --git a/src/styles/photos.css b/src/styles/photos.css
index 3c09ac6..2ac1c3b 100644
--- a/src/styles/photos.css
+++ b/src/styles/photos.css
@@ -445,7 +445,8 @@
/* The caption, typed in place at the head of Info, as Photos has it. */
.px-caption-row { margin: 0 0 4px; }
-.px-caption {
+.px-title-field, .px-caption {
+ display: block;
padding: 6px 8px;
margin: 0 -8px;
width: calc(100% + 16px);
@@ -458,7 +459,8 @@
font-weight: 600;
outline: none;
}
-.px-caption::placeholder { color: var(--text-3); font-weight: 500; }
-.px-caption:hover:not(:read-only) { background: color-mix(in srgb, var(--text) 6%, transparent); }
-.px-caption:focus { background: var(--field, transparent); box-shadow: 0 0 0 2px var(--accent-ring); }
+.px-caption { resize: none; overflow: hidden; font-size: var(--t-13); font-weight: 400; line-height: 1.4; color: var(--text-2); }
+.px-title-field::placeholder, .px-caption::placeholder { color: var(--text-3); font-weight: 500; }
+.px-title-field:hover:not(:read-only), .px-caption:hover:not(:read-only) { background: color-mix(in srgb, var(--text) 6%, transparent); }
+.px-title-field:focus, .px-caption:focus { background: var(--field, transparent); box-shadow: 0 0 0 2px var(--accent-ring); }
.px input, .px textarea { -webkit-user-select: text; user-select: text; }