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
Screens no longer go blank while iCloud is slow; a busy iCloud is waited out
Yashwanth Kamireddi4b343a85bb40
diff --git a/crates/quince-icloud/Cargo.toml b/crates/quince-icloud/Cargo.tomlindex b4c7966..847519e 100644--- a/crates/quince-icloud/Cargo.toml+++ b/crates/quince-icloud/Cargo.toml@@ -15,7 +15,7 @@ jiff = "0.2.37"base64 = "0.22"flate2 = "1"uuid = { workspace = true }-tokio = { workspace = true, features = ["fs", "io-util"] }+tokio = { workspace = true, features = ["fs", "io-util", "time"] }futures-util = { version = "0.3", default-features = false, features = ["std"] }sha1 = "0.10"diff --git a/crates/quince-icloud/src/cloudkit.rs b/crates/quince-icloud/src/cloudkit.rsindex 71fc26c..d2fc7f9 100644--- a/crates/quince-icloud/src/cloudkit.rs+++ b/crates/quince-icloud/src/cloudkit.rs@@ -68,6 +68,11 @@ fn trouble_with(zone_result: &Value) -> Option<ZoneTrouble> {}}+/// How many times a busy CloudKit is asked before saying so.+const BUSY_TRIES: u32 = 3;+/// The longest single wait a busy CloudKit is given, whatever it asks for.+const LONGEST_WAIT: u64 = 30;+impl<'a> ZoneClient<'a> {pub fn new(http: &'a reqwest::Client,@@ -91,6 +96,49 @@ impl<'a> ZoneClient<'a> {}/// One page of changes for `zone`.+ /// POST to CloudKit, waiting out a busy server the way it asks to be waited out.+ ///+ /// Measured on the account: an overloaded CloudKit answers 503 with+ /// `{"serverErrorCode":"SERVER_OVERLOADED","retryAfter":10}`. That went to the screen as+ /// raw JSON and the write was simply lost. It is a request to come back shortly, so it is+ /// honoured — up to `BUSY_TRIES` times, never waiting more than `LONGEST_WAIT` — and only+ /// a server still busy after that is reported, in words.+ async fn post_json(&self, url: &str, body: &Value) -> Result<(reqwest::StatusCode, String)> {+ let mut tries = 0;+ loop {+ tries += 1;+ let response = self+ .http+ .post(url)+ .query(&self.query())+ .json(body)+ .send()+ .await?;+ let status = response.status();+ let header_wait = response+ .headers()+ .get("retry-after")+ .and_then(|v| v.to_str().ok())+ .and_then(|v| v.trim().parse::<u64>().ok());+ let text = response.text().await.unwrap_or_default();+ if !matches!(status.as_u16(), 429 | 503) {+ return Ok((status, text));+ }+ if tries >= BUSY_TRIES {+ eprintln!("cloudkit: still busy after {tries} tries ({status}): {text}");+ return Err(Error::Refused(+ "iCloud is busy right now. Nothing was changed — try again in a minute.".into(),+ ));+ }+ let asked = serde_json::from_str::<Value>(&text)+ .ok()+ .and_then(|v| v.get("retryAfter").and_then(Value::as_u64))+ .or(header_wait)+ .unwrap_or(2);+ tokio::time::sleep(std::time::Duration::from_secs(asked.clamp(1, LONGEST_WAIT))).await;+ }+ }+pub async fn changes(&self, zone: &str, sync_token: Option<&str>) -> Result<Page> {let mut zone_body = json!({"zoneID": { "zoneName": zone, "zoneType": "REGULAR_CUSTOM_ZONE" },@@ -107,16 +155,9 @@ impl<'a> ZoneClient<'a> {"{}/database/1/{}/production/private/changes/zone",self.base, self.container);- let response = self- .http- .post(url)- .query(&self.query())- .json(&json!({ "zones": [zone_body] }))- .send()+ let (status, text) = self+ .post_json(&url, &json!({ "zones": [zone_body] })).await?;-- let status = response.status();- let text = response.text().await.unwrap_or_default();if status.as_u16() == 450 {return Err(Error::ReauthRequired);}@@ -396,6 +437,61 @@ mod tests {})}+ fn overloaded() -> ResponseTemplate {+ // What the account sent, verbatim but for the uuid.+ ResponseTemplate::new(503).set_body_json(json!({+ "uuid": "1", "retryAfter": 1, "serverErrorCode": "SERVER_OVERLOADED"+ }))+ }++ /// A busy CloudKit asks to be asked again shortly; asked again, the change goes through+ /// instead of being lost with raw JSON on the screen.+ #[tokio::test]+ async fn an_overloaded_cloudkit_is_waited_out() {+ let server = MockServer::start().await;+ Mock::given(method("POST"))+ .and(path_regex(r".*/records/modify$"))+ .respond_with(overloaded())+ .up_to_n_times(1)+ .mount(&server)+ .await;+ Mock::given(method("POST"))+ .and(path_regex(r".*/records/modify$"))+ .respond_with(ResponseTemplate::new(200).set_body_json(json!({+ "records": [{ "recordName": "R", "recordChangeTag": "t2" }]+ })))+ .mount(&server)+ .await;+ let http = reqwest::Client::new();+ let client = ZoneClient::new(&http, &server.uri(), "com.apple.reminders", vec![]);+ client+ .update_record("Reminders", "R", "Reminder", Some("t1"), json!({}))+ .await+ .unwrap();+ }++ /// And one still busy after that is said in a sentence, not Apple's JSON.+ #[tokio::test]+ async fn a_cloudkit_that_stays_busy_says_so_plainly() {+ let server = MockServer::start().await;+ Mock::given(method("POST"))+ .and(path_regex(r".*/records/modify$"))+ .respond_with(overloaded())+ .mount(&server)+ .await;+ let http = reqwest::Client::new();+ let client = ZoneClient::new(&http, &server.uri(), "com.apple.reminders", vec![]);+ let message = client+ .update_record("Reminders", "R", "Reminder", Some("t1"), json!({}))+ .await+ .unwrap_err()+ .to_string();+ assert_eq!(+ message,+ "iCloud is busy right now. Nothing was changed — try again in a minute."+ );+ }+/// Ignoring moreComing silently truncates someone's data, so paging is the thing to test.#[tokio::test]async fn paging_follows_more_coming_to_the_end() {@@ -573,15 +669,7 @@ impl ZoneClient<'_> {"{}/database/1/{}/production/private/records/modify",self.base, self.container);- let response = self- .http- .post(url)- .query(&self.query())- .json(&body)- .send()- .await?;- let status = response.status();- let text = response.text().await.unwrap_or_default();+ let (status, text) = self.post_json(&url, &body).await?;if status.as_u16() == 450 {return Err(Error::ReauthRequired);@@ -710,18 +798,22 @@ impl ZoneClient<'_> {"records": [{ "recordName": record_name }],"zoneID": { "zoneName": zone, "zoneType": "REGULAR_CUSTOM_ZONE" },});- let response = self- .http- .post(url)- .query(&self.query())- .json(&body)- .send()- .await?;- if !response.status().is_success() {+ let (status, text) = self.post_json(&url, &body).await?;+ if status.as_u16() == 450 {+ return Err(Error::ReauthRequired);+ }+ // Nothing there is an answer; a server that failed to say is not. A busy or broken+ // lookup read as "no such record" sent callers on to create what already existed, or+ // to skip what was there.+ if status.as_u16() == 404 {return Ok(None);}- let parsed: Value =- serde_json::from_str(&response.text().await.unwrap_or_default()).unwrap_or(Value::Null);+ if !status.is_success() {+ return Err(Error::Protocol(format!(+ "CloudKit couldn't look that up ({status})"+ )));+ }+ let parsed: Value = serde_json::from_str(&text).unwrap_or(Value::Null);Ok(parsed.get("records").and_then(Value::as_array)diff --git a/crates/quince-icloud/src/drive.rs b/crates/quince-icloud/src/drive.rsindex 53c3d34..8b7a2de 100644--- a/crates/quince-icloud/src/drive.rs+++ b/crates/quince-icloud/src/drive.rs@@ -62,6 +62,29 @@ pub async fn sync_folder(library: &mut quince_core::Library,folder_id: &str,) -> Result<usize> {+ let items = fetch_folder(http, root, params, folder_id).await?;+ store_folder(library, folder_id, &items)+}++/// Store a folder's contents fetched by [`fetch_folder`].+pub fn store_folder(+ library: &mut quince_core::Library,+ folder_id: &str,+ items: &[DriveItem],+) -> Result<usize> {+ library.put_drive_children(folder_id, items)?;+ library.mark_synced("drive", None)?;+ Ok(items.len())+}++/// Ask Apple for one folder's contents. Touches no local state, so it can run without+/// holding the library every screen reads.+pub async fn fetch_folder(+ http: &reqwest::Client,+ root: &str,+ params: Vec<(String, String)>,+ folder_id: &str,+) -> Result<Vec<DriveItem>> {let mut query = params;query.push(("clientVersion".into(), "2.1".into()));@@ -87,10 +110,7 @@ pub async fn sync_folder(let parsed: Value = serde_json::from_str(&text).map_err(|e| Error::Protocol(format!("Drive returned invalid JSON: {e}")))?;- let items = parse_folder(&parsed);- library.put_drive_children(folder_id, &items)?;- library.mark_synced("drive", None)?;- Ok(items.len())+ Ok(parse_folder(&parsed))}/// Bare docwsid: `FILE::com.apple.CloudDocs::<uuid>` carries it after the last `::`.diff --git a/crates/quince-icloud/src/sync.rs b/crates/quince-icloud/src/sync.rsindex d0fe4a9..db5ecee 100644--- a/crates/quince-icloud/src/sync.rs+++ b/crates/quince-icloud/src/sync.rs@@ -117,6 +117,17 @@ pub async fn fetch_calendar(})}+/// The change tag Apple last gave an event's calendar, which a write carries.+#[must_use]+pub fn calendar_ctag(library: &Library, calendar_guid: &str) -> Option<String> {+ library+ .calendars()+ .ok()?+ .into_iter()+ .find(|c| c.guid == calendar_guid)+ .and_then(|c| c.ctag)+}+/// Create an event, or save changes to one, and store what Apple answers with.////// Apple takes the whole event on every write, so an edit is the event as it should end up@@ -129,42 +140,55 @@ pub async fn put_event(library: &mut Library,event: &quince_core::calendar::Event,) -> Result<()> {- let client = CalendarClient::new(http, root, params);- let ctag = library- .calendars()?- .into_iter()- .find(|c| c.guid == event.calendar_guid)- .and_then(|c| c.ctag);+ let ctag = calendar_ctag(library, &event.calendar_guid);+ let kept = save_event(http, root, params, ctag.as_deref(), event).await?;+ store_events(library, kept)+}- let answer = client.put_event(event, ctag.as_deref()).await?;+/// The network half of [`put_event`]: write the event, and return Apple's own copy of it.+///+/// Kept apart so a caller can do it without holding the library — everything on screen+/// reads that library, and a save that held it while Apple was slow froze every screen.+pub async fn save_event(+ http: &reqwest::Client,+ root: &str,+ params: Vec<(String, String)>,+ ctag: Option<&str>,+ event: &quince_core::calendar::Event,+) -> Result<Vec<quince_core::calendar::Event>> {+ let client = CalendarClient::new(http, root, params);+ let answer = client.put_event(event, ctag).await?;// What goes into the library is what Apple holds, never what was sent. Measured: a save// to the account answers with an empty list, and storing the sent copy instead kept an// event with no etag — so the next edit or delete went without one — and, where Apple// had not kept it, a ghost that could never be deleted. So an empty answer is followed// by asking for the event's day and taking Apple's own copy.- let stored: Vec<_> = if answer.events.iter().any(|e| e.guid == event.guid) {- answer.events- } else {- let zone = crate::calendar::event_zone(event);- let day = crate::calendar::day_of(event.starts_at, zone.as_deref());- let tz = zone.as_deref().unwrap_or("UTC");- let kept: Vec<_> = client- .events(&day, &day, tz)- .await?- .events- .into_iter()- .filter(|e| e.guid == event.guid)- .collect();- if kept.is_empty() {- return Err(Error::Protocol(- "iCloud took the event but did not keep it — nothing was saved".into(),- ));- }- kept- };+ if answer.events.iter().any(|e| e.guid == event.guid) {+ return Ok(answer.events);+ }+ let zone = crate::calendar::event_zone(event);+ let day = crate::calendar::day_of(event.starts_at, zone.as_deref());+ let tz = zone.as_deref().unwrap_or("UTC");+ let kept: Vec<_> = client+ .events(&day, &day, tz)+ .await?+ .events+ .into_iter()+ .filter(|e| e.guid == event.guid)+ .collect();+ if kept.is_empty() {+ return Err(Error::Protocol(+ "iCloud took the event but did not keep it — nothing was saved".into(),+ ));+ }+ Ok(kept)+}++/// The library half of [`put_event`]: store what Apple kept, in calendars this library has.+pub fn store_events(library: &mut Library, kept: Vec<quince_core::calendar::Event>) -> Result<()> {let known: std::collections::HashSet<String> =library.calendars()?.into_iter().map(|c| c.guid).collect();- let storable: Vec<_> = stored+ let storable: Vec<_> = kept.into_iter().filter(|e| known.contains(&e.calendar_guid)).collect();@@ -180,13 +204,10 @@ pub async fn delete_event(library: &mut Library,event: &quince_core::calendar::Event,) -> Result<()> {- let client = CalendarClient::new(http, root, params);- let ctag = library- .calendars()?- .into_iter()- .find(|c| c.guid == event.calendar_guid)- .and_then(|c| c.ctag);- client.delete_event(event, ctag.as_deref()).await?;+ let ctag = calendar_ctag(library, &event.calendar_guid);+ CalendarClient::new(http, root, params)+ .delete_event(event, ctag.as_deref())+ .await?;library.forget_events(std::slice::from_ref(&event.guid))?;Ok(())}diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rsindex 9c6d47f..dff7006 100644--- a/src-tauri/src/main.rs+++ b/src-tauri/src/main.rs@@ -61,13 +61,64 @@ async fn resync_reminders(params: Vec<(String, String)>,data: &State<'_, Data>,) -> Result<(), String> {- let mut library = data.0.lock().await;- let synced = quince_icloud::reminders::sync_cloudkit(http, root, params, &mut library, None)+ refresh_reminders(http, root, params, data, true).await+}++/// Ask Apple what changed in Reminders and store it — without holding the library while+/// Apple answers.+///+/// Every screen reads that library. A refresh that held it across the network made every+/// screen wait on Apple: when CloudKit was slow or overloaded (503, retry in 10s), Reminders,+/// Notes and the rest drew nothing at all until it gave up. The fetch runs unlocked; the+/// library is held only to store what came back.+async fn refresh_reminders(+ http: &reqwest::Client,+ root: &str,+ params: Vec<(String, String)>,+ data: &State<'_, Data>,+ whole: bool,+) -> Result<(), String> {+ let since = if whole {+ None+ } else {+ data.0+ .lock()+ .await+ .sync_token("reminders")+ .map_err(|e| e.to_string())?+ };+ let fetched = quince_icloud::reminders::fetch_cloudkit(http, root, params, since.as_deref()).await- .map(|_| ())- .map_err(|e| e.to_string());+ .map_err(|e| e.to_string())?;+ {+ let mut library = data.0.lock().await;+ quince_icloud::reminders::apply_cloudkit(&mut library, fetched)+ .map_err(|e| e.to_string())?;+ }alerts::changed();- synced+ Ok(())+}++/// The same for Notes.+async fn refresh_notes(+ http: &reqwest::Client,+ root: &str,+ params: Vec<(String, String)>,+ data: &State<'_, Data>,+) -> Result<(), String> {+ let since = data+ .0+ .lock()+ .await+ .sync_token("notes")+ .map_err(|e| e.to_string())?;+ let fetched = quince_icloud::notes::fetch_cloudkit(http, root, params, since.as_deref())+ .await+ .map_err(|e| e.to_string())?;+ let mut library = data.0.lock().await;+ quince_icloud::notes::apply_cloudkit(&mut library, fetched)+ .map(|_| ())+ .map_err(|e| e.to_string())}async fn cloudkit_context(@@ -252,10 +303,12 @@ async fn calendar_sync((client.http().clone(), root, client.service_params())};- let mut library = data.0.lock().await;- quince_icloud::sync::calendar(&http, &root, params, &mut library, &from, &to, &timezone)+ // Asked of Apple unlocked; the library is held only to store the answer.+ let fetched = quince_icloud::sync::fetch_calendar(&http, &root, params, &from, &to, &timezone).await- .map_err(|e| e.to_string())+ .map_err(|e| e.to_string())?;+ let mut library = data.0.lock().await;+ quince_icloud::sync::apply_calendar(&mut library, fetched).map_err(|e| e.to_string())}/// What the interface sends to create or change an event.@@ -333,10 +386,12 @@ async fn event_save(etag: existing.and_then(|e| e.etag),};- let mut library = data.0.lock().await;- quince_icloud::sync::put_event(&http, &root, params, &mut library, &event)+ let ctag = quince_icloud::sync::calendar_ctag(&*data.0.lock().await, &event.calendar_guid);+ let kept = quince_icloud::sync::save_event(&http, &root, params, ctag.as_deref(), &event).await.map_err(|e| e.to_string())?;+ let mut library = data.0.lock().await;+ quince_icloud::sync::store_events(&mut library, kept).map_err(|e| e.to_string())?;Ok(guid)}@@ -350,9 +405,14 @@ async fn event_delete(guid: String, auth: State<'_, Auth>, data: State<'_, Data>.map_err(|e| e.to_string())?.ok_or("That event is no longer in the local library.")?};- let mut library = data.0.lock().await;- quince_icloud::sync::delete_event(&http, &root, params, &mut library, &event)+ let ctag = quince_icloud::sync::calendar_ctag(&*data.0.lock().await, &event.calendar_guid);+ quince_icloud::calendar::CalendarClient::new(&http, &root, params)+ .delete_event(&event, ctag.as_deref()).await+ .map_err(|e| e.to_string())?;+ let mut library = data.0.lock().await;+ library+ .forget_events(std::slice::from_ref(&event.guid)).map_err(|e| e.to_string())}@@ -464,13 +524,7 @@ async fn set_done(.await.map_err(|e| e.to_string())?;- let mut library = data.0.lock().await;- let since = library.sync_token("reminders").map_err(|e| e.to_string())?;- quince_icloud::reminders::sync_cloudkit(&http, &root, params, &mut library, since.as_deref())- .await- .map_err(|e| e.to_string())?;- alerts::changed();- Ok(())+ refresh_reminders(&http, &root, params, data, false).await}/// Set or clear how often a reminder comes back.@@ -538,13 +592,7 @@ async fn reminder_create(.await.map_err(|e| e.to_string())?;- let mut library = data.0.lock().await;- let since = library.sync_token("reminders").map_err(|e| e.to_string())?;- quince_icloud::reminders::sync_cloudkit(&http, &root, params, &mut library, since.as_deref())- .await- .map_err(|e| e.to_string())?;- alerts::changed();- Ok(())+ refresh_reminders(&http, &root, params, &data, false).await}#[tauri::command]@@ -570,13 +618,7 @@ async fn reminder_delete(.await.map_err(|e| e.to_string())?;- let mut library = data.0.lock().await;- let since = library.sync_token("reminders").map_err(|e| e.to_string())?;- quince_icloud::reminders::sync_cloudkit(&http, &root, params, &mut library, since.as_deref())- .await- .map_err(|e| e.to_string())?;- alerts::changed();- Ok(())+ refresh_reminders(&http, &root, params, &data, false).await}/// Apply an edit — title, notes, due date, flag, completion — in one write.@@ -622,13 +664,7 @@ async fn reminder_edit(.map_err(|e| e.to_string())?;}- let mut library = data.0.lock().await;- let since = library.sync_token("reminders").map_err(|e| e.to_string())?;- quince_icloud::reminders::sync_cloudkit(&http, &root, params, &mut library, since.as_deref())- .await- .map_err(|e| e.to_string())?;- alerts::changed();- Ok(())+ refresh_reminders(&http, &root, params, &data, false).await}/// One of Apple's smart lists. `until` is the end of today in the viewer's own timezone,@@ -699,12 +735,7 @@ async fn resync_notes(params: Vec<(String, String)>,data: &State<'_, Data>,) -> Result<(), String> {- let mut library = data.0.lock().await;- let since = library.sync_token("notes").map_err(|e| e.to_string())?;- quince_icloud::notes::sync_cloudkit(http, root, params, &mut library, since.as_deref())- .await- .map(|_| ())- .map_err(|e| e.to_string())+ refresh_notes(http, root, params, data).await}/// One note, by record name. `None` once Apple no longer has it.@@ -993,10 +1024,11 @@ async fn drive_sync_folder(.ok_or("Apple hasn't offered iCloud Drive for this account.")?;(client.http().clone(), root, client.service_params())};- let mut library = data.0.lock().await;- quince_icloud::drive::sync_folder(&http, &root, params, &mut library, &folder_id)+ let items = quince_icloud::drive::fetch_folder(&http, &root, params, &folder_id).await- .map_err(|e| e.to_string())+ .map_err(|e| e.to_string())?;+ let mut library = data.0.lock().await;+ quince_icloud::drive::store_folder(&mut library, &folder_id, &items).map_err(|e| e.to_string())}#[tauri::command]@@ -1034,9 +1066,11 @@ async fn resync_drive_folder(data: &State<'_, Data>,folder_id: &str,) -> Result<(), String> {- let mut library = data.0.lock().await;- quince_icloud::drive::sync_folder(http, root, params, &mut library, folder_id)+ let items = quince_icloud::drive::fetch_folder(http, root, params, folder_id).await+ .map_err(|e| e.to_string())?;+ let mut library = data.0.lock().await;+ quince_icloud::drive::store_folder(&mut library, folder_id, &items).map(|_| ()).map_err(|e| e.to_string())}diff --git a/src/components/Notice.tsx b/src/components/Notice.tsxnew file mode 100644index 0000000..f44c81d--- /dev/null+++ b/src/components/Notice.tsx@@ -0,0 +1,19 @@+import { TriangleAlert, X } from "lucide-react";++/**+ * Something went wrong, said once and plainly, beside a way to put it away.+ *+ * Every screen showed failures as a bare red line — on Reminders, CloudKit's own JSON in+ * full — that stayed until something else replaced it.+ */+export function Notice({ message, onDismiss }: { message: string; onDismiss: () => void }) {+ return (+ <div className="notice" role="alert">+ <TriangleAlert size={15} strokeWidth={2} aria-hidden="true" />+ <p>{message}</p>+ <button className="notice-close" aria-label="Dismiss" title="Dismiss" onClick={onDismiss}>+ <X size={14} strokeWidth={2.25} aria-hidden="true" />+ </button>+ </div>+ );+}diff --git a/src/screens/ContactsView.tsx b/src/screens/ContactsView.tsxindex a891fb1..2b8f4fb 100644--- a/src/screens/ContactsView.tsx+++ b/src/screens/ContactsView.tsx@@ -1,4 +1,5 @@import { useCallback, useEffect, useMemo, useState } from "react";+import { Notice } from "../components/Notice";import { ChevronLeft } from "lucide-react";import {api,@@ -202,7 +203,7 @@ export function ContactsView() {type="search"/>- {error && <p className="error" role="alert">{error}</p>}+ {error && <Notice message={error} onDismiss={() => setError(null)} />}<ul className="contact-rows">{contacts.map((contact) => (diff --git a/src/screens/DriveView.tsx b/src/screens/DriveView.tsxindex 5d4090c..ee102a7 100644--- a/src/screens/DriveView.tsx+++ b/src/screens/DriveView.tsx@@ -1,4 +1,5 @@import { useCallback, useEffect, useRef, useState } from "react";+import { Notice } from "../components/Notice";import { open as openFileDialog } from "@tauri-apps/plugin-dialog";import { getCurrentWebview } from "@tauri-apps/api/webview";import {@@ -399,9 +400,7 @@ export function DriveView() {</header>{error && (- <p className="error" role="alert">- {error}- </p>+ <Notice message={error} onDismiss={() => setError(null)} />)}{savedTo && (<p className="drive-saved" role="status">diff --git a/src/screens/NotesView.tsx b/src/screens/NotesView.tsxindex b14b916..dc173d9 100644--- a/src/screens/NotesView.tsx+++ b/src/screens/NotesView.tsx@@ -1,4 +1,5 @@import { Fragment, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";+import { Notice } from "../components/Notice";import { flushSync } from "react-dom";import { ChevronLeft, Folder, FolderOpen, Pin, PinOff, SquarePen, Trash2 } from "lucide-react";import { LongTextarea } from "../components/LongTextarea";@@ -498,7 +499,7 @@ export function NotesView() {/></div>- {error && <p className="error" role="alert">{error}</p>}+ {error && <Notice message={error} onDismiss={() => setError(null)} />}<div className="note-rows" role="list">{sections.map((section) => (diff --git a/src/screens/RemindersView.tsx b/src/screens/RemindersView.tsxindex 399692a..b1e9cfb 100644--- a/src/screens/RemindersView.tsx+++ b/src/screens/RemindersView.tsx@@ -1,4 +1,5 @@import { Fragment, useCallback, useEffect, useMemo, useState } from "react";+import { Notice } from "../components/Notice";import { ChevronLeft } from "lucide-react";import {api,@@ -921,9 +922,7 @@ export function RemindersView() {)}{error && (- <p className="rx-error" role="alert">- {error}- </p>+ <Notice message={error} onDismiss={() => setError(null)} />)}{/* An account with no lists: a reminder cannot exist outside one, so the one thingdiff --git a/src/screens/calendar/CalendarView.tsx b/src/screens/calendar/CalendarView.tsxindex b883ff5..71dbe08 100644--- a/src/screens/calendar/CalendarView.tsx+++ b/src/screens/calendar/CalendarView.tsx@@ -1,4 +1,4 @@-import { TriangleAlert, X } from "lucide-react";+import { Notice } from "../../components/Notice";import { Fragment, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";import {api,@@ -481,13 +481,7 @@ export function CalendarView() {</header>{error && (- <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>+ <Notice message={error} onDismiss={() => setError(null)} />)}{view === "month" && (diff --git a/src/styles/app.css b/src/styles/app.cssindex 4fb5419..29cbc5b 100644--- a/src/styles/app.css+++ b/src/styles/app.css@@ -1602,3 +1602,35 @@.upload-row.is-done .upload-state { color: var(--gold-strong); font-size: var(--t-13); font-weight: 700; }.upload-row.is-failed .upload-state,.upload-row.is-failed .upload-where { color: var(--danger); }++/* Something went wrong: said once, plainly, beside a way to put it away. Shared by every+ screen. */+.notice {+ display: flex;+ align-items: flex-start;+ gap: 8px;+ margin: 0 0 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;+}+.notice > svg { flex: none; margin-top: 2px; color: var(--danger); }+.notice p { flex: 1; min-width: 0; margin: 0; }+.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;+}+.notice-close:hover { background: color-mix(in srgb, var(--text) 10%, transparent); color: var(--text); }+.notice-close:focus-visible { outline: 3px solid var(--gold-ring); }diff --git a/src/styles/calendar.css b/src/styles/calendar.cssindex 544ec42..8f48c75 100644--- a/src/styles/calendar.css+++ b/src/styles/calendar.css@@ -184,37 +184,7 @@}.cx-icon:focus-visible, .cx-today:focus-visible { outline: 3px solid color-mix(in srgb, var(--sys-blue) 40%, transparent); }-/* 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); }+.cx .notice { margin: 0 18px 10px; }/* ---- month ---------------------------------------------------------------------- */diff --git a/src/styles/reminders.css b/src/styles/reminders.cssindex c607a79..d82289a 100644--- a/src/styles/reminders.css+++ b/src/styles/reminders.css@@ -307,7 +307,6 @@.rx-link.danger { color: var(--sys-red); }.rx-link:disabled { opacity: 0.5; }-.rx-error { margin: 0 14px 8px 0; color: var(--danger); font-size: var(--t-13); }.rx-capped {margin: 0 14px 8px 0;