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
Lists can be created, renamed and deleted
Yashwanth Kamireddi8d71ff350b08
diff --git a/.uiverify/a11y.mjs b/.uiverify/a11y.mjsindex 9f7aa4a..a35b26f 100644--- a/.uiverify/a11y.mjs+++ b/.uiverify/a11y.mjs@@ -34,6 +34,8 @@ function installStub({ screen, services, twoFactor }) {case "reminder_delete": return null;case "reminder_set_done": return null;case "reminder_edit": return null;+ case "reminder_list_create": case "reminder_list_rename": case "reminder_list_delete":+ return null;case "reminders_smart": return [];case "note_folders": return [];case "notes_in": return [];diff --git a/.uiverify/assert.mjs b/.uiverify/assert.mjsindex 52f1781..8f62b8a 100644--- a/.uiverify/assert.mjs+++ b/.uiverify/assert.mjs@@ -23,6 +23,7 @@ await ctx.addInitScript(({ services }) => {if (cmd === "reminder_set_done") return null;if (cmd === "reminder_edit") return null;if (cmd === "reminders_smart") return [];+ if (cmd === "reminder_list_create" || cmd === "reminder_list_rename" || cmd === "reminder_list_delete") return null;if (cmd === "note_folders") return [];if (cmd === "notes_in") return [];if (cmd === "notes_last_synced") return Math.floor(Date.now() / 1000);diff --git a/.uiverify/keyboard.mjs b/.uiverify/keyboard.mjsindex a8bd83e..a00c7f9 100644--- a/.uiverify/keyboard.mjs+++ b/.uiverify/keyboard.mjs@@ -33,6 +33,8 @@ function installStub({ screen, services, twoFactor }) {case "reminder_delete": return null;case "reminder_set_done": return null;case "reminder_edit": return null;+ case "reminder_list_create": case "reminder_list_rename": case "reminder_list_delete":+ return null;case "reminders_smart": return [];case "note_folders": return [];case "notes_in": return [];diff --git a/.uiverify/shots.mjs b/.uiverify/shots.mjsindex 9f7164d..1ebc08c 100644--- a/.uiverify/shots.mjs+++ b/.uiverify/shots.mjs@@ -136,6 +136,8 @@ function installStub({ screen, services, twoFactor, calendarFixture, notesFixturcase "reminder_delete": return null;case "reminder_set_done": return null;case "reminder_edit": return null;+ case "reminder_list_create": case "reminder_list_rename": case "reminder_list_delete":+ return null;case "reminders_smart": return !remindersFixture ? [] : reminderItems.filter(r => !r.completedAt);case "note_folders": return !notesFixture ? [] : noteFolders;case "notes_in": return !notesFixture ? [] : noteList;diff --git a/crates/quince-icloud/src/reminders.rs b/crates/quince-icloud/src/reminders.rsindex 01a802d..49cd010 100644--- a/crates/quince-icloud/src/reminders.rs+++ b/crates/quince-icloud/src/reminders.rs@@ -837,6 +837,91 @@ pub async fn edit_cloudkit(Ok(())}+/// Create a list.+///+/// Returns the record name Apple will know it by. `Name` is a plain string here, unlike a+/// reminder's title, which is wrapped in the document format.+pub async fn create_list_cloudkit(+ http: &reqwest::Client,+ ckdatabasews_root: &str,+ params: Vec<(String, String)>,+ title: &str,+) -> Result<String> {+ let title = title.trim();+ if title.is_empty() {+ return Err(Error::Protocol("a list needs a name".into()));+ }++ let client = ZoneClient::new(http, ckdatabasews_root, CONTAINER, params);+ let record_name = format!("List/{}", uuid::Uuid::new_v4().to_string().to_uppercase());++ client+ .create_record(+ ZONE,+ &record_name,+ "List",+ serde_json::json!({+ "Name": { "type": "STRING", "value": title },+ "Deleted": { "type": "NUMBER_INT64", "value": 0 },+ "IsGroup": { "type": "NUMBER_INT64", "value": 0 },+ "SortingStyle": { "type": "STRING", "value": "manual" },+ }),+ )+ .await?;++ Ok(record_name)+}++/// Rename a list.+pub async fn rename_list_cloudkit(+ http: &reqwest::Client,+ ckdatabasews_root: &str,+ params: Vec<(String, String)>,+ list_guid: &str,+ title: &str,+) -> Result<()> {+ let title = title.trim();+ if title.is_empty() {+ return Err(Error::Protocol("a list needs a name".into()));+ }+ let client = ZoneClient::new(http, ckdatabasews_root, CONTAINER, params);+ client+ .update_record(+ ZONE,+ list_guid,+ "List",+ None,+ serde_json::json!({ "Name": { "type": "STRING", "value": title } }),+ )+ .await?;+ Ok(())+}++/// Remove a list.+///+/// Marks it deleted rather than destroying it, matching how Apple's own clients work and+/// leaving other devices able to reconcile. Its reminders go with it.+pub async fn delete_list_cloudkit(+ http: &reqwest::Client,+ ckdatabasews_root: &str,+ params: Vec<(String, String)>,+ list_guid: &str,+) -> Result<()> {+ let client = ZoneClient::new(http, ckdatabasews_root, CONTAINER, params);+ client+ .update_record(+ ZONE,+ list_guid,+ "List",+ None,+ serde_json::json!({+ "Deleted": { "type": "NUMBER_INT64", "value": 1 },+ }),+ )+ .await?;+ Ok(())+}+/// Tick a CloudKit reminder off, or put it back.////// Sends only the fields that change, guarded by the record's change tag, so a reminder@@ -1426,3 +1511,96 @@ mod edit_tests {assert_eq!(fields["Flagged"]["value"], 1);}}++#[cfg(test)]+mod list_write_tests {+ use super::*;+ use serde_json::json;+ use wiremock::matchers::{method, path_regex};+ use wiremock::{Mock, MockServer, ResponseTemplate};++ async fn accepting() -> MockServer {+ let server = MockServer::start().await;+ Mock::given(method("POST"))+ .and(path_regex(r".*/records/modify$"))+ .respond_with(+ ResponseTemplate::new(200)+ .set_body_json(json!({ "records": [{ "recordName": "List/x" }] })),+ )+ .mount(&server)+ .await;+ server+ }++ async fn sent(server: &MockServer) -> Value {+ let requests = server.received_requests().await.unwrap();+ serde_json::from_slice::<Value>(&requests[0].body).unwrap()["operations"][0].clone()+ }++ /// A list's name is a plain string, unlike a reminder's title — writing it as a document+ /// would leave the list unnamed on the phone.+ #[tokio::test]+ async fn a_created_list_carries_a_plain_name() {+ let server = accepting().await;+ let name =+ create_list_cloudkit(&reqwest::Client::new(), &server.uri(), vec![], "Groceries")+ .await+ .unwrap();+ assert!(+ name.starts_with("List/"),+ "the caller needs the identifier: {name}"+ );++ let op = sent(&server).await;+ assert_eq!(op["operationType"], "create");+ assert_eq!(op["record"]["recordType"], "List");+ assert_eq!(op["record"]["fields"]["Name"]["value"], "Groceries");+ assert_eq!(op["record"]["fields"]["Name"]["type"], "STRING");+ }++ #[tokio::test]+ async fn renaming_sends_only_the_name() {+ let server = accepting().await;+ rename_list_cloudkit(+ &reqwest::Client::new(),+ &server.uri(),+ vec![],+ "List/a",+ "Errands",+ )+ .await+ .unwrap();+ let op = sent(&server).await;+ assert_eq!(op["operationType"], "update");+ assert_eq!(op["record"]["fields"]["Name"]["value"], "Errands");+ assert!(op["record"]["fields"].get("Deleted").is_none());+ }++ /// Deleting marks the flag Apple's own clients use rather than destroying the record.+ #[tokio::test]+ async fn deleting_marks_rather_than_destroys() {+ let server = accepting().await;+ delete_list_cloudkit(&reqwest::Client::new(), &server.uri(), vec![], "List/a")+ .await+ .unwrap();+ let op = sent(&server).await;+ assert_eq!(op["operationType"], "update");+ assert_eq!(op["record"]["fields"]["Deleted"]["value"], 1);+ }++ #[tokio::test]+ async fn a_blank_name_is_refused_before_anything_is_sent() {+ let server = accepting().await;+ assert!(+ create_list_cloudkit(&reqwest::Client::new(), &server.uri(), vec![], " ")+ .await+ .is_err()+ );+ assert!(+ rename_list_cloudkit(&reqwest::Client::new(), &server.uri(), vec![], "List/a", "")+ .await+ .is_err()+ );+ assert!(server.received_requests().await.unwrap().is_empty());+ }+}diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rsindex 243386c..14ff2d3 100644--- a/src-tauri/src/main.rs+++ b/src-tauri/src/main.rs@@ -48,6 +48,23 @@ type UiResult<T> = Result<T, String>;/// The HTTP client, CloudKit root and query parameters, with the auth lock released before/// any network work so a slow sync cannot block the heartbeat or a sign-out.+/// Re-read reminders after a write, so what is on screen is what Apple stored.+///+/// A list change moves records other than the one written, so this is a full pass rather+/// than a delta.+async fn resync_reminders(+ http: &reqwest::Client,+ root: &str,+ params: Vec<(String, String)>,+ data: &State<'_, Data>,+) -> Result<(), String> {+ let mut library = data.0.lock().await;+ quince_icloud::reminders::sync_cloudkit(http, root, params, &mut library, None)+ .await+ .map(|_| ())+ .map_err(|e| e.to_string())+}+async fn cloudkit_context(auth: &State<'_, Auth>,) -> Result<(reqwest::Client, String, Vec<(String, String)>), String> {@@ -416,6 +433,53 @@ async fn reminders_smart(.map_err(|e| e.to_string())}+/// Create, rename or delete a list, then re-read so the sidebar matches Apple.+#[tauri::command]+async fn reminder_list_create(+ title: String,+ auth: State<'_, Auth>,+ data: State<'_, Data>,+) -> UiResult<()> {+ let (http, root, params) = cloudkit_context(&auth).await?;+ quince_icloud::reminders::create_list_cloudkit(&http, &root, params.clone(), &title)+ .await+ .map_err(|e| e.to_string())?;+ resync_reminders(&http, &root, params, &data).await+}++#[tauri::command]+async fn reminder_list_rename(+ list_guid: String,+ title: String,+ auth: State<'_, Auth>,+ data: State<'_, Data>,+) -> UiResult<()> {+ let (http, root, params) = cloudkit_context(&auth).await?;+ quince_icloud::reminders::rename_list_cloudkit(+ &http,+ &root,+ params.clone(),+ &list_guid,+ &title,+ )+ .await+ .map_err(|e| e.to_string())?;+ resync_reminders(&http, &root, params, &data).await+}++#[tauri::command]+async fn reminder_list_delete(+ list_guid: String,+ auth: State<'_, Auth>,+ data: State<'_, Data>,+) -> UiResult<()> {+ let (http, root, params) = cloudkit_context(&auth).await?;+ quince_icloud::reminders::delete_list_cloudkit(&http, &root, params.clone(), &list_guid)+ .await+ .map_err(|e| e.to_string())?;+ resync_reminders(&http, &root, params, &data).await+}+#[tauri::command]async fn reminders_last_synced(data: State<'_, Data>) -> UiResult<Option<i64>> {let library = data.0.lock().await;@@ -572,6 +636,9 @@ fn main() {reminder_delete,reminder_edit,reminders_smart,+ reminder_list_create,+ reminder_list_rename,+ reminder_list_delete,notes_sync,note_folders,notes_in,diff --git a/src/lib/ipc.ts b/src/lib/ipc.tsindex e48ff17..d5cc388 100644--- a/src/lib/ipc.ts+++ b/src/lib/ipc.ts@@ -42,6 +42,11 @@ export const api = {invoke<void>("reminder_set_done", { guid, listGuid, done }),reminderEdit: (guid: string, listGuid: string, edit: ReminderEdit) =>invoke<void>("reminder_edit", { guid, listGuid, edit }),+ reminderListCreate: (title: string) => invoke<void>("reminder_list_create", { title }),+ reminderListRename: (listGuid: string, title: string) =>+ invoke<void>("reminder_list_rename", { listGuid, title }),+ reminderListDelete: (listGuid: string) =>+ invoke<void>("reminder_list_delete", { listGuid }),remindersSmart: (kind: SmartList, until: number) =>invoke<Reminder[]>("reminders_smart", { kind, until }),reminderCreate: (listGuid: string, title: string) =>diff --git a/src/screens/RemindersView.tsx b/src/screens/RemindersView.tsxindex 37c5f21..d9c6b83 100644--- a/src/screens/RemindersView.tsx+++ b/src/screens/RemindersView.tsx@@ -65,6 +65,9 @@ export function RemindersView() {const [busyGuid, setBusyGuid] = useState<string | null>(null);const [openGuid, setOpenGuid] = useState<string | null>(null);const [draft, setDraft] = useState("");+ const [newList, setNewList] = useState("");+ const [addingList, setAddingList] = useState(false);+ const [renaming, setRenaming] = useState<string | null>(null);const [loaded, setLoaded] = useState(false);const [error, setError] = useState<string | null>(null);@@ -164,6 +167,33 @@ export function RemindersView() {const setNotes = (r: Reminder, notes: string) =>write(r, () => api.reminderEdit(r.guid, r.listGuid, { notes: notes.trim() || null }));+ /** List writes go to Apple first, then the whole set is re-read. */+ const listWrite = useCallback(+ async (run: () => Promise<void>) => {+ setSyncing(true);+ setError(null);+ try {+ await run();+ await readLists();+ await readItems();+ } catch (e) {+ setError(messageOf(e));+ } finally {+ setSyncing(false);+ }+ },+ [readLists, readItems]+ );++ async function createList(e: React.FormEvent) {+ e.preventDefault();+ const title = newList.trim();+ if (!title) return;+ await listWrite(() => api.reminderListCreate(title));+ setNewList("");+ setAddingList(false);+ }+async function add(e: React.FormEvent) {e.preventDefault();const title = draft.trim();@@ -207,17 +237,81 @@ export function RemindersView() {<p className="rem-lists-heading">My Lists</p>{lists.map((list) => (- <button- key={list.guid}- className="rem-list"- aria-current={listGuid === list.guid}- onClick={() => setSelection({ type: "list", guid: list.guid })}- >- <span className="dot" style={{ background: list.colour || "var(--gold)" }} />- <span className="rem-list-name">{list.title}</span>- </button>+ <div className="rem-list-row" key={list.guid}>+ {renaming === list.guid ? (+ <input+ className="rem-list-rename"+ defaultValue={list.title}+ autoFocus+ aria-label={`Rename ${list.title}`}+ onBlur={(e) => {+ const title = e.target.value.trim();+ setRenaming(null);+ if (title && title !== list.title) {+ void listWrite(() => api.reminderListRename(list.guid, title));+ }+ }}+ onKeyDown={(e) => {+ if (e.key === "Enter") e.currentTarget.blur();+ if (e.key === "Escape") {+ e.currentTarget.value = list.title;+ e.currentTarget.blur();+ }+ }}+ />+ ) : (+ <>+ <button+ className="rem-list"+ aria-current={listGuid === list.guid}+ onClick={() => setSelection({ type: "list", guid: list.guid })}+ onDoubleClick={() => setRenaming(list.guid)}+ >+ <span className="dot" style={{ background: list.colour || "var(--gold)" }} />+ <span className="rem-list-name">{list.title}</span>+ </button>+ <button+ className="rem-list-action"+ aria-label={`Rename ${list.title}`}+ onClick={() => setRenaming(list.guid)}+ >+ ✎+ </button>+ <button+ className="rem-list-action danger"+ aria-label={`Delete ${list.title}`}+ onClick={() => {+ // Deleting a list takes its reminders, so ask before doing it.+ if (window.confirm(`Delete "${list.title}" and everything in it?`)) {+ void listWrite(() => api.reminderListDelete(list.guid));+ }+ }}+ >+ ×+ </button>+ </>+ )}+ </div>))}{loaded && lists.length === 0 && <p className="badge">No lists yet</p>}++ {addingList ? (+ <form onSubmit={createList}>+ <input+ className="rem-list-rename"+ value={newList}+ onChange={(e) => setNewList(e.target.value)}+ placeholder="List name"+ aria-label="New list name"+ autoFocus+ onBlur={() => !newList.trim() && setAddingList(false)}+ />+ </form>+ ) : (+ <button className="rem-list add" onClick={() => setAddingList(true)}>+ <span className="rem-list-name">Add List</span>+ </button>+ )}</aside><section className="rem-items">diff --git a/src/styles/app.css b/src/styles/app.cssindex 857e519..d22a15e 100644--- a/src/styles/app.css+++ b/src/styles/app.css@@ -1076,3 +1076,42 @@/* A row holding an open detail panel needs the controls at the top, not centred. */.rem-list-items li { align-items: start; }.rem-trailing { padding-top: 2px; }++/* List management sits in the sidebar, with its controls out of the way until hovered. */+.rem-list-row { display: flex; align-items: center; gap: 1px; }+.rem-list-row .rem-list { flex: 1; min-width: 0; }++.rem-list-action {+ border: 0;+ background: none;+ color: var(--text-3);+ font-size: var(--t-11);+ line-height: 1;+ padding: 4px 5px;+ border-radius: var(--r-field);+ cursor: pointer;+ opacity: 0;+ flex: none;+}++.rem-list-row:hover .rem-list-action,+.rem-list-action:focus-visible { opacity: 1; }+.rem-list-action:hover { color: var(--text); background: color-mix(in srgb, var(--text) 8%, transparent); }+.rem-list-action.danger:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }+.rem-list-action:focus-visible { outline: 3px solid var(--gold-ring); outline-offset: 1px; }++.rem-list.add { color: var(--text-3); }+.rem-list.add:hover { color: var(--text-2); }++.rem-list-rename {+ width: 100%;+ font: inherit;+ font-size: var(--t-13);+ color: var(--text);+ background: var(--field);+ border: 1px solid var(--gold);+ border-radius: var(--r-field);+ padding: 5px 8px;+ outline: none;+ box-shadow: 0 0 0 3px var(--gold-ring);+}