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
Calendar: errors are plain sentences, in a notice that can be put away
Yashwanth Kamireddi280270cdfb3e
diff --git a/.uiverify/calendar.mjs b/.uiverify/calendar.mjsindex f0a541f..d7afa73 100644--- a/.uiverify/calendar.mjs+++ b/.uiverify/calendar.mjs@@ -24,6 +24,7 @@ await ctx.addInitScript(() => {{ ...r("d", "Done already", at(16)), completedAt: at(16) }, r("s", "Study", at(19))];if (cmd === "calendar_sync") return { calendars: 1, events: 0 };if (cmd === "event_save") { (window.__saved ??= []).push(args.draft); return "E-new"; }+ if (cmd === "event_delete") throw "iCloud didn't accept that change, so nothing was saved.";if (cmd === "sync_all" || cmd === "sync_status") return { services: [], asOf: 1, tookMs: 0 };if (cmd === "plugin:event|listen") return 0;return [];@@ -218,6 +219,31 @@ ok(/Sep/.test(title) && /Oct/.test(title), `a week across two months is named foawait tall.close();}+// A delete iCloud turns down says so in a sentence, with a way to put it away — not a red+// line of the request and Apple's JSON under the toolbar.+{+ const p = await ctx.newPage();+ await p.goto("http://localhost:4173", { waitUntil: "networkidle" });+ await p.getByRole("button", { name: "Week", exact: true }).click();+ await p.waitForTimeout(300);+ await p.locator(".cx-block", { hasText: "New Event" }).first().click();+ await p.waitForTimeout(250);+ await p.locator(".cx-pop-delete").click();+ await p.waitForTimeout(300);+ const notice = await p.evaluate(() => {+ const n = document.querySelector('[role="alert"]');+ return n && { text: n.textContent.trim(), dismiss: Boolean(n.querySelector('button[aria-label="Dismiss"]')) };+ });+ ok(notice?.text === "iCloud didn't accept that change, so nothing was saved." && notice.dismiss,+ "a refused delete says so in a sentence, with Dismiss", `the notice: ${JSON.stringify(notice)}`);+ if (notice?.dismiss) {+ await p.getByRole("button", { name: "Dismiss" }).click();+ await p.waitForTimeout(150);+ ok((await p.locator('[role="alert"]').count()) === 0, "and Dismiss puts it away", "Dismiss left the notice up");+ }+ await p.close();+}+// A small window: the title is shortened, never cut, and a month cell with room for a line// shows an event in it rather than only "N more".{diff --git a/crates/quince-icloud/src/calendar.rs b/crates/quince-icloud/src/calendar.rsindex c354e2f..5a9ab40 100644--- a/crates/quince-icloud/src/calendar.rs+++ b/crates/quince-icloud/src/calendar.rs@@ -187,6 +187,33 @@ fn client_state(calendar_guid: &str, ctag: Option<&str>) -> Value {})}+/// What to tell someone when Apple's calendar turns a request down.+///+/// The screen showed what Apple sent — `/ca/events/work/4186… returned 404 Not Found:+/// {"ChangeSet":…}` — which says nothing to a person about what happened or what to do. The+/// sentence says that; the path, status and body go to the log for whoever has to look.+fn refusal(path: &str, status: reqwest::StatusCode, body: &str) -> Error {+ eprintln!(+ "calendar: {path} answered {status}: {}",+ body.chars().take(300).collect::<String>()+ );+ match status.as_u16() {+ 409 | 412 => Error::Conflict,+ 400 | 422 => Error::Refused("iCloud didn't accept that change, so nothing was saved.".into()),+ 401 | 403 => Error::Refused(+ "iCloud won't let this calendar be changed from here — it may be read-only.".into(),+ ),+ 429 => Error::Refused("iCloud asked Quince to slow down. Try again in a minute.".into()),+ 500..=599 => Error::Refused(+ "iCloud's calendar isn't answering right now. Nothing was changed — try again in a moment."+ .into(),+ ),+ code => Error::Refused(format!(+ "iCloud's calendar turned that down (status {code}). Nothing was changed."+ )),+ }+}+/// Everything one calendar refresh yields.#[derive(Debug, Default)]pub struct Snapshot {@@ -475,10 +502,7 @@ impl<'a> CalendarClient<'a> {return Err(Error::NotFound);}if !status.is_success() {- return Err(Error::Protocol(format!(- "{path} returned {status}: {}",- text.chars().take(200).collect::<String>()- )));+ return Err(refusal(path, status, &text));}Ok(serde_json::from_str(&text).unwrap_or(Value::Null))}@@ -511,10 +535,7 @@ impl<'a> CalendarClient<'a> {return Err(Error::NotFound);}if !status.is_success() {- return Err(Error::Protocol(format!(- "{path} returned {status}: {}",- text.chars().take(160).collect::<String>()- )));+ return Err(refusal(path, status, &text));}serde_json::from_str(&text).map_err(|e| Error::Protocol(format!("{path} returned invalid JSON: {e}")))@@ -1004,8 +1025,11 @@ mod write_tests {.await.unwrap_err().to_string();- assert!(message.contains("400"), "{message}");- assert!(message.contains("bad event"), "{message}");+ // A sentence saying what happened, not the request and Apple's body.+ assert_eq!(+ message,+ "iCloud didn't accept that change, so nothing was saved."+ );}}diff --git a/crates/quince-icloud/src/lib.rs b/crates/quince-icloud/src/lib.rsindex 6428b0c..f046279 100644--- a/crates/quince-icloud/src/lib.rs+++ b/crates/quince-icloud/src/lib.rs@@ -24,6 +24,10 @@ pub enum Error {ReauthRequired,#[error("this changed on another device first — refresh and try again")]Conflict,+ /// Apple turned a request down, said in words a person can act on. What Apple actually+ /// sent goes to the log, not the screen: a path and a JSON body told nobody anything.+ #[error("{0}")]+ Refused(String),/// Apple has no such record — it was deleted elsewhere, or never kept.#[error("that is no longer in iCloud")]NotFound,diff --git a/src/screens/calendar/CalendarView.tsx b/src/screens/calendar/CalendarView.tsxindex 1b620d2..b883ff5 100644--- a/src/screens/calendar/CalendarView.tsx+++ b/src/screens/calendar/CalendarView.tsx@@ -1,3 +1,4 @@+import { TriangleAlert, X } from "lucide-react";import { Fragment, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";import {api,@@ -480,9 +481,13 @@ export function CalendarView() {</header>{error && (- <p className="cx-error" role="alert">- {error}- </p>+ <div className="cx-notice" role="alert">+ <TriangleAlert size={15} strokeWidth={2} aria-hidden="true" />+ <p>{error}</p>+ <button className="cx-notice-close" aria-label="Dismiss" title="Dismiss" onClick={() => setError(null)}>+ <X size={14} strokeWidth={2.25} aria-hidden="true" />+ </button>+ </div>)}{view === "month" && (diff --git a/src/styles/calendar.css b/src/styles/calendar.cssindex f00fd0c..544ec42 100644--- a/src/styles/calendar.css+++ b/src/styles/calendar.css@@ -184,7 +184,37 @@}.cx-icon:focus-visible, .cx-today:focus-visible { outline: 3px solid color-mix(in srgb, var(--sys-blue) 40%, transparent); }-.cx-error { margin: 0 18px 8px; color: var(--danger); font-size: var(--t-13); }+/* Something went wrong: said once, plainly, beside a way to put it away — not a red line of+ Apple's own words squeezed under the toolbar. */+.cx-notice {+ display: flex;+ align-items: flex-start;+ gap: 8px;+ margin: 0 18px 10px;+ padding: 8px 8px 8px 12px;+ border-radius: 10px;+ background: color-mix(in srgb, var(--danger) 12%, transparent);+ color: var(--text);+ font-size: var(--t-13);+ line-height: 1.4;+}+.cx-notice > svg { flex: none; margin-top: 2px; color: var(--danger); }+.cx-notice p { flex: 1; min-width: 0; margin: 0; }+.cx-notice-close {+ display: grid;+ place-items: center;+ flex: none;+ width: 22px;+ height: 22px;+ padding: 0;+ border: 0;+ border-radius: 6px;+ background: none;+ color: var(--text-2);+ cursor: default;+}+.cx-notice-close:hover { background: color-mix(in srgb, var(--text) 10%, transparent); color: var(--text); }+.cx-notice-close:focus-visible { outline: 3px solid var(--gold-ring); }/* ---- month ---------------------------------------------------------------------- */