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
Notes: each note's formatting stored beside its body at sync, so it shows offline; the notes zone read once more from the start to fill it in
Yashwanth Kamireddic2aba31d0944
diff --git a/crates/quince-core/src/lib.rs b/crates/quince-core/src/lib.rsindex 467b2d4..817d45c 100644--- a/crates/quince-core/src/lib.rs+++ b/crates/quince-core/src/lib.rs@@ -142,10 +142,9 @@ mod tests {}let library = Library::open(dir.path()).unwrap();assert_eq!(library.sync_token("reminders").unwrap(), None);- assert_eq!(- library.sync_token("notes").unwrap().as_deref(),- Some("kept")- );+ // Notes is read from the start once too, by a later migration of its own: every note+ // has to have its formatting read, and only a full pass reaches the untouched ones.+ assert_eq!(library.sync_token("notes").unwrap(), None);}#[test]diff --git a/crates/quince-core/src/notes.rs b/crates/quince-core/src/notes.rsindex 68185b9..87a2d8a 100644--- a/crates/quince-core/src/notes.rs+++ b/crates/quince-core/src/notes.rs@@ -1,7 +1,7 @@//! Notes and their folders in the local library.use crate::{Library, Result};-use rusqlite::params;+use rusqlite::{params, OptionalExtension};use serde::{Deserialize, Serialize};#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]@@ -51,6 +51,10 @@ pub struct Note {#[serde(default = "yes")]pub editable: bool,pub etag: Option<String>,+ /// How the body is set — Apple's attribute runs, as JSON — read from the same record as+ /// the body, so formatting shows without the network. Absent where none was read.+ #[serde(default, skip_serializing)]+ pub runs: Option<String>,}fn yes() -> bool {@@ -108,19 +112,32 @@ impl Library {Ok(())}+ /// The note's attribute runs as stored, JSON, if any were read.+ pub fn note_runs(&self, guid: &str) -> Result<Option<String>> {+ Ok(self+ .conn+ .query_row(+ "SELECT runs FROM notes WHERE guid = ?1",+ params![guid],+ |r| r.get(0),+ )+ .optional()?+ .flatten())+ }+pub fn put_notes(&mut self, notes: &[Note]) -> Result<()> {let tx = self.conn.transaction()?;{let mut stmt = tx.prepare("INSERT INTO notes (guid, folder_guid, title, snippet, body, locked, pinned,- created_at, modified_at, editable, etag, updated_at)- VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12)+ created_at, modified_at, editable, etag, updated_at, runs)+ VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13)ON CONFLICT(guid) DO UPDATE SETfolder_guid = excluded.folder_guid, title = excluded.title,snippet = excluded.snippet, body = excluded.body,locked = excluded.locked, pinned = excluded.pinned,created_at = excluded.created_at, modified_at = excluded.modified_at,- editable = excluded.editable,+ editable = excluded.editable, runs = excluded.runs,etag = excluded.etag, updated_at = excluded.updated_at",)?;let stamp = now();@@ -137,7 +154,8 @@ impl Library {n.modified_at,i64::from(n.editable),n.etag,- stamp+ stamp,+ n.runs])?;}}@@ -317,6 +335,7 @@ impl Library {modified_at: row.get(7)?,editable: row.get::<_, i64>(8)? != 0,etag: row.get(9)?,+ runs: None,})})?;Ok(rows.collect::<rusqlite::Result<Vec<_>>>()?)@@ -358,6 +377,7 @@ impl Library {modified_at: row.get(7)?,editable: row.get::<_, i64>(8)? != 0,etag: row.get(9)?,+ runs: None,},body,))@@ -391,6 +411,7 @@ mod search_tests {created_at: Some(1),modified_at: Some(1),etag: None,+ runs: None,}}@@ -545,6 +566,7 @@ mod tests {modified_at: Some(modified),editable: true,etag: None,+ runs: None,}}@@ -652,6 +674,7 @@ mod body_tests {created_at: Some(1),modified_at: Some(2),etag: None,+ runs: None,},Note {guid: "N2".into(),@@ -667,6 +690,7 @@ mod body_tests {created_at: Some(1),modified_at: Some(1),etag: None,+ runs: None,},]).unwrap();@@ -730,6 +754,7 @@ mod unreadable_tests {created_at: Some(1),modified_at: Some(1),etag: None,+ runs: None,}}@@ -786,6 +811,7 @@ mod count_tests {modified_at: None,editable: true,etag: None,+ runs: None,}}diff --git a/crates/quince-core/src/schema.rs b/crates/quince-core/src/schema.rsindex f1f4d1d..3387dc9 100644--- a/crates/quince-core/src/schema.rs+++ b/crates/quince-core/src/schema.rs@@ -371,4 +371,10 @@ pub const MIGRATIONS: &[&str] = &[ALTER TABLE reminders ADD COLUMN all_day INTEGER NOT NULL DEFAULT 0;UPDATE sync_state SET token = NULL WHERE service = 'reminders';"#,+ // A note's formatting — Apple's attribute runs — kept beside its body, and the notes zone+ // read again from the start so every note has them.+ r#"+ ALTER TABLE notes ADD COLUMN runs TEXT;+ UPDATE sync_state SET token = NULL WHERE service = 'notes';+ "#,];diff --git a/crates/quince-icloud/src/notes.rs b/crates/quince-icloud/src/notes.rsindex 47c9dcd..4e0c24d 100644--- a/crates/quince-icloud/src/notes.rs+++ b/crates/quince-icloud/src/notes.rs@@ -91,6 +91,12 @@ fn note_from_record(record: &Value) -> Option<Note> {.unwrap_or_else(|| "New Note".into()),snippet: field::document_text(record, "SnippetEncrypted"),body,+ runs: record+ .pointer("/fields/TextDataEncrypted/value")+ .and_then(Value::as_str)+ .map(crate::ckdocument::runs_from_base64)+ .filter(|r| !r.is_empty())+ .and_then(|r| serde_json::to_string(&r).ok()),// Set from the PasswordProtectedNote records below. Inferring it from a body that// failed to decode would label our own parsing failures as "locked", which is a// claim we would not be able to stand behind.@@ -1257,6 +1263,7 @@ mod write_tests {modified_at: None,editable: true,etag: Some("tag".into()),+ runs: None,}}diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rsindex 069bc2f..be27721 100644--- a/src-tauri/src/main.rs+++ b/src-tauri/src/main.rs@@ -768,9 +768,10 @@ async fn reminder_create(data: State<'_, Data>,) -> UiResult<()> {let (http, root, params) = cloudkit_context(&auth).await?;- let guid = quince_icloud::reminders::create_cloudkit(&http, &root, params.clone(), &list_guid, &title)- .await- .map_err(|e| e.to_string())?;+ let guid =+ quince_icloud::reminders::create_cloudkit(&http, &root, params.clone(), &list_guid, &title)+ .await+ .map_err(|e| e.to_string())?;if due_at.is_some() || flagged.is_some() {let made = quince_core::reminders::Reminder {guid,@@ -996,6 +997,16 @@ async fn note_body(guid: String, data: State<'_, Data>) -> UiResult<Option<Strinlibrary.note_body(&guid).map_err(|e| e.to_string())}+/// How a note's text is set — Apple's attribute runs, in order — as stored at the last sync.+#[tauri::command]+async fn note_runs(guid: String, data: State<'_, Data>) -> UiResult<serde_json::Value> {+ let library = data.0.lock().await;+ let stored = library.note_runs(&guid).map_err(|e| e.to_string())?;+ Ok(stored+ .and_then(|s| serde_json::from_str(&s).ok())+ .unwrap_or(serde_json::Value::Array(Vec::new())))+}+#[tauri::command]async fn note_save(guid: String,@@ -1093,6 +1104,7 @@ async fn note_create(modified_at: Some(now),editable: true,etag: None,+ runs: None,}]).map_err(|e| e.to_string())?;}@@ -2396,6 +2408,7 @@ fn main() {note_folder_rename,note_folder_delete,note_body,+ note_runs,note_save,note_create,note_delete,