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
Reminders: making and renaming a list works again — Name is an encrypted field and must say so, measured live; new lists are blue and linked to the account as icloud.com makes them; list colour backend verified live
Yashwanth Kamireddi365ef0638eda
diff --git a/crates/quince-icloud/src/reminders.rs b/crates/quince-icloud/src/reminders.rsindex 7e0d526..70bdaff 100644--- a/crates/quince-icloud/src/reminders.rs+++ b/crates/quince-icloud/src/reminders.rs@@ -1569,9 +1569,15 @@ pub async fn create_list_cloudkit(&record_name,"List",serde_json::json!({- "Name": { "type": "STRING", "value": title },+ // `isEncrypted`, as every list on a real account has it: without it CloudKit+ // takes the field for raw bytes and refuses the list ("byte values must be+ // base64 encoded") — measured, and why making a list here failed.+ "Name": { "type": "STRING", "value": title, "isEncrypted": true },"Deleted": { "type": "NUMBER_INT64", "value": 0 },"IsGroup": { "type": "NUMBER_INT64", "value": 0 },+ // As icloud.com makes a list: blue, and linked to the account.+ "Color": { "type": "STRING", "value": list_colour_value("blue").unwrap_or_default() },+ "IsLinkedToAccount": { "type": "NUMBER_INT64", "value": 1 },"SortingStyle": { "type": "STRING", "value": "manual" },}),)@@ -1599,7 +1605,73 @@ pub async fn rename_list_cloudkit(list_guid,"List",None,- serde_json::json!({ "Name": { "type": "STRING", "value": title } }),+ serde_json::json!({ "Name": { "type": "STRING", "value": title, "isEncrypted": true } }),+ )+ .await?;+ Ok(())+}++/// Apple's list colours, as icloud.com's picker offers them: the CloudKit name each is keyed+/// by, its RGB, and the older name where it has one ("custom" where not). A list's `Color`+/// is resolved by the CloudKit name first, so that is what matters; the rest is written as+/// Apple writes it, so every client reads the same colour.+pub const LIST_COLOURS: [(&str, [u8; 3], &str); 12] = [+ ("red", [255, 59, 48], "red"),+ ("orange", [255, 149, 0], "orange"),+ ("yellow", [255, 204, 0], "yellow"),+ ("green", [52, 199, 89], "green"),+ ("lightBlue", [81, 170, 242], "custom"),+ ("blue", [0, 122, 255], "blue"),+ ("indigo", [88, 86, 214], "custom"),+ ("pink", [234, 66, 106], "custom"),+ ("purple", [192, 119, 219], "purple"),+ ("brown", [162, 132, 94], "custom"),+ ("gray", [91, 103, 112], "custom"),+ ("rose", [217, 166, 159], "custom"),+];++/// A list's `Color` value, as icloud.com writes one — measured beside a list the phone made:+/// `{"red":…,"green":…,"blue":…,"alpha":1,"colorRGBSpace":2,"daHexString":"#5AC8FA",+/// "ckSymbolicColorName":"lightBlue","daSymbolicColorName":"custom"}`.+pub fn list_colour_value(name: &str) -> Option<String> {+ let (ck, [r, g, b], da) = LIST_COLOURS.iter().find(|(ck, _, _)| *ck == name)?;+ Some(+ serde_json::json!({+ "red": f64::from(*r) / 255.0,+ "green": f64::from(*g) / 255.0,+ "blue": f64::from(*b) / 255.0,+ "alpha": 1,+ "colorRGBSpace": 2,+ "daHexString": format!("#{r:02X}{g:02X}{b:02X}"),+ "ckSymbolicColorName": ck,+ "daSymbolicColorName": da,+ })+ .to_string(),+ )+}++/// Change a list's colour, as Show List Info does: `Color` only, with its token advanced so+/// every device takes the change.+pub async fn set_list_colour_cloudkit(+ http: &reqwest::Client,+ ckdatabasews_root: &str,+ params: Vec<(String, String)>,+ list_guid: &str,+ colour: &str,+) -> Result<()> {+ let value = list_colour_value(colour).ok_or_else(|| {+ Error::Refused(format!(+ "\u{201c}{colour}\u{201d} isn't one of Apple's list colours."+ ))+ })?;+ let client = ZoneClient::new(http, ckdatabasews_root, CONTAINER, params);+ client+ .update_record_signed(+ ZONE,+ list_guid,+ "List",+ None,+ serde_json::json!({ "Color": { "type": "STRING", "value": value } }),).await?;Ok(())@@ -1763,7 +1835,7 @@ mod incremental_tests {fn list(name: &str, title: &str) -> Value {json!({"recordName": name, "recordType": "List",- "fields": { "Name": { "type": "STRING", "value": title } }+ "fields": { "Name": { "type": "STRING", "value": title, "isEncrypted": true } }})}@@ -3343,7 +3415,7 @@ mod list_shape_tests {"recordName": name,"recordType": "List","fields": {- "Name": { "type": "STRING", "value": title },+ "Name": { "type": "STRING", "value": title, "isEncrypted": true },"IsGroup": { "type": "NUMBER_INT64", "value": i64::from(group) },}})@@ -3505,7 +3577,7 @@ mod other_accounts_tests {"recordName": name,"recordType": "List","fields": {- "Name": { "type": "STRING", "value": title },+ "Name": { "type": "STRING", "value": title, "isEncrypted": true },"IsGroup": { "type": "NUMBER_INT64", "value": i64::from(group) },}})@@ -3906,7 +3978,7 @@ mod account_order_tests {fn list(name: &str, title: &str, group: Option<&str>, is_group: bool) -> Value {let mut fields = json!({- "Name": { "type": "STRING", "value": title },+ "Name": { "type": "STRING", "value": title, "isEncrypted": true },"IsGroup": { "type": "NUMBER_INT64", "value": i64::from(is_group) },});if let Some(parent) = group {diff --git a/probe/examples/drive_thumbs.rs b/probe/examples/drive_thumbs.rsindex bca42fb..3557c94 100644--- a/probe/examples/drive_thumbs.rs+++ b/probe/examples/drive_thumbs.rs@@ -4,18 +4,48 @@ use anyhow::{anyhow, Result};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 drivews = client.session().service_url("drivews").ok_or_else(|| anyhow!("no drivews"))?;- let docws = client.session().service_url("docws").ok_or_else(|| anyhow!("no docws"))?;+ if !client.resume().await? {+ return Err(anyhow!("no session"));+ }+ let drivews = client+ .session()+ .service_url("drivews")+ .ok_or_else(|| anyhow!("no drivews"))?;+ let docws = client+ .session()+ .service_url("docws")+ .ok_or_else(|| anyhow!("no docws"))?;let (http, p) = (client.http().clone(), client.service_params());- let mut lib = quince_core::Library::open(&std::env::temp_dir().join(format!("qth-{}", uuid::Uuid::new_v4())))?;- quince_icloud::drive::sync_folder(&http, &drivews, p.clone(), &mut lib, quince_core::drive::ROOT).await?;- let downloads = lib.drive_children(quince_core::drive::ROOT)?.into_iter().find(|i| i.name == "Downloads").ok_or_else(|| anyhow!("no Downloads"))?;- quince_icloud::drive::sync_folder(&http, &drivews, p.clone(), &mut lib, &downloads.drivewsid).await?;+ let mut lib = quince_core::Library::open(+ &std::env::temp_dir().join(format!("qth-{}", uuid::Uuid::new_v4())),+ )?;+ quince_icloud::drive::sync_folder(+ &http,+ &drivews,+ p.clone(),+ &mut lib,+ quince_core::drive::ROOT,+ )+ .await?;+ let downloads = lib+ .drive_children(quince_core::drive::ROOT)?+ .into_iter()+ .find(|i| i.name == "Downloads")+ .ok_or_else(|| anyhow!("no Downloads"))?;+ quince_icloud::drive::sync_folder(&http, &drivews, p.clone(), &mut lib, &downloads.drivewsid)+ .await?;let files = lib.drive_children(&downloads.drivewsid)?;for (id, bytes) in quince_icloud::drive::thumbnails(&http, &docws, p, &files).await? {- let name = files.iter().find(|f| f.drivewsid == id).map(|f| f.display_name()).unwrap_or_default();- println!("{name}: {} bytes, starts {:02x?}", bytes.len(), &bytes[..4.min(bytes.len())]);+ let name = files+ .iter()+ .find(|f| f.drivewsid == id)+ .map(|f| f.display_name())+ .unwrap_or_default();+ println!(+ "{name}: {} bytes, starts {:02x?}",+ bytes.len(),+ &bytes[..4.min(bytes.len())]+ );}Ok(())}diff --git a/probe/examples/reminder_list_colour.rs b/probe/examples/reminder_list_colour.rsnew file mode 100644index 0000000..004999e--- /dev/null+++ b/probe/examples/reminder_list_colour.rs@@ -0,0 +1,41 @@+//! Live, throwaway list only: make a list, colour it purple, read it back, delete it.+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 ckdatabasews"))?;+ let (http, p) = (client.http().clone(), client.service_params());+ let guid = quince_icloud::reminders::create_list_cloudkit(+ &http,+ &root,+ p.clone(),+ "Quince colour test",+ )+ .await?;+ println!("made {guid}");+ quince_icloud::reminders::set_list_colour_cloudkit(&http, &root, p.clone(), &guid, "purple")+ .await?;+ let zc =+ quince_icloud::cloudkit::ZoneClient::new(&http, &root, "com.apple.reminders", p.clone());+ let r = zc+ .lookup_record("Reminders", &guid)+ .await?+ .ok_or_else(|| anyhow!("gone"))?;+ println!("Color = {}", r["fields"]["Color"]["value"]);+ let rtm: serde_json::Value = serde_json::from_str(+ r["fields"]["ResolutionTokenMap"]["value"]+ .as_str()+ .unwrap_or("{}"),+ )?;+ println!("color token = {}", rtm["map"]["color"]);+ quince_icloud::reminders::delete_list_cloudkit(&http, &root, p, &guid).await?;+ println!("deleted");+ Ok(())+}diff --git a/probe/examples/reminder_lists_raw.rs b/probe/examples/reminder_lists_raw.rsnew file mode 100644index 0000000..48f4335--- /dev/null+++ b/probe/examples/reminder_lists_raw.rs@@ -0,0 +1,43 @@+//! Live, read-only: one Reminders List record, every field.+use anyhow::{anyhow, Result};+use serde_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 ckdatabasews"))?;+ let zc = quince_icloud::cloudkit::ZoneClient::new(+ client.http(),+ &root,+ "com.apple.reminders",+ client.service_params(),+ );+ let walk = zc.all_records("Reminders", None).await?;+ for r in walk+ .records+ .iter()+ .filter(|r| {+ r["recordType"] == "List"+ && r["fields"]["IsGroup"]["value"] != 1+ && r["fields"].get("Color").is_some()+ })+ .take(1)+ {+ let mut r = r.clone();+ if let Some(f) = r.get_mut("fields").and_then(Value::as_object_mut) {+ for (k, v) in f.iter_mut() {+ if k == "ReminderIDs" {+ *v = Value::from("…");+ }+ }+ }+ println!("{}", serde_json::to_string_pretty(&r["fields"])?);+ }+ Ok(())+}