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: every pass walked the whole library; now only what changed
Yashwanth Kamireddi1786220ca772
diff --git a/Cargo.lock b/Cargo.lockindex f860ab2..55ff1cf 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -3743,6 +3743,7 @@ dependencies = ["quince-vfs","reqwest 0.12.28","rpassword",+ "rusqlite","serde_json","sha1","sha2",diff --git a/probe/Cargo.toml b/probe/Cargo.tomlindex 5f06d53..dceee22 100644--- a/probe/Cargo.toml+++ b/probe/Cargo.toml@@ -6,6 +6,7 @@ license.workspace = truepublish = false[dependencies]+rusqlite = { version = "0.32", features = ["bundled"] }keyring = { version = "3", default-features = false, features = ["sync-secret-service", "crypto-rust"] }futures-util = "0.3"image = { version = "0.25", default-features = false, features = ["png", "jpeg"] }diff --git a/probe/examples/notes_vs_library.rs b/probe/examples/notes_vs_library.rsnew file mode 100644index 0000000..02ebd29--- /dev/null+++ b/probe/examples/notes_vs_library.rs@@ -0,0 +1,75 @@+//! Read-only: every note Apple holds against the app's library — which differ, and how (text,+//! or missing on one side). Prints titles and lengths, never note text beyond the title.+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());+ let walk = zc.all_records("Notes", None).await?;+ let db = rusqlite::Connection::open_with_flags(+ std::path::PathBuf::from(std::env::var("HOME")?)+ .join(".local/share/dev.quince.client/library.db"),+ rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY,+ )?;+ let mut apple = std::collections::HashSet::new();+ for r in walk.records.iter().filter(|r| r["recordType"] == "Note") {+ let deleted = r["fields"]["Deleted"]["value"].as_i64() == Some(1)+ || r["fields"]["MarkedForDeletion"]["value"].as_i64() == Some(1);+ if deleted {+ continue;+ }+ let id = r["recordName"].as_str().unwrap_or_default().to_string();+ apple.insert(id.clone());+ let text = r["fields"]["TextDataEncrypted"]["value"]+ .as_str()+ .and_then(quince_icloud::ckdocument::text_from_base64)+ .unwrap_or_default();+ let modified = r["fields"]["ModificationDate"]["value"]+ .as_i64()+ .unwrap_or(0)+ / 1000;+ let mine: Option<(String, Option<String>, Option<i64>)> = db+ .query_row(+ "SELECT title, body, modified_at FROM notes WHERE guid = ?1",+ [&id],+ |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)),+ )+ .ok();+ let title: String = text.lines().next().unwrap_or("").chars().take(30).collect();+ match mine {+ None => println!("MISSING here: {title:?} (Apple modified {modified})"),+ Some((_, body, at)) => {+ let body = body.unwrap_or_default();+ if body.trim_end() != text.trim_end() {+ println!(+ "DIFFERS: {title:?} — Apple {} chars @ {modified}, here {} chars @ {}",+ text.chars().count(),+ body.chars().count(),+ at.unwrap_or(0)+ );+ }+ }+ }+ }+ let mut stmt = db.prepare("SELECT guid, title FROM notes")?;+ for row in stmt.query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?)))? {+ let (guid, title) = row?;+ if !apple.contains(&guid) {+ println!(+ "HERE ONLY: {:?}",+ title.chars().take(30).collect::<String>()+ );+ }+ }+ println!("compared {} notes", apple.len());+ Ok(())+}diff --git a/probe/examples/photos_pass_cost.rs b/probe/examples/photos_pass_cost.rsnew file mode 100644index 0000000..c203f69--- /dev/null+++ b/probe/examples/photos_pass_cost.rs@@ -0,0 +1,20 @@+//! Read-only: what a Photos pass costs walked whole against read from the last position.+use anyhow::{anyhow, Result};+use std::time::Instant;+#[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 ck = client.session().service_url("ckdatabasews").ok_or_else(|| anyhow!("no ck"))?;+ let (http, p) = (client.http().clone(), client.service_params());+ let t = Instant::now();+ let whole = quince_icloud::photos::fetch(&http, &ck, p.clone(), None).await?;+ println!("whole library: {} records in {:.1} s", whole.records.len(), t.elapsed().as_secs_f64());+ let t = Instant::now();+ let since = quince_icloud::photos::fetch(&http, &ck, p, whole.token.as_deref()).await?;+ println!("changes since: {} records in {:.2} s", since.records.len(), t.elapsed().as_secs_f64());+ Ok(())+}diff --git a/src-tauri/src/refresh.rs b/src-tauri/src/refresh.rsindex 4b5dc79..768dc5f 100644--- a/src-tauri/src/refresh.rs+++ b/src-tauri/src/refresh.rs@@ -349,6 +349,7 @@ async fn run(client: &Arc<Mutex<Client>>, data: &Mutex<Library>, services: &[&stSome(root) => {let _one = crate::PHOTOS_PASS.lock().await;let since = token(data, quince_icloud::photos::SERVICE).await;+ let full = since.is_none();let fetched = quince_icloud::photos::fetch(&ctx.http,root,@@ -362,8 +363,13 @@ async fn run(client: &Arc<Mutex<Client>>, data: &Mutex<Library>, services: &[&stdata,ctx.account.as_deref(),fetched,- |library, f| {+ move |library, f| {let (_, links) = quince_icloud::photos::apply(library, f)?;+ // Marked, or every pass after walked the whole library again: the+ // daily full read is due when none was ever recorded.+ if full {+ library.mark_full_sync(quince_icloud::photos::SERVICE)?;+ }crate::photos::remember(links);let n = library.photos(quince_core::photos::View::Library)?.len();Ok(format!("{n} photo{}", plural(n)))