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: one note found by its key — every save, tick, pin, move and delete had read the whole library twice to find it
Yashwanth Kamireddib72d6670885c
diff --git a/crates/quince-core/src/notes.rs b/crates/quince-core/src/notes.rsindex 0b44e35..1117db4 100644--- a/crates/quince-core/src/notes.rs+++ b/crates/quince-core/src/notes.rs@@ -327,6 +327,37 @@ impl Library {/// The preview is a truncation, so it is put in `snippet` — which is only ever displayed —/// and never in `body`, which is what an editor would save back. A body that came back/// short and got written would take the rest of the note with it.+ /// One note by record name, wherever it is filed — Recently Deleted too — as `notes_in`+ /// gives it: no body. One row by key, where finding it through `notes_in` read every note.+ pub fn note(&self, guid: &str) -> Result<Option<Note>> {+ Ok(self+ .conn+ .query_row(+ "SELECT guid, folder_guid, title,+ coalesce(snippet, substr(body, 1, 200)), locked, pinned,+ created_at, modified_at, editable, etag+ FROM notes WHERE guid = ?1",+ params![guid],+ |row| {+ Ok(Note {+ guid: row.get(0)?,+ folder_guid: row.get(1)?,+ title: row.get(2)?,+ snippet: row.get(3)?,+ body: None,+ locked: row.get::<_, i64>(4)? != 0,+ pinned: row.get::<_, i64>(5)? != 0,+ created_at: row.get(6)?,+ modified_at: row.get(7)?,+ editable: row.get::<_, i64>(8)? != 0,+ etag: row.get(9)?,+ runs: None,+ })+ },+ )+ .optional()?)+ }+pub fn notes_in(&self, folder_guid: Option<&str>) -> Result<Vec<Note>> {let mut stmt = self.conn.prepare("SELECT guid, folder_guid, title,diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rsindex 94b702c..5328da6 100644--- a/src-tauri/src/main.rs+++ b/src-tauri/src/main.rs@@ -978,15 +978,11 @@ async fn resync_notes(/// One note, by record name. `None` once Apple no longer has it.async fn note_by_guid(data: &State<'_, Data>, guid: &str) -> Result<Note, String> {let library = data.0.lock().await;- // Recently Deleted too: "All" leaves it out, and Delete Now and Recover act on what is- // in it — looking only in "All" answered every one of them "no longer in the library".- let all = library.notes_in(None).map_err(|e| e.to_string())?;- let trash = library- .notes_in(Some(quince_core::notes::TRASH_FOLDER))- .map_err(|e| e.to_string())?;- all.into_iter()- .chain(trash)- .find(|n| n.guid == guid)+ // Wherever it is filed, Recently Deleted included: Delete Now and Recover act on notes+ // there, and looking only in "All" answered each of them "no longer in the library".+ library+ .note(guid)+ .map_err(|e| e.to_string())?.ok_or_else(|| "That note is no longer in the local library.".into())}@@ -1138,11 +1134,7 @@ async fn note_create(// pasting, lost the paste's save. Saving reads the record from Apple, so a local stand-in// with no tag is enough until the feed catches up.let mut library = data.0.lock().await;- let known = library- .notes_in(None)- .map_err(|e| e.to_string())?- .iter()- .any(|n| n.guid == guid);+ let known = library.note(&guid).map_err(|e| e.to_string())?.is_some();if !known {let (title, snippet) = quince_icloud::notes::title_and_snippet(&body);let now = std::time::SystemTime::now()