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
Work on accounts that look nothing like the one this was built against
Yashwanth Kamireddi536aa5510e50
diff --git a/.uiverify/assert.mjs b/.uiverify/assert.mjsindex cba1205..adab303 100644--- a/.uiverify/assert.mjs+++ b/.uiverify/assert.mjs@@ -264,5 +264,78 @@ let failures = 0;await page.close();}+// ── An account with nothing in it ─────────────────────────────────────────────────────+// Everything above was measured against one real library: nine lists, folders, a Drive with+// things in it. A person installing this may have none of that — a new Apple ID, or one whose+// lists and notes have all been deleted. Every screen has to be usable, say something true,+// and never offer a write it cannot carry out.+{+ const empty = await b.newContext({ viewport: { width: 1040, height: 900 } });+ await empty.addInitScript(({ services }) => {+ window.__TAURI_INTERNALS__ = {+ transformCallback: (cb) => cb,+ invoke: async (cmd) => {+ if (cmd === "auth_status") return { hasStoredSession: true, signedIn: true };+ if (cmd === "auth_resume") return true;+ if (cmd === "account_services") return services;+ if (cmd === "reminder_counts")+ return { today: 0, scheduled: 0, flagged: 0, all: 0, lists: [] };+ if (cmd === "sync_all" || cmd === "sync_status")+ return { services: [], asOf: null, tookMs: 0 };+ if (cmd === "plugin:event|listen") return 0;+ // Every list, every folder, every calendar, every row: nothing at all.+ if (cmd.endsWith("_list") || cmd.endsWith("_lists") || cmd.endsWith("_folders") ||+ cmd.endsWith("_children") || cmd.endsWith("_events") || cmd.startsWith("reminders_") ||+ cmd === "notes_in" || cmd === "contacts_list") return [];+ return null;+ },+ };+ }, { services: ["account","calendar","ckdatabasews","contacts","docws","drivews","notes","reminders"] });++ const page = await empty.newPage();+ const blew = [];+ page.on("pageerror", (e) => blew.push(String(e)));+ await page.goto("http://localhost:4173", { waitUntil: "networkidle" });++ for (const [screen, expect] of [+ ["Reminders", ".rem-nolists"],+ ["Calendar", ".cal-grid, .cal-month, .cal-empty"],+ ["Notes", ".cal-empty, .notes-empty"],+ ["Contacts", ".cal-empty, .contact-empty"],+ ["iCloud Drive", ".drive-rows"],+ ]) {+ await page.getByRole("button", { name: screen, exact: true }).click();+ await page.waitForTimeout(350);+ const there = await page.locator(expect).count();+ console.log(+ there > 0+ ? `PASS ${screen} is usable with nothing in the account`+ : `FAIL ${screen} shows nothing at all with an empty account [wanted ${expect}]`+ );+ if (there === 0) failures++;+ }++ // Nothing may offer a write it has nowhere to put.+ await page.getByRole("button", { name: "Calendar", exact: true }).click();+ await page.waitForTimeout(300);+ const newEvent = page.getByRole("button", { name: "New event" });+ const offered = (await newEvent.count()) > 0 && (await newEvent.isEnabled());+ console.log(+ offered+ ? "FAIL New event is offered on an account with no calendars"+ : "PASS no calendars means no event to create"+ );+ if (offered) failures++;++ console.log(+ blew.length === 0+ ? "PASS an empty account raises nothing"+ : `FAIL an empty account threw: ${blew.join(" | ")}`+ );+ if (blew.length > 0) failures++;+ await page.close();+ await empty.close();+}+await b.close();process.exitCode = collapsed && selectsBuilt && failures === 0 ? 0 : 1;diff --git a/crates/quince-icloud/src/calendar.rs b/crates/quince-icloud/src/calendar.rsindex 02c7125..815cadd 100644--- a/crates/quince-icloud/src/calendar.rs+++ b/crates/quince-icloud/src/calendar.rs@@ -236,7 +236,17 @@ impl<'a> CalendarClient<'a> {/// The window in the query is not decoration: Apple answers with the events in it, and/// sending the day the event falls on is what makes the response carry the event back so/// a caller can confirm what was stored rather than assume.+ /// Save an event, creating it where it has no guid yet.+ ///+ /// The calendar id is a path segment, so an empty one does not fail loudly — it builds+ /// `/ca/events//<guid>`, which is a different request entirely. An account with no+ /// calendars is a real account, so it is caught here rather than sent.pub async fn put_event(&self, event: &Event, ctag: Option<&str>) -> Result<Snapshot> {+ if event.calendar_guid.trim().is_empty() {+ return Err(Error::Protocol(+ "an event has to go in a calendar, and this account has none yet".into(),+ ));+ }let day = day_of(event.starts_at, event.timezone.as_deref());// What Apple already has, if this event exists. An event carries far more than this// app models — its alerts, its guests, its attachments, its link to the series it@@ -260,6 +270,9 @@ impl<'a> CalendarClient<'a> {/// `etag` is what stops a delete from landing on a version of the event someone changed/// on another device in the meantime.pub async fn delete_event(&self, event: &Event, ctag: Option<&str>) -> Result<()> {+ if event.calendar_guid.trim().is_empty() {+ return Err(Error::Protocol("that event names no calendar".into()));+ }let day = day_of(event.starts_at, event.timezone.as_deref());let body = serde_json::json!({"Event": { "guid": event.guid, "pGuid": event.calendar_guid, "etag": event.etag },diff --git a/crates/quince-icloud/src/drive.rs b/crates/quince-icloud/src/drive.rsindex f0d8df0..bad2854 100644--- a/crates/quince-icloud/src/drive.rs+++ b/crates/quince-icloud/src/drive.rs@@ -1014,6 +1014,9 @@ pub async fn upload(folder_id: &str,path: &std::path::Path,) -> Result<DriveItem> {+ if folder_id.trim().is_empty() {+ return Err(Error::Protocol("no folder was named to put this in".into()));+ }let name = path.file_name().and_then(|n| n.to_str())diff --git a/crates/quince-icloud/src/reminders.rs b/crates/quince-icloud/src/reminders.rsindex da6b36e..341475e 100644--- a/crates/quince-icloud/src/reminders.rs+++ b/crates/quince-icloud/src/reminders.rs@@ -869,6 +869,14 @@ pub async fn create_cloudkit(if title.is_empty() {return Err(Error::Protocol("a reminder needs a title".into()));}+ // An account with no lists is a real account — a new one, or one whose lists were all+ // deleted. Sending a reference to nothing would have Apple file the reminder somewhere+ // no device can show it, so it is refused here in words a person can act on.+ if list_guid.trim().is_empty() {+ return Err(Error::Protocol(+ "a reminder has to go in a list, and this account has none yet".into(),+ ));+ }let client = ZoneClient::new(http, ckdatabasews_root, CONTAINER, params);let record_name = format!(@@ -3053,3 +3061,98 @@ mod list_shape_tests {assert_eq!(order, vec!["List/B", "List/A", "List/NEW"]);}}++/// An account that looks nothing like the one this was built against.+///+/// Everything here was measured on one real library with nine lists, three sections and+/// seven hundred reminders. Someone installing this may have none of that: a new account with+/// no lists at all, one list and nothing in it, or a set of lists whose names and ids look+/// nothing like these. These check the shapes that account would produce.+#[cfg(test)]+mod other_accounts_tests {+ use super::*;+ use serde_json::json;++ fn list_record(name: &str, title: &str, group: bool) -> Value {+ json!({+ "recordName": name,+ "recordType": "List",+ "fields": {+ "Name": { "type": "STRING", "value": title },+ "IsGroup": { "type": "NUMBER_INT64", "value": i64::from(group) },+ }+ })+ }++ /// A brand new account: Apple answers with a zone and nothing in it.+ #[test]+ fn an_empty_account_syncs_to_an_empty_library_rather_than_failing() {+ let mut lib = quince_core::Library::in_memory().unwrap();+ let stored = apply_cloudkit(+ &mut lib,+ RemindersFetch {+ records: Vec::new(),+ token: Some("t1".into()),+ incremental: false,+ },+ )+ .unwrap();+ assert_eq!(stored.0, 0, "no lists");+ assert_eq!(stored.1, 0, "no reminders");+ assert!(lib.reminder_lists().unwrap().is_empty());+ }++ /// Every list on an account can be a group — someone who files everything in folders and+ /// has since emptied them. There is then nowhere to put a reminder, and saying so beats+ /// putting one where no device will show it.+ #[test]+ fn an_account_whose_lists_are_all_groups_offers_none_of_them() {+ let records = [+ list_record("List/A", "Work", true),+ list_record("List/B", "Home", true),+ ];+ let lists: Vec<ReminderList> = records.iter().filter_map(list_from_record).collect();+ assert!(lists.is_empty());+ }++ /// A one-list account must not be reordered into nonsense by an arrangement it predates.+ #[test]+ fn a_single_list_account_keeps_its_one_list() {+ let mut lists = vec![ReminderList {+ guid: "List/ONLY".into(),+ title: "Reminders".into(),+ colour: None,+ ctag: None,+ sort_order: 0,+ enabled: true,+ }];+ apply_list_order(&mut lists, &[]);+ assert_eq!(lists[0].sort_order, 0);+ apply_list_order(&mut lists, &["SOMETHING-ELSE".into()]);+ assert_eq!(+ lists[0].sort_order, 0,+ "an arrangement about other lists is not ours"+ );+ }++ /// Apple's own list names are translated, and a person's are whatever they typed. Nothing+ /// here may depend on a particular word.+ #[test]+ fn a_list_is_recognised_by_its_record_not_by_what_it_is_called() {+ for title in ["Erinnerungen", "रिमाइंडर", "🌈", " ", "Assignments"] {+ let parsed = list_from_record(&list_record("List/X", title, false));+ assert!(parsed.is_some(), "{title:?} must still be a list");+ }+ }++ /// A title Apple sends as empty still needs something to show.+ #[test]+ fn a_list_with_no_name_still_has_one() {+ let bare = json!({+ "recordName": "List/X",+ "recordType": "List",+ "fields": {}+ });+ assert_eq!(list_from_record(&bare).unwrap().title, "Reminders");+ }+}diff --git a/src/screens/CalendarView.tsx b/src/screens/CalendarView.tsxindex 2402922..b1241f8 100644--- a/src/screens/CalendarView.tsx+++ b/src/screens/CalendarView.tsx@@ -720,9 +720,14 @@ export function CalendarView() {day.getDate(),hour);+ // An account with no calendars has nowhere to put an event. The New+ // event button already knows that; clicking an empty hour has to know+ // it too, or it opens a form that cannot be saved.+ const target = calendars[0]?.guid;+ if (!target) return;const startsAt = Math.floor(at.getTime() / 1000);setDraft({- ...blankEvent(day, calendars[0]?.guid ?? ""),+ ...blankEvent(day, target),startsAt,endsAt: startsAt + 3600,});@@ -781,7 +786,10 @@ export function CalendarView() {<buttonclassName="quiet"disabled={busy || calendars.length === 0}- onClick={() => setDraft(blankEvent(selected, calendars[0]?.guid ?? ""))}+ onClick={() => {+ const target = calendars[0]?.guid;+ if (target) setDraft(blankEvent(selected, target));+ }}>New event</button>diff --git a/src/screens/RemindersView.tsx b/src/screens/RemindersView.tsxindex ee0a5e4..fe3088e 100644--- a/src/screens/RemindersView.tsx+++ b/src/screens/RemindersView.tsx@@ -286,6 +286,16 @@ export function RemindersView() {[readLists, readItems],);+ /**+ * The first list on an account that has none.+ *+ * Named the way Apple names the one it makes for a new account, so the two accounts end up+ * looking the same rather than this one carrying a name only this app would have chosen.+ */+ async function makeFirstList() {+ await listWrite(() => api.reminderListCreate("Reminders"));+ }+async function createList(e: React.FormEvent) {e.preventDefault();const title = newList.trim();@@ -527,6 +537,21 @@ export function RemindersView() {</p>)}+ {/*+ * An account with no lists is a real account — a new one, or one whose lists have+ * all been deleted. A reminder cannot exist outside a list, so rather than the add+ * field quietly disappearing and leaving nothing to do, this says why and offers+ * the one thing that helps.+ */}+ {lists.length === 0 && loaded && (+ <div className="rem-nolists">+ <p className="rem-nolists-line">Reminders live in lists, and there aren’t any yet.</p>+ <button className="primary" onClick={() => void makeFirstList()} disabled={syncing}>+ Create a list+ </button>+ </div>+ )}+{targetListGuid && (<form className="rem-add" onSubmit={add}><span className="tick ghost" aria-hidden="true" />diff --git a/src/styles/app.css b/src/styles/app.cssindex 6eeaa81..b8ab8b0 100644--- a/src/styles/app.css+++ b/src/styles/app.css@@ -2265,3 +2265,23 @@ button.cal-day-item:hover { background: color-mix(in srgb, var(--sheet) 92%, vargrid-template-columns: 28px 1fr;padding: 7px 9px;}++/*+ * What Reminders says on an account with no lists — a new one, or one emptied out.+ *+ * Before this the add field simply vanished and the pane sat blank, which reads as broken+ * rather than as a thing with an obvious next step.+ */+.rem-nolists {+ display: flex;+ flex-direction: column;+ align-items: flex-start;+ gap: 10px;+ padding: 18px 2px 10px;+}++.rem-nolists-line {+ margin: 0;+ color: var(--text-2);+ font-size: var(--t-13);+}