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: Screenshots and Panoramas by Apple's own rule; media types only when there are some

Yashwanth Kamireddi2ed6eaa47db6
diff --git a/.uiverify/photos-real.mjs b/.uiverify/photos-real.mjs
index 89bc9e1..1262eb9 100644
--- a/.uiverify/photos-real.mjs
+++ b/.uiverify/photos-real.mjs
@@ -64,5 +64,17 @@ await page.keyboard.press("Escape");
await page.locator(".px-tile").nth(1).dblclick();
await page.waitForTimeout(500);
ok(/full/.test((await page.locator(".px-sharp").getAttribute("src")) ?? ""), "an opened photo fetches the whole picture at once, not only when zoomed");
+// Media types as icloud.com lists them: only the kinds the library has — a panorama appears
+// once there is one (Apple's assetSubtypeV2 1); no empty ones.
+ok((await page.locator(".px-source", { hasText: "Panoramas" }).count()) === 0, "no Panoramas in the sidebar while there are none");
+await page.evaluate(() => { window.__photos.find((p) => p.id === "p4").subtype = 1; });
+await page.locator(".px-source", { hasText: "Recents" }).first().click();
+await page.waitForTimeout(300);
+await page.locator(".px-source", { hasText: "Library" }).first().click();
+await page.waitForTimeout(400);
+ok(/Panoramas\s*1/.test(await page.locator(".px-source", { hasText: "Panoramas" }).innerText()), "and there it is once there is one, with its count");
+await page.locator(".px-source", { hasText: "Panoramas" }).click();
+await page.waitForTimeout(300);
+ok((await page.locator(".px-tile").evaluateAll((t) => t.map((x) => x.dataset.id).join())) === "p4", "holding the panorama");
await b.close();
process.exitCode = failures ? 1 : (process.exitCode ?? 0);
diff --git a/.uiverify/stub.mjs b/.uiverify/stub.mjs
index b2f892c..7b176de 100644
--- a/.uiverify/stub.mjs
+++ b/.uiverify/stub.mjs
@@ -318,7 +318,7 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note
const live = all.filter((p) => !p.deleted && !p.hidden);
const 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),
+ screenshots: live.filter((p) => p.subtype === 3), panoramas: live.filter((p) => p.subtype === 1), recentlyDeleted: all.filter((p) => p.deleted),
hidden: all.filter((p) => !p.deleted && p.hidden),
rated: live.filter((p) => (p.rating ?? 0) > 0).sort((a, b) => b.rating - a.rating || b.takenAt - a.takenAt),
};
diff --git a/crates/quince-core/src/photos.rs b/crates/quince-core/src/photos.rs
index c15bf34..6c712ba 100644
--- a/crates/quince-core/src/photos.rs
+++ b/crates/quince-core/src/photos.rs
@@ -126,6 +126,8 @@ pub enum View {
Favorites,
Videos,
Screenshots,
+ /// Wide photos made by sweeping: assetSubtypeV2 1.
+ Panoramas,
/// Newest added first.
Recents,
/// Hidden from every other view, as Photos' Hidden album.
@@ -317,8 +319,15 @@ impl Library {
"deleted = 0 AND hidden = 0 AND kind = 'video'",
"taken_at DESC",
),
+ // Apple's own rule, read from its smart albums on his library: assetSubtypeV2 3 is a
+ // screenshot, 1 a panorama. (Counting any PNG, and 1, as screenshots put 43 there
+ // against Apple's 4.)
View::Screenshots => (
- "deleted = 0 AND hidden = 0 AND (subtype IN (1, 3) OR uti = 'public.png')",
+ "deleted = 0 AND hidden = 0 AND subtype = 3",
+ "taken_at DESC",
+ ),
+ View::Panoramas => (
+ "deleted = 0 AND hidden = 0 AND subtype = 1",
"taken_at DESC",
),
View::Recents => (
@@ -351,6 +360,7 @@ impl Library {
View::Favorites,
View::Videos,
View::Screenshots,
+ View::Panoramas,
View::Hidden,
View::Rated,
View::RecentlyDeleted,
@@ -721,4 +731,27 @@ mod tests {
lib.forget_photos(&["a".into()]).unwrap();
assert_eq!(ids(&lib, View::Library), ["c", "b"]);
}
+
+ /// Media types as Apple decides them (read from its smart albums on his library): a
+ /// screenshot is assetSubtypeV2 3 and a panorama 1 — not every PNG.
+ #[test]
+ fn media_types_follow_apple() {
+ let mut lib = Library::in_memory().unwrap();
+ let mut png = photo("png", 100);
+ png.uti = Some("public.png".into());
+ let mut shot = photo("shot", 200);
+ shot.subtype = 3;
+ let mut wide = photo("wide", 300);
+ wide.subtype = 1;
+ lib.put_photos(&[png, shot, wide]).unwrap();
+ let ids = |v| {
+ lib.photos(v)
+ .unwrap()
+ .into_iter()
+ .map(|p| p.id)
+ .collect::<Vec<_>>()
+ };
+ assert_eq!(ids(View::Screenshots), ["shot"]);
+ assert_eq!(ids(View::Panoramas), ["wide"]);
+ }
}
diff --git a/probe/examples/photos_smart_albums.rs b/probe/examples/photos_smart_albums.rs
new file mode 100644
index 0000000..8041d3c
--- /dev/null
+++ b/probe/examples/photos_smart_albums.rs
@@ -0,0 +1,77 @@
+//! Read-only: which assets Apple puts in each Media Types smart album, and the fields they
+//! carry that could decide it — to mirror Apple's own rule locally. Nothing is written.
+use anyhow::{anyhow, Result};
+use serde_json::{json, Value};
+
+#[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, mut p) = (client.http().clone(), client.service_params());
+ p.push(("remapEnums".into(), "true".into()));
+ let url = format!(
+ "{}/database/1/com.apple.photos.cloud/production/private/records/query",
+ root.trim_end_matches('/')
+ );
+ for album in [
+ "PANORAMA",
+ "LIVE",
+ "SCREENSHOT",
+ "VIDEO",
+ "DEPTH",
+ "TIMELAPSE",
+ "SLOMO",
+ "ANIMATED",
+ "EXPOSURE",
+ ] {
+ // Walk the album rank by rank, as icloud.com pages it, until it runs out.
+ let mut all: Vec<Value> = Vec::new();
+ let mut rank = 0i64;
+ loop {
+ let body = json!({"query":{"recordType":"CPLAssetAndMasterInSmartAlbumByAssetDate","filterBy":[
+ {"fieldName":"direction","comparator":"EQUALS","fieldValue":{"value":"ASCENDING","type":"STRING"}},
+ {"fieldName":"smartAlbum","comparator":"EQUALS","fieldValue":{"value":album,"type":"STRING"}},
+ {"fieldName":"startRank","comparator":"EQUALS","fieldValue":{"value":rank,"type":"INT64"}}]},
+ "zoneID":{"zoneName":"PrimarySync"},"resultsLimit":100});
+ let v: Value = http
+ .post(&url)
+ .query(&p)
+ .header("content-type", "text/plain")
+ .body(body.to_string())
+ .send()
+ .await?
+ .json()
+ .await?;
+ let page: Vec<Value> = v["records"]
+ .as_array()
+ .into_iter()
+ .flatten()
+ .filter(|r| r["recordType"] == "CPLAsset")
+ .cloned()
+ .collect();
+ if page.is_empty() || all.len() > 2000 {
+ break;
+ }
+ rank += page.len() as i64;
+ all.extend(page);
+ }
+ let mut subtypes = std::collections::BTreeMap::new();
+ for a in &all {
+ *subtypes
+ .entry(a["fields"]["assetSubtypeV2"]["value"].to_string())
+ .or_insert(0) += 1;
+ }
+ println!(
+ "{album}: {} assets; assetSubtypeV2 → {subtypes:?}",
+ all.len()
+ );
+ }
+ Ok(())
+}
diff --git a/src/lib/ipc.ts b/src/lib/ipc.ts
index e72a0d7..67d1e2c 100644
--- a/src/lib/ipc.ts
+++ b/src/lib/ipc.ts
@@ -573,7 +573,7 @@ export function pictureSrc(id: string, size: "thumb" | "medium" | "full" | "orig
export type PhotoAlbum = { id: string; name: string; position: number; changeTag: string | null };
-export type PhotoView = "library" | "favorites" | "videos" | "screenshots" | "recents" | "hidden" | "rated" | "recentlyDeleted";
+export type PhotoView = "library" | "favorites" | "videos" | "screenshots" | "panoramas" | "recents" | "hidden" | "rated" | "recentlyDeleted";
export type Photo = {
id: string;
diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsx
index 84b1687..cf2e957 100644
--- a/src/screens/PhotosView.tsx
+++ b/src/screens/PhotosView.tsx
@@ -35,6 +35,7 @@ const VIEWS: { key: PhotoView; label: string; Icon: LucideIcon }[] = [
/** Photos' Media Types: the library by what kind of picture each is. */
const MEDIA: typeof VIEWS = [
{ key: "videos", label: "Videos", Icon: Video },
+ { key: "panoramas", label: "Panoramas", Icon: RectangleHorizontal },
{ key: "screenshots", label: "Screenshots", Icon: Scan },
];
/** Photos' Utilities: what is kept out of the library. */
@@ -1545,7 +1546,8 @@ export function PhotosView() {
</button>
{branches.media && (
<div className="px-children" role="group" aria-label="Media Types">
- {MEDIA.map(source)}
+ {/* As icloud.com lists them: only the kinds the library has. */}
+ {MEDIA.filter((m) => (counts[m.key] ?? 0) > 0 || (!album && !albumsPage && view === m.key)).map(source)}
</div>
)}
{UTILITIES.map(source)}