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.

Settings scrolls again; drawings and links to notes as Notes has them

Yashwanth Kamireddi8df5811f5d5b
diff --git a/.uiverify/notes-drawing-link.mjs b/.uiverify/notes-drawing-link.mjs
new file mode 100644
index 0000000..17301ea
--- /dev/null
+++ b/.uiverify/notes-drawing-link.mjs
@@ -0,0 +1,62 @@
+// A phone's drawing and a link to another note, as Notes shows them: the drawing as its ink,
+// made for the page's look (light, or dark with its lightness turned as a phone turns it),
+// opening large on a click; a link to a note opens that note here, whatever folder holds it.
+import zlib from "node:zlib";
+import { engine } from "./engine.mjs";
+import { SERVICES, installStub, openScreen } from "./stub.mjs";
+// Ink on white, as Apple's fallback image is: a white 300×240 PNG with a black band.
+const png = (() => {
+ const { deflateSync, crc32 } = zlib;
+ const w = 300, h = 240;
+ const raw = Buffer.alloc((w * 3 + 1) * h, 255);
+ for (let y = 0; y < h; y++) {
+ raw[y * (w * 3 + 1)] = 0;
+ if (y > 100 && y < 120) raw.fill(0, y * (w * 3 + 1) + 1, (y + 1) * (w * 3 + 1));
+ }
+ const chunk = (type, data) => {
+ const len = Buffer.alloc(4); len.writeUInt32BE(data.length);
+ const td = Buffer.concat([Buffer.from(type), data]);
+ const crc = Buffer.alloc(4); crc.writeUInt32BE(crc32(td));
+ return Buffer.concat([len, td, crc]);
+ };
+ const ihdr = Buffer.alloc(13); ihdr.writeUInt32BE(w, 0); ihdr.writeUInt32BE(h, 4); ihdr[8] = 8; ihdr[9] = 2;
+ return Buffer.concat([Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]), chunk("IHDR", ihdr), chunk("IDAT", deflateSync(raw)), chunk("IEND", Buffer.alloc(0))]);
+})();
+const b = await engine.launch();
+let failures = 0;
+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };
+for (const scheme of ["light", "dark"]) {
+ const ctx = await b.newContext({ viewport: { width: 1280, height: 800 }, colorScheme: scheme });
+ await ctx.addInitScript(() => { window.__drawNote = true; window.__picBase = "http://pics.test"; });
+ await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null, notesFixture: true });
+ await ctx.route("http://pics.test/**", (r) => r.fulfill({ status: 200, contentType: "image/png", body: png }));
+ 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, "Notes");
+ await page.waitForTimeout(400);
+ await page.locator(".note-row", { hasText: "Sketch" }).first().click();
+ await page.waitForTimeout(700);
+ const drawing = page.locator(`.ProseMirror img.nf-drawing.nf-ink-${scheme}`);
+ const other = page.locator(`.ProseMirror img.nf-drawing.nf-ink-${scheme === "light" ? "dark" : "light"}`);
+ ok((await drawing.count()) === 1 && (await drawing.getAttribute("src")).includes(scheme === "dark" ? "note%2FD1%2Fdrawing-dark" : "note%2FD1%2Fdrawing"),
+ `${scheme}: the drawing is drawn as its ink for this look, not shown as a file`);
+ ok((await page.locator(".ProseMirror .nf-file").count()) === 0, `${scheme}: no file chip for it`);
+ ok((await drawing.isVisible()) && !(await other.isVisible()), `${scheme}: the ink for this look shows, the other does not`);
+ await page.screenshot({ path: `${process.env.TMPDIR ?? "/tmp"}/notes-drawing-${scheme}-${process.env.ENGINE}.png` });
+ await drawing.click();
+ await page.waitForTimeout(150);
+ ok(await page.getByRole("dialog", { name: "Drawing" }).isVisible(), `${scheme}: a click shows it large`);
+ await page.keyboard.press("Escape");
+ // The link to another note: that note opens, in Quince.
+ const link = page.locator(".ProseMirror a", { hasText: "The plan" });
+ ok((await link.count()) === 1, `${scheme}: the link to a note shows as a link`);
+ await link.click();
+ await page.waitForTimeout(600);
+ ok(page.url().startsWith("http://localhost:4173"), `${scheme}: following it stays in Quince`);
+ ok((await page.locator(".note-row[aria-current='true'], .note-row.is-open, .note-row[aria-selected='true']", { hasText: "The plan" }).count()) === 1
+ || /The plan/.test(await page.locator(".note-rich").first().innerText()), `${scheme}: and opens the note it links to`);
+ await ctx.close();
+}
+await b.close();
+process.exitCode = failures ? 1 : 0;
diff --git a/.uiverify/settings-scroll.mjs b/.uiverify/settings-scroll.mjs
new file mode 100644
index 0000000..2c00724
--- /dev/null
+++ b/.uiverify/settings-scroll.mjs
@@ -0,0 +1,41 @@
+// Settings scrolls, whatever screens were opened before it. Screens stay loaded out of sight,
+// and each one's layout ("the content does not scroll; the screen scrolls inside") was keyed on
+// it merely being there: once any app had been opened, Settings could not scroll at all.
+import { engine } from "./engine.mjs";
+import { SERVICES, installStub, openScreen } from "./stub.mjs";
+const b = await engine.launch();
+const ctx = await b.newContext({ viewport: { width: 1200, height: 600 } });
+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null, notesFixture: true });
+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" });
+let failures = 0;
+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };
+const settings = () => page.locator(".account-card, [aria-label*='Settings'], .sidebar-foot button").first().click();
+// Scrolled by the wheel, as a person scrolls: the page moves.
+const scrolls = async () => {
+ const box = await page.locator(".settings").boundingBox();
+ await page.mouse.move(box.x + box.width / 2, 300);
+ const before = await page.evaluate(() => document.querySelector(".content").scrollTop);
+ await page.mouse.wheel(0, 600);
+ await page.waitForTimeout(300);
+ const after = await page.evaluate(() => document.querySelector(".content").scrollTop);
+ await page.evaluate(() => { document.querySelector(".content").scrollTop = 0; });
+ return after > before;
+};
+await settings();
+await page.waitForTimeout(300);
+ok(await scrolls(), "Settings scrolls");
+for (const s of ["Notes", "Photos", "Calendar", "iCloud Drive", "Reminders", "Contacts"]) {
+ await openScreen(page, s);
+ await page.waitForTimeout(300);
+ await settings();
+ await page.waitForTimeout(300);
+ ok(await scrolls(), `and still, after ${s} was opened`);
+}
+// And each app, back in front, lays out as its own screen again (it does not scroll the page).
+await openScreen(page, "Notes");
+await page.waitForTimeout(300);
+ok(await page.evaluate(() => getComputedStyle(document.querySelector(".content")).overflowY === "hidden"), "Notes in front lays out as its own screen again");
+await b.close();
+process.exitCode = failures ? 1 : 0;
diff --git a/.uiverify/stub.mjs b/.uiverify/stub.mjs
index ae6afe4..eb201ad 100644
--- a/.uiverify/stub.mjs
+++ b/.uiverify/stub.mjs
@@ -247,6 +247,11 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note
const plain = (length) => ({ length, style: null, indent: 0, checked: null, bold: false, italic: false, underline: false, strike: false, link: null });
return [plain(5), { ...plain(1), attachment: "M1" }, plain(1), { ...plain(1), attachment: "M2" }, plain(4)];
}
+ if (args.guid === "nD") {
+ const plain = (length) => ({ length, style: null, indent: 0, checked: null, bold: false, italic: false, underline: false, strike: false, link: null });
+ // "Sketch\n", "See " then "The plan" linked to that note (lower-cased, as a phone links), "\n", the drawing, "\nend".
+ return [{ ...plain(7), style: 0 }, plain(4), { ...plain(8), link: "applenotes:note/1a2b3c4d-0000-4000-8000-00000000ab12?ownerIdentifier=_x" }, plain(1), { ...plain(1), attachment: "D1" }, plain(4)];
+ }
if (args.guid === "nL") {
// "Links", then the address line, then the last line quoted (Block Quote, field 8).
const body = (noteList.find((n) => n.guid === "nL") ?? {}).body ?? "";
@@ -313,6 +318,13 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note
if (window.__mediaNote && !noteList.some((n) => n.guid === "nM"))
noteList.unshift({ guid: "nM", folderGuid: "f1", title: "Trip", snippet: "", body: "Trip\n\uFFFC\n\uFFFC\nend",
locked: false, editable: true, pinned: false, createdAt: null, modifiedAt: 1789100000, etag: null });
+ // Opt-in: a note linking to another note, with a drawing in it, as a phone makes them.
+ if (window.__drawNote && !noteList.some((n) => n.guid === "nD"))
+ noteList.unshift({ guid: "nD", folderGuid: "f1", title: "Sketch", snippet: "", body: "Sketch\nSee The plan\n\uFFFC\nend",
+ locked: false, editable: true, pinned: false, createdAt: null, modifiedAt: 1789300000, etag: null },
+ // The note it links to: a made-up record name, in another folder.
+ { guid: "1A2B3C4D-0000-4000-8000-00000000AB12", folderGuid: "f3", title: "The plan", snippet: "Step one", body: "The plan\nStep one",
+ locked: false, editable: true, pinned: false, createdAt: null, modifiedAt: 1781000000, etag: null });
// Opt-in: a note with web addresses in its text and no links of its own.
if (window.__linkNote && !noteList.some((n) => n.guid === "nL"))
noteList.unshift({ guid: "nL", folderGuid: "f1", title: "Links", snippet: "", body: "Links\nYashps://www.youtube.com/watch?v=5vVh0ZGx8aU\nRead https://example.org/a. Done",
@@ -322,11 +334,12 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note
locked: false, editable: true, pinned: false, createdAt: null, modifiedAt: 1789000000, etag: null });
return !notesFixture ? [] : noteList.map((n) => ({ ...n }));
case "note_attachment_info":
+ if (args.id === "D1") return { id: "D1", uti: "com.apple.paper", kind: "drawing", filename: null, title: null, width: 768, height: 621, size: null, hasPreview: true };
return args.id === "M1"
? { id: "M1", uti: "public.jpeg", kind: "image", filename: "beach.jpeg", title: null, width: 1200, height: 800, size: 271872, hasPreview: true }
: { id: "M2", uti: "org.openxmlformats.spreadsheetml.sheet", kind: "file", filename: "Budget.xlsx", title: null, width: null, height: null, size: 9100, hasPreview: false };
case "note_attachment_open": (window.__opened ??= []).push(args.id); return null;
- case "note_table": if (String(args.id).startsWith("M")) return null; return (window.__table ??= [["Item", "Qty"], ["Milk", "2"], ["", ""]]).map((r) => r.slice());
+ case "note_table": if (/^[MD]/.test(String(args.id))) return null; return (window.__table ??= [["Item", "Qty"], ["Milk", "2"], ["", ""]]).map((r) => r.slice());
case "photos_list": case "photos_counts": {
const P = (id, takenAt, extra = {}) => ({ id, master: `m${id}`, takenAt, addedAt: takenAt, kind: "image",
width: 4032, height: 3024, duration: null, filename: `IMG_${id}.JPG`, size: 2400000, uti: "public.jpeg",
diff --git a/crates/quince-icloud/src/note_media.rs b/crates/quince-icloud/src/note_media.rs
index c4bceca..4084711 100644
--- a/crates/quince-icloud/src/note_media.rs
+++ b/crates/quince-icloud/src/note_media.rs
@@ -40,6 +40,14 @@ pub struct AttachmentInfo {
#[must_use]
pub fn kind_of(uti: &str) -> &'static str {
let u = uti.to_ascii_lowercase();
+ // A drawing made in the note (iOS 17's inline drawings, and the older drawing kinds):
+ // shown as Apple renders it, never as a file.
+ if matches!(
+ u.as_str(),
+ "com.apple.paper" | "com.apple.drawing" | "com.apple.drawing.2"
+ ) {
+ return "drawing";
+ }
if matches!(
u.as_str(),
"public.jpeg"
@@ -157,6 +165,9 @@ pub enum Part {
File,
/// Apple's largest rendering of it.
Preview,
+ /// A drawing as Apple renders it: its fallback image (twice its size, ink on white), or
+ /// its largest preview when it has none.
+ Drawing,
}
async fn download(http: &reqwest::Client, url: &str) -> Result<Vec<u8>> {
@@ -184,8 +195,16 @@ pub async fn bytes(
.lookup_record(ZONE, id)
.await?
.ok_or(Error::NotFound)?;
+ if part == Part::Drawing {
+ if let Some(url) = record
+ .pointer("/fields/FallbackImage/value/downloadURL")
+ .and_then(Value::as_str)
+ {
+ return download(http, url).await;
+ }
+ }
match part {
- Part::Preview => {
+ Part::Preview | Part::Drawing => {
let previews = record
.pointer("/fields/PreviewImages/value")
.and_then(Value::as_array)
@@ -249,6 +268,10 @@ mod tests {
assert_eq!(kind_of("public.jpeg"), "image");
assert_eq!(kind_of("com.apple.paper.doc.pdf"), "document");
assert_eq!(kind_of("com.apple.paper.doc.scan"), "document");
+ // Measured: an iOS 17 drawing in his "Colors" note is com.apple.paper, with a
+ // FallbackImage (1536×1242 for a 768×621 drawing) and two previews.
+ assert_eq!(kind_of("com.apple.paper"), "drawing");
+ assert_eq!(kind_of("com.apple.drawing.2"), "drawing");
assert_eq!(kind_of("com.apple.m4a-audio"), "audio");
assert_eq!(kind_of("public.mpeg-4-audio"), "audio");
assert_eq!(kind_of("com.apple.quicktime-movie"), "video");
diff --git a/crates/quince-media/src/lib.rs b/crates/quince-media/src/lib.rs
index c3fe801..54b0c7d 100644
--- a/crates/quince-media/src/lib.rs
+++ b/crates/quince-media/src/lib.rs
@@ -364,6 +364,76 @@ pub fn thumbnail_mtime(png_bytes: &[u8]) -> Option<i64> {
.and_then(|t| t.text.trim().parse().ok())
}
+/// A drawing's ink, for a page of either look: Apple renders a drawing as ink on white
+/// (its fallback image), and a note is not white. The white is taken back out exactly
+/// ("un-multiplied" over white: each pixel's ink and how much of it there is), leaving the
+/// ink alone on a transparent page. For `dark`, each colour's lightness is turned and its hue
+/// and saturation kept, as a phone shows a drawing in dark mode: black ink white, a yellow
+/// still the yellow it was.
+///
+/// # Errors
+/// When the image cannot be read or written.
+pub fn drawing_ink(png: &[u8], dark: bool) -> Result<Vec<u8>, String> {
+ let mut img = image::load_from_memory(png)
+ .map_err(|e| e.to_string())?
+ .to_rgba8();
+ for px in img.pixels_mut() {
+ let [r, g, b, a0] = px.0.map(|c| f32::from(c) / 255.0);
+ // How much ink: none on white, all of it wherever a channel is fully dark.
+ let ink = 1.0 - r.min(g).min(b);
+ if ink <= 1.0 / 255.0 {
+ px.0 = [0, 0, 0, 0];
+ continue;
+ }
+ let un = |c: f32| ((c - (1.0 - ink)) / ink).clamp(0.0, 1.0);
+ let (mut r, mut g, mut b) = (un(r), un(g), un(b));
+ if dark {
+ let (h, s, l) = to_hsl(r, g, b);
+ (r, g, b) = from_hsl(h, s, 1.0 - l);
+ }
+ let byte = |c: f32| (c * 255.0).round().clamp(0.0, 255.0) as u8;
+ px.0 = [byte(r), byte(g), byte(b), byte(ink * a0)];
+ }
+ let mut out = Vec::new();
+ image::DynamicImage::ImageRgba8(img)
+ .write_to(&mut std::io::Cursor::new(&mut out), image::ImageFormat::Png)
+ .map_err(|e| e.to_string())?;
+ Ok(out)
+}
+
+fn to_hsl(r: f32, g: f32, b: f32) -> (f32, f32, f32) {
+ let (max, min) = (r.max(g).max(b), r.min(g).min(b));
+ let l = (max + min) / 2.0;
+ let d = max - min;
+ if d < f32::EPSILON {
+ return (0.0, 0.0, l);
+ }
+ let s = d / (1.0 - (2.0 * l - 1.0).abs());
+ let h = if (max - r).abs() < f32::EPSILON {
+ ((g - b) / d).rem_euclid(6.0)
+ } else if (max - g).abs() < f32::EPSILON {
+ (b - r) / d + 2.0
+ } else {
+ (r - g) / d + 4.0
+ };
+ (h * 60.0, s.clamp(0.0, 1.0), l)
+}
+
+fn from_hsl(h: f32, s: f32, l: f32) -> (f32, f32, f32) {
+ let c = (1.0 - (2.0 * l - 1.0).abs()) * s;
+ let x = c * (1.0 - ((h / 60.0).rem_euclid(2.0) - 1.0).abs());
+ let m = l - c / 2.0;
+ let (r, g, b) = match (h / 60.0) as u32 {
+ 0 => (c, x, 0.0),
+ 1 => (x, c, 0.0),
+ 2 => (0.0, c, x),
+ 3 => (0.0, x, c),
+ 4 => (x, 0.0, c),
+ _ => (c, 0.0, x),
+ };
+ (r + m, g + m, b + m)
+}
+
/// Whether a freedesktop thumbnail was written by Quince (its `Software` chunk): the ones to
/// remove with an account, and only those — every other app's stay.
#[must_use]
@@ -514,6 +584,43 @@ mod tests {
use super::*;
+ /// A drawing's white goes, its ink stays; in dark, black ink turns white and a mid-tone
+ /// colour keeps its hue and lightness (yellow stays yellow), as on a phone.
+ #[test]
+ fn a_drawing_is_its_ink_on_either_page() {
+ let mut page = image::RgbImage::from_pixel(3, 1, image::Rgb([255, 255, 255]));
+ page.put_pixel(1, 0, image::Rgb([0, 0, 0]));
+ page.put_pixel(2, 0, image::Rgb([255, 204, 0]));
+ let mut png = Vec::new();
+ image::DynamicImage::ImageRgb8(page)
+ .write_to(&mut std::io::Cursor::new(&mut png), image::ImageFormat::Png)
+ .unwrap();
+ let read = |b: Vec<u8>| image::load_from_memory(&b).unwrap().to_rgba8();
+ let light = read(drawing_ink(&png, false).unwrap());
+ assert_eq!(light.get_pixel(0, 0).0[3], 0, "the white is gone");
+ assert_eq!(
+ light.get_pixel(1, 0).0,
+ [0, 0, 0, 255],
+ "black ink stays black"
+ );
+ assert_eq!(
+ light.get_pixel(2, 0).0,
+ [255, 204, 0, 255],
+ "a colour stays itself"
+ );
+ let dark = read(drawing_ink(&png, true).unwrap());
+ assert_eq!(
+ dark.get_pixel(1, 0).0,
+ [255, 255, 255, 255],
+ "black ink turns white"
+ );
+ let y = dark.get_pixel(2, 0).0;
+ assert!(
+ y[0] > y[2] && y[1] > y[2] && y[3] == 255,
+ "yellow stays yellow: {y:?}"
+ );
+ }
+
/// Only Quince's own thumbnails are told apart as ours: another app's are never touched.
#[test]
fn our_thumbnails_are_known_by_their_software_chunk() {
diff --git a/probe/examples/drawing_ink_file.rs b/probe/examples/drawing_ink_file.rs
new file mode 100644
index 0000000..a8a1f62
--- /dev/null
+++ b/probe/examples/drawing_ink_file.rs
@@ -0,0 +1,21 @@
+//! Local: a drawing's fallback image made its ink for a light and a dark page
+//! (quince_media::drawing_ink), written beside it — to look at the result.
+fn main() -> anyhow::Result<()> {
+ let input = std::path::PathBuf::from(
+ std::env::args()
+ .nth(1)
+ .ok_or_else(|| anyhow::anyhow!("png"))?,
+ );
+ let bytes = std::fs::read(&input)?;
+ for (dark, name) in [(false, "ink-light.png"), (true, "ink-dark.png")] {
+ let t = std::time::Instant::now();
+ let out = quince_media::drawing_ink(&bytes, dark).map_err(|e| anyhow::anyhow!(e))?;
+ std::fs::write(input.with_file_name(name), &out)?;
+ println!(
+ "{name}: {} bytes in {} ms",
+ out.len(),
+ t.elapsed().as_millis()
+ );
+ }
+ Ok(())
+}
diff --git a/probe/examples/notes_attachment_census.rs b/probe/examples/notes_attachment_census.rs
new file mode 100644
index 0000000..f2df928
--- /dev/null
+++ b/probe/examples/notes_attachment_census.rs
@@ -0,0 +1,60 @@
+//! Read-only: what each attachment of one note is, as Apple records it — its type and which
+//! of the renderings Notes keeps (preview images, a fallback image or PDF) it has.
+use anyhow::{anyhow, Result};
+#[tokio::main]
+async fn main() -> Result<()> {
+ 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 root = 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, &root, "com.apple.notes", p.clone());
+ for id in std::env::args().skip(1) {
+ let Some(r) = zc.lookup_record("Notes", &id).await? else {
+ println!("{id}: not found");
+ continue;
+ };
+ let mut keys: Vec<String> = r["fields"]
+ .as_object()
+ .map(|o| o.keys().cloned().collect())
+ .unwrap_or_default();
+ keys.sort();
+ let uti = r["fields"]["UTIEncrypted"]["value"]
+ .as_str()
+ .and_then(|v| {
+ base64::Engine::decode(&base64::engine::general_purpose::STANDARD, v).ok()
+ })
+ .map(|b| String::from_utf8_lossy(&b).into_owned())
+ .or_else(|| r["fields"]["UTI"]["value"].as_str().map(String::from));
+ println!("{id}: type {} uti {uti:?}", r["recordType"]);
+ for k in [
+ "PreviewAppearances",
+ "PreviewWidths",
+ "PreviewHeights",
+ "PreviewScales",
+ "PreviewScaleWhenDrawings",
+ "Width",
+ "Height",
+ ] {
+ if let Some(v) = r["fields"][k].get("value") {
+ println!(" {k} = {v}");
+ }
+ }
+ if let Some(n) = r["fields"]["PreviewImages"]["value"].as_array() {
+ println!(
+ " PreviewImages: {} of sizes {:?}",
+ n.len(),
+ n.iter().map(|x| x["size"].clone()).collect::<Vec<_>>()
+ );
+ }
+ if let Some(f) = r["fields"]["FallbackImage"]["value"].as_object() {
+ println!(" FallbackImage size {:?}", f.get("size"));
+ }
+ }
+ Ok(())
+}
diff --git a/probe/examples/notes_drawing_previews.rs b/probe/examples/notes_drawing_previews.rs
new file mode 100644
index 0000000..f70fb0a
--- /dev/null
+++ b/probe/examples/notes_drawing_previews.rs
@@ -0,0 +1,65 @@
+//! Read-only: a drawing's preview images, one per appearance, saved to a folder to look at.
+use anyhow::{anyhow, Result};
+#[tokio::main]
+async fn main() -> Result<()> {
+ let mut args = std::env::args().skip(1);
+ let id = args.next().ok_or_else(|| anyhow!("attachment id"))?;
+ let out = std::path::PathBuf::from(args.next().ok_or_else(|| anyhow!("folder"))?);
+ 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 root = 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, &root, "com.apple.notes", p);
+ let r = zc
+ .lookup_record("Notes", &id)
+ .await?
+ .ok_or_else(|| anyhow!("gone"))?;
+ let looks = r["fields"]["PreviewAppearances"]["value"]
+ .as_array()
+ .cloned()
+ .unwrap_or_default();
+ let mut assets: Vec<(String, String)> = r["fields"]["PreviewImages"]["value"]
+ .as_array()
+ .cloned()
+ .unwrap_or_default()
+ .iter()
+ .enumerate()
+ .filter_map(|(i, a)| {
+ Some((
+ format!("preview-appearance{}", looks.get(i)?),
+ a["downloadURL"].as_str()?.to_string(),
+ ))
+ })
+ .collect();
+ if let Some(u) = r["fields"]["FallbackImage"]["value"]["downloadURL"].as_str() {
+ assets.push(("fallback".into(), u.to_string()));
+ }
+ std::fs::create_dir_all(&out)?;
+ for (name, url) in assets {
+ let bytes = http
+ .get(url.replace("${f}", "file"))
+ .send()
+ .await?
+ .bytes()
+ .await?;
+ let img = image::load_from_memory(&bytes)?;
+ let rgba = img.to_rgba8();
+ let transparent =
+ rgba.pixels().filter(|p| p.0[3] < 255).count() * 100 / rgba.pixels().count().max(1);
+ let path = out.join(format!("{name}.png"));
+ img.save(&path)?;
+ println!(
+ "{name}: {}x{}, {transparent}% transparent, kind {:?}",
+ img.width(),
+ img.height(),
+ image::guess_format(&bytes).ok()
+ );
+ }
+ Ok(())
+}
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 73856d0..a46b4ac 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -196,6 +196,7 @@ fn note_part(path: &str) -> Option<(String, quince_icloud::note_media::Part)> {
let part = match part {
"preview" => quince_icloud::note_media::Part::Preview,
"file" => quince_icloud::note_media::Part::File,
+ "drawing" | "drawing-dark" => quince_icloud::note_media::Part::Drawing,
_ => return None,
};
(!id.is_empty()).then(|| (id.to_string(), part))
@@ -221,6 +222,7 @@ async fn note_media_cached(
let name = match part {
quince_icloud::note_media::Part::Preview => "preview",
quince_icloud::note_media::Part::File => "file",
+ quince_icloud::note_media::Part::Drawing => "drawing",
};
let path = state_dir(app)
.join("note-media")
@@ -250,13 +252,18 @@ async fn note_media_cached(
/// A note's picture as the window can draw it: a HEIC original (what an iPhone takes) made a
/// JPEG on this computer once and kept beside it — the engine draws no HEIC, and the picture
/// fell back to a file chip. Opening it elsewhere still hands over the original.
+///
+/// A drawing is shown as its ink alone, for the page's look (`dark`): see
+/// `quince_media::drawing_ink`.
async fn note_media_shown(
app: &tauri::AppHandle,
id: &str,
part: quince_icloud::note_media::Part,
+ dark: bool,
) -> Result<Vec<u8>, String> {
let bytes = note_media_cached(app, id, part).await?;
- if !quince_media::is_heif(&bytes) {
+ let drawing = part == quince_icloud::note_media::Part::Drawing;
+ if !drawing && !quince_media::is_heif(&bytes) {
return Ok(bytes);
}
let safe: String = id
@@ -269,15 +276,24 @@ async fn note_media_shown(
}
})
.collect();
- let shown = state_dir(app)
- .join("note-media")
- .join(format!("{safe}-shown.jpg"));
- if let Ok(jpeg) = tokio::fs::read(&shown).await {
- return Ok(jpeg);
+ let name = match (drawing, dark) {
+ (true, true) => format!("{safe}-ink-dark.png"),
+ (true, false) => format!("{safe}-ink.png"),
+ _ => format!("{safe}-shown.jpg"),
+ };
+ let shown = state_dir(app).join("note-media").join(name);
+ if let Ok(made) = tokio::fs::read(&shown).await {
+ return Ok(made);
}
- let jpeg = crate::cpu::run(move || quince_media::heic_to_jpeg(&bytes))
- .await
- .map_err(|e| e.to_string())??;
+ let jpeg = crate::cpu::run(move || {
+ if drawing {
+ quince_media::drawing_ink(&bytes, dark)
+ } else {
+ quince_media::heic_to_jpeg(&bytes)
+ }
+ })
+ .await
+ .map_err(|e| e.to_string())??;
let part_path = shown.with_extension("part");
if tokio::fs::write(&part_path, &jpeg).await.is_ok() {
let _ = tokio::fs::rename(&part_path, &shown).await;
@@ -4053,6 +4069,8 @@ fn main() {
let uri = request.uri();
let wanted = photo_guid(uri.host(), uri.path());
let attachment = note_part(uri.path());
+ // A drawing's ink for a dark page, rather than a light one.
+ let ink_dark = uri.path().ends_with("drawing-dark");
let picture = photos::requested(uri.path());
let fit = photos::requested_fit(uri.path());
let queued = photos::requested_upload(uri.path());
@@ -4103,7 +4121,7 @@ fn main() {
}
// A note's picture, or the rendering of a document or film in it.
if let Some((id, part)) = attachment {
- let response = match note_media_shown(&app, &id, part).await {
+ let response = match note_media_shown(&app, &id, part, ink_dark).await {
Ok(bytes) => tauri::http::Response::builder()
.status(200)
.header("Content-Type", image_type(&bytes))
diff --git a/src/lib/ipc.ts b/src/lib/ipc.ts
index ae868a0..a777269 100644
--- a/src/lib/ipc.ts
+++ b/src/lib/ipc.ts
@@ -585,7 +585,7 @@ export type AccountInfo = {
export type NoteAttachment = {
id: string;
uti: string;
- kind: "image" | "document" | "audio" | "video" | "file";
+ kind: "image" | "drawing" | "document" | "audio" | "video" | "file";
filename: string | null;
title: string | null;
width: number | null;
@@ -595,7 +595,7 @@ export type NoteAttachment = {
};
/** A note attachment's picture — the file itself, or Apple's rendering of it. */
-export function noteMediaSrc(id: string, part: "file" | "preview"): string {
+export function noteMediaSrc(id: string, part: "file" | "preview" | "drawing" | "drawing-dark"): string {
return convertFileSrc(`note/${id}/${part}`, "quince");
}
diff --git a/src/screens/NotesView.tsx b/src/screens/NotesView.tsx
index 677a709..84eeeab 100644
--- a/src/screens/NotesView.tsx
+++ b/src/screens/NotesView.tsx
@@ -10,6 +10,7 @@ import { carryRuns, runsFit } from "./notes/rich";
import { NoteEditor, refreshTables, type EditorHandle, type EditorStatus } from "./notes/NoteEditor";
import { FormatPanel } from "./notes/FormatPanel";
import { NotePicture } from "./notes/NotePicture";
+import { OPEN_NOTE_EVENT } from "./notes/links";
import { useSync } from "../lib/sync";
import { Picker } from "../components/Picker";
@@ -208,6 +209,36 @@ export function NotesView() {
);
}, [notes]);
+ // A link to another note, followed: that note opened — from All iCloud when the folder in
+ // front does not hold it — or, when it is not in this account's notes, said so.
+ const following = useRef<string | null>(null);
+ useEffect(() => {
+ const follow = (e: Event) => {
+ const guid = (e as CustomEvent<string>).detail;
+ if (notes.some((n) => n.guid === guid)) {
+ setOpenGuid(guid);
+ setDetail(true);
+ return;
+ }
+ following.current = guid;
+ if (folder !== ALL) setFolder(ALL);
+ else void read();
+ };
+ window.addEventListener(OPEN_NOTE_EVENT, follow);
+ return () => window.removeEventListener(OPEN_NOTE_EVENT, follow);
+ }, [notes, folder, read]);
+ useEffect(() => {
+ const guid = following.current;
+ if (!guid || folder !== ALL || notes.length === 0) return;
+ following.current = null;
+ if (notes.some((n) => n.guid === guid)) {
+ setOpenGuid(guid);
+ setDetail(true);
+ } else {
+ setError("That note isn’t in your notes. It may have been deleted, or it belongs to someone else.");
+ }
+ }, [notes, folder]);
+
const open = useMemo(
() => notes.find((n) => n.guid === openGuid) ?? null,
[notes, openGuid]
diff --git a/src/screens/notes/NoteEditor.tsx b/src/screens/notes/NoteEditor.tsx
index 6f8ddd9..40f937a 100644
--- a/src/screens/notes/NoteEditor.tsx
+++ b/src/screens/notes/NoteEditor.tsx
@@ -76,7 +76,7 @@ function size(bytes: number | null): string {
*/
/** A note's picture asked to be shown large: the viewer (NotePicture) listens for it. */
export const PICTURE_EVENT = "quince:note-picture";
-export type PictureShown = { id: string; name: string; src: string };
+export type PictureShown = { id: string; name: string; src: string; srcDark?: string; drawing?: boolean };
function drawMedia(dom: HTMLElement, info: NoteAttachment) {
const name = info.filename ?? info.title ?? (info.kind === "audio" ? "Recording" : "Attachment");
@@ -101,7 +101,7 @@ function drawMedia(dom: HTMLElement, info: NoteAttachment) {
c.addEventListener("click", open);
return c;
};
- const picture = (part: "file" | "preview", cls: string) => {
+ const picture = (part: "file" | "preview" | "drawing" | "drawing-dark", cls: string) => {
const img = document.createElement("img");
img.className = cls;
img.alt = name;
@@ -121,6 +121,21 @@ function drawMedia(dom: HTMLElement, info: NoteAttachment) {
);
dom.className = "nf-attachment is-image";
dom.replaceChildren(img);
+ } else if (info.kind === "drawing") {
+ // A drawing made in the note, as its ink alone (made on this computer from Apple's
+ // rendering): one for a light page, one for a dark — the look in force shows its own.
+ const light = picture("drawing", "nf-drawing nf-ink-light");
+ const dark = picture("drawing-dark", "nf-drawing nf-ink-dark");
+ const show = () =>
+ window.dispatchEvent(
+ new CustomEvent<PictureShown>(PICTURE_EVENT, {
+ detail: { id: info.id, name: info.title ?? "Drawing", src: light.src, srcDark: dark.src, drawing: true },
+ }),
+ );
+ light.addEventListener("click", show);
+ dark.addEventListener("click", show);
+ dom.className = "nf-attachment is-image is-drawing";
+ dom.replaceChildren(light, dark);
} else if ((info.kind === "document" || info.kind === "video") && info.hasPreview) {
const figure = document.createElement("button");
figure.type = "button";
diff --git a/src/screens/notes/NotePicture.tsx b/src/screens/notes/NotePicture.tsx
index c3134e4..d9501f4 100644
--- a/src/screens/notes/NotePicture.tsx
+++ b/src/screens/notes/NotePicture.tsx
@@ -43,15 +43,24 @@ export function NotePicture() {
aria-label={shown.name}
onClick={(e) => e.stopPropagation()}
>
- <img src={shown.src} alt={shown.name} draggable={false} />
+ {shown.drawing ? (
+ <>
+ <img src={shown.src} alt={shown.name} draggable={false} className="nf-drawing nf-ink-light" />
+ <img src={shown.srcDark} alt={shown.name} draggable={false} className="nf-drawing nf-ink-dark" />
+ </>
+ ) : (
+ <img src={shown.src} alt={shown.name} draggable={false} />
+ )}
<figcaption>
<span className="nf-picture-name">{problem ?? shown.name}</span>
- <button
- className="quiet"
- onClick={() => void api.noteAttachmentOpen(shown.id).catch((e) => setProblem(messageOf(e)))}
- >
- Open in Default App
- </button>
+ {!shown.drawing && (
+ <button
+ className="quiet"
+ onClick={() => void api.noteAttachmentOpen(shown.id).catch((e) => setProblem(messageOf(e)))}
+ >
+ Open in Default App
+ </button>
+ )}
<button className="nf-picture-close" aria-label="Close" autoFocus onClick={() => setShown(null)}>
<X size={16} strokeWidth={2} />
</button>
diff --git a/src/screens/notes/links.ts b/src/screens/notes/links.ts
index d8e6c8b..91b83ce 100644
--- a/src/screens/notes/links.ts
+++ b/src/screens/notes/links.ts
@@ -52,10 +52,27 @@ export const autolink = new Plugin<DecorationSet>({
/** A click on a link (its own, or one found) opens it, as a click does in Notes on the Mac.
* Navigating is enough: the app hands any address outside it to this computer's browser. */
+/** A link to another note asked to be followed: the Notes screen (NotesView) opens it. */
+export const OPEN_NOTE_EVENT = "quince:open-note";
+
+/** The note an Apple Notes link points at, as the library names it: `applenotes:note/<id>?…`
+ * carries the note's record name, lower-cased (measured on his "Link feature of notes"). */
+export function linkedNote(href: string): string | null {
+ const m = /^applenotes:(?:\/\/)?note\/([0-9a-f-]{36})/i.exec(href);
+ return m ? m[1].toUpperCase() : null;
+}
+
export function openLinkAt(event: MouseEvent): boolean {
const a = (event.target as HTMLElement | null)?.closest?.("a[href]") as HTMLAnchorElement | null;
if (!a || event.button !== 0 || event.shiftKey || event.altKey) return false;
const href = a.getAttribute("href") ?? "";
+ // A link to another note opens that note here, as it does in Notes.
+ const note = linkedNote(href);
+ if (note) {
+ event.preventDefault();
+ window.dispatchEvent(new CustomEvent<string>(OPEN_NOTE_EVENT, { detail: note }));
+ return true;
+ }
if (!/^(https?:|mailto:|tel:)/i.test(href)) return false;
event.preventDefault();
window.location.assign(href);
diff --git a/src/styles/app.css b/src/styles/app.css
index 5ce713d..c97ee82 100644
--- a/src/styles/app.css
+++ b/src/styles/app.css
@@ -748,7 +748,7 @@
.cal-empty { margin-top: 14px; color: var(--text-2); max-width: 54ch; }
/* The content pane holds the grid, so it must not scroll independently. */
-.content:has(.cal) { display: flex; flex-direction: column; overflow: hidden; }
+.content:has(> .screen-slot:not([hidden]) .cal) { display: flex; flex-direction: column; overflow: hidden; }
.rem-lists {
overflow-y: auto;
@@ -999,7 +999,7 @@
.contact-notes { margin-top: 20px; color: var(--text-2); white-space: pre-wrap; }
-.content:has(.contacts) { display: flex; flex-direction: column; overflow: hidden; }
+.content:has(> .screen-slot:not([hidden]) .contacts) { display: flex; flex-direction: column; overflow: hidden; }
/* ---- iCloud Drive ---------------------------------------------------------------
A file browser: a path you can walk back along, then rows of what is here. */
@@ -1220,7 +1220,7 @@
.drive-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drive-meta { color: var(--text-2); font-size: var(--t-11); font-variant-numeric: tabular-nums; }
-.content:has(.drive) { display: flex; flex-direction: column; overflow: hidden; }
+.content:has(> .screen-slot:not([hidden]) .drive) { display: flex; flex-direction: column; overflow: hidden; }
/*
* A narrow window, as Files on iPhone sets a row: the name gets the width, with its size and
diff --git a/src/styles/calendar.css b/src/styles/calendar.css
index 0e7f8c3..1d47fe9 100644
--- a/src/styles/calendar.css
+++ b/src/styles/calendar.css
@@ -1,6 +1,6 @@
/* Calendar, laid out the way macOS Calendar is. Scoped under `.cx`. */
-.content:has(.cx) {
+.content:has(> .screen-slot:not([hidden]) .cx) {
display: flex;
flex-direction: column;
overflow: hidden;
diff --git a/src/styles/notes.css b/src/styles/notes.css
index a9e58e5..9169f55 100644
--- a/src/styles/notes.css
+++ b/src/styles/notes.css
@@ -1,6 +1,6 @@
/* Notes, laid out the way Apple Notes is: folders, the list, the note. */
-.content:has(.notes) { display: flex; flex-direction: column; overflow: hidden; padding-top: 18px; }
+.content:has(> .screen-slot:not([hidden]) .notes) { display: flex; flex-direction: column; overflow: hidden; padding-top: 18px; }
.notes {
flex: 1;
@@ -475,3 +475,15 @@ textarea.note-title::placeholder { color: var(--text-3); }
.fp-extra { border-top: 1px solid var(--separator); margin-top: 6px; padding-top: 6px; }
.fp-quote-bar { width: 3px; height: 16px; border-radius: 2px; margin: 0 6px 0 4px;
background: color-mix(in srgb, var(--text) 30%, transparent); }
+
+/* A drawing made in a note: its ink alone, made for a light page and for a dark one
+ (quince_media::drawing_ink); the look in force shows its own. */
+.nf-drawing { display: block; max-width: min(100%, 640px); height: auto; cursor: zoom-in; }
+.nf-picture img.nf-drawing { background: none; box-shadow: none; }
+.nf-ink-dark { display: none; }
+@media (prefers-color-scheme: dark) {
+ :root:not([data-theme="light"]) .nf-ink-light { display: none; }
+ :root:not([data-theme="light"]) .nf-ink-dark { display: block; }
+}
+:root[data-theme="dark"] .nf-ink-light { display: none; }
+:root[data-theme="dark"] .nf-ink-dark { display: block; }
diff --git a/src/styles/photos.css b/src/styles/photos.css
index e13d97b..3e5ba1a 100644
--- a/src/styles/photos.css
+++ b/src/styles/photos.css
@@ -3,7 +3,7 @@
/* The screen fills the window as Notes does, so the sidebar's divider runs the full height
and only the library scrolls. */
-.content:has(.px) { display: flex; flex-direction: column; overflow: hidden; padding-top: 18px; }
+.content:has(> .screen-slot:not([hidden]) .px) { display: flex; flex-direction: column; overflow: hidden; padding-top: 18px; }
.px {
/* An app's own words are not text to select, as in Photos; a field still takes typing. */
diff --git a/src/styles/reminders.css b/src/styles/reminders.css
index 637589f..695243d 100644
--- a/src/styles/reminders.css
+++ b/src/styles/reminders.css
@@ -29,7 +29,7 @@
--sys-orange: #ff9230;
}
-.content:has(.rx) { display: flex; flex-direction: column; overflow: hidden; }
+.content:has(> .screen-slot:not([hidden]) .rx) { display: flex; flex-direction: column; overflow: hidden; }
.rx {
flex: 1;