Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Reminder alerts on the desktop, with the window closed

Yashwanth Kamireddif8e377a81d30
diff --git a/Cargo.lock b/Cargo.lock
index 4d70807..d108e0d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -116,6 +116,20 @@ dependencies = [
"tokio",
]
+[[package]]
+name = "async-executor"
+version = "1.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c96bf972d85afc50bf5ab8fe2d54d1586b4e0b46c97c50a0c9e71e2f7bcd812a"
+dependencies = [
+ "async-task",
+ "concurrent-queue",
+ "fastrand",
+ "futures-lite",
+ "pin-project-lite",
+ "slab",
+]
+
[[package]]
name = "async-io"
version = "2.6.0"
@@ -2366,6 +2380,20 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154"
+[[package]]
+name = "mac-notification-sys"
+version = "0.6.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fd604973958ddcc11b561193c0fb96ba146506ef2f231ef2e7c35fd2cbc9beca"
+dependencies = [
+ "cc",
+ "log",
+ "objc2",
+ "objc2-foundation",
+ "time",
+ "uuid",
+]
+
[[package]]
name = "markup5ever"
version = "0.38.0"
@@ -2513,6 +2541,20 @@ dependencies = [
"memoffset",
]
+[[package]]
+name = "notify-rust"
+version = "4.18.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fe430c879247371c47fdedd328ad4e301e6b30b533c5fd5db1c06d75253d0e46"
+dependencies = [
+ "futures-lite",
+ "log",
+ "mac-notification-sys",
+ "serde",
+ "tauri-winrt-notification",
+ "zbus 5.19.0",
+]
+
[[package]]
name = "num"
version = "0.4.3"
@@ -3184,6 +3226,7 @@ dependencies = [
"anyhow",
"futures-util",
"jiff",
+ "notify-rust",
"quince-auth",
"quince-core",
"quince-icloud",
@@ -3194,8 +3237,11 @@ dependencies = [
"tauri",
"tauri-build",
"tauri-plugin-dialog",
+ "tauri-plugin-single-instance",
+ "tempfile",
"tokio",
"uuid",
+ "zbus 5.19.0",
]
[[package]]
@@ -3839,7 +3885,7 @@ dependencies = [
"rand 0.8.8",
"serde",
"sha2",
- "zbus",
+ "zbus 4.4.0",
]
[[package]]
@@ -4320,7 +4366,7 @@ dependencies = [
"tao-macros",
"unicode-segmentation",
"url",
- "windows",
+ "windows 0.61.3",
"windows-core 0.61.2",
"windows-version",
"x11-dl",
@@ -4360,6 +4406,7 @@ dependencies = [
"gtk",
"heck 0.5.0",
"http",
+ "image",
"jni",
"libc",
"log",
@@ -4391,7 +4438,7 @@ dependencies = [
"webkit2gtk",
"webview2-com",
"window-vibrancy",
- "windows",
+ "windows 0.61.3",
]
[[package]]
@@ -4514,6 +4561,22 @@ dependencies = [
"url",
]
+[[package]]
+name = "tauri-plugin-single-instance"
+version = "2.4.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "db817fe9295e19b7d8357e900af31edb93703dd9fb6de524b007b47b6afc63b0"
+dependencies = [
+ "serde",
+ "serde_json",
+ "tauri",
+ "thiserror 2.0.20",
+ "tokio",
+ "tracing",
+ "windows-sys 0.60.2",
+ "zbus 5.19.0",
+]
+
[[package]]
name = "tauri-runtime"
version = "2.11.3"
@@ -4536,7 +4599,7 @@ dependencies = [
"url",
"webkit2gtk",
"webview2-com",
- "windows",
+ "windows 0.61.3",
]
[[package]]
@@ -4561,7 +4624,7 @@ dependencies = [
"url",
"webkit2gtk",
"webview2-com",
- "windows",
+ "windows 0.61.3",
"wry",
]
@@ -4614,6 +4677,17 @@ dependencies = [
"toml 1.1.6+spec-1.1.0",
]
+[[package]]
+name = "tauri-winrt-notification"
+version = "0.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f37a6c354fd28fc9e322ed9bd47e3959576dad28c9d58ea1cf888cce1c7ccb36"
+dependencies = [
+ "thiserror 2.0.20",
+ "windows 0.62.2",
+ "windows-version",
+]
+
[[package]]
name = "tempfile"
version = "3.27.0"
@@ -5387,7 +5461,7 @@ checksum = "7130243a7a5b33c54a444e54842e6a9e133de08b5ad7b5861cd8ed9a6a5bc96a"
dependencies = [
"webview2-com-macros",
"webview2-com-sys",
- "windows",
+ "windows 0.61.3",
"windows-core 0.61.2",
"windows-implement",
"windows-interface",
@@ -5411,7 +5485,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "381336cfffd772377d291702245447a5251a2ffa5bad679c99e61bc48bacbf9c"
dependencies = [
"thiserror 2.0.20",
- "windows",
+ "windows 0.61.3",
"windows-core 0.61.2",
]
@@ -5467,11 +5541,23 @@ version = "0.61.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893"
dependencies = [
- "windows-collections",
+ "windows-collections 0.2.0",
"windows-core 0.61.2",
- "windows-future",
+ "windows-future 0.2.1",
"windows-link 0.1.3",
- "windows-numerics",
+ "windows-numerics 0.2.0",
+]
+
+[[package]]
+name = "windows"
+version = "0.62.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580"
+dependencies = [
+ "windows-collections 0.3.2",
+ "windows-core 0.62.2",
+ "windows-future 0.3.2",
+ "windows-numerics 0.3.1",
]
[[package]]
@@ -5483,6 +5569,15 @@ dependencies = [
"windows-core 0.61.2",
]
+[[package]]
+name = "windows-collections"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "23b2d95af1a8a14a3c7367e1ed4fc9c20e0a26e79551b1454d72583c97cc6610"
+dependencies = [
+ "windows-core 0.62.2",
+]
+
[[package]]
name = "windows-core"
version = "0.61.2"
@@ -5517,7 +5612,18 @@ checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e"
dependencies = [
"windows-core 0.61.2",
"windows-link 0.1.3",
- "windows-threading",
+ "windows-threading 0.1.0",
+]
+
+[[package]]
+name = "windows-future"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb"
+dependencies = [
+ "windows-core 0.62.2",
+ "windows-link 0.2.1",
+ "windows-threading 0.2.1",
]
[[package]]
@@ -5564,6 +5670,16 @@ dependencies = [
"windows-link 0.1.3",
]
+[[package]]
+name = "windows-numerics"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26"
+dependencies = [
+ "windows-core 0.62.2",
+ "windows-link 0.2.1",
+]
+
[[package]]
name = "windows-result"
version = "0.3.4"
@@ -5702,6 +5818,15 @@ dependencies = [
"windows-link 0.1.3",
]
+[[package]]
+name = "windows-threading"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37"
+dependencies = [
+ "windows-link 0.2.1",
+]
+
[[package]]
name = "windows-version"
version = "0.1.7"
@@ -5956,7 +6081,7 @@ dependencies = [
"webkit2gtk",
"webkit2gtk-sys",
"webview2-com",
- "windows",
+ "windows 0.61.3",
"windows-core 0.61.2",
"windows-version",
"x11-dl",
@@ -6043,9 +6168,44 @@ dependencies = [
"uds_windows",
"windows-sys 0.52.0",
"xdg-home",
- "zbus_macros",
- "zbus_names",
- "zvariant",
+ "zbus_macros 4.4.0",
+ "zbus_names 3.0.0",
+ "zvariant 4.2.0",
+]
+
+[[package]]
+name = "zbus"
+version = "5.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5db4be7c075cb421e4b7ee645541604239bd243ba7c357511f4ff3a74b555907"
+dependencies = [
+ "async-broadcast",
+ "async-executor",
+ "async-io",
+ "async-lock",
+ "async-process",
+ "async-recursion",
+ "async-task",
+ "async-trait",
+ "blocking",
+ "enumflags2",
+ "event-listener",
+ "futures-core",
+ "futures-lite",
+ "hex",
+ "libc",
+ "ordered-stream",
+ "rustix",
+ "serde",
+ "serde_repr",
+ "tracing",
+ "uds_windows",
+ "uuid",
+ "windows-sys 0.61.2",
+ "winnow 1.0.4",
+ "zbus_macros 5.19.0",
+ "zbus_names 4.3.4",
+ "zvariant 5.15.0",
]
[[package]]
@@ -6058,7 +6218,22 @@ dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
- "zvariant_utils",
+ "zvariant_utils 2.1.0",
+]
+
+[[package]]
+name = "zbus_macros"
+version = "5.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2990635d09ade6df1868f72f8cac69a876a90981e8bd3c40b1be413f8dc88f40"
+dependencies = [
+ "proc-macro-crate 3.5.0",
+ "proc-macro2",
+ "quote",
+ "syn 3.0.5",
+ "zbus_names 4.3.4",
+ "zvariant 5.15.0",
+ "zvariant_utils 4.2.0",
]
[[package]]
@@ -6069,7 +6244,27 @@ checksum = "4b9b1fef7d021261cc16cba64c351d291b715febe0fa10dc3a443ac5a5022e6c"
dependencies = [
"serde",
"static_assertions",
- "zvariant",
+ "zvariant 4.2.0",
+]
+
+[[package]]
+name = "zbus_names"
+version = "4.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d8bf88b4a3ff53e883001e0e0115b297a9d53c31b9c1edd2bfdd853e3428624e"
+dependencies = [
+ "serde",
+ "winnow 1.0.4",
+ "zvariant 5.15.0",
+]
+
+[[package]]
+name = "zcheapstr"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d1afec51604565183aeb5c54c20aeab286120d4e4460f7f76e3e8bb8c0d99473"
+dependencies = [
+ "serde",
]
[[package]]
@@ -6203,7 +6398,22 @@ dependencies = [
"enumflags2",
"serde",
"static_assertions",
- "zvariant_derive",
+ "zvariant_derive 4.2.0",
+]
+
+[[package]]
+name = "zvariant"
+version = "5.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c1d34c27cc6cdd1f458427519dd6b8612f7b7e3f7b9a0b2355d041dda9869147"
+dependencies = [
+ "endi",
+ "enumflags2",
+ "serde",
+ "winnow 1.0.4",
+ "zcheapstr",
+ "zvariant_derive 5.15.0",
+ "zvariant_utils 4.2.0",
]
[[package]]
@@ -6216,7 +6426,20 @@ dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
- "zvariant_utils",
+ "zvariant_utils 2.1.0",
+]
+
+[[package]]
+name = "zvariant_derive"
+version = "5.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "864155e69b4352db0c7f374917bf45d1e0c8d17659c8b3dbf9795f3673f8c497"
+dependencies = [
+ "proc-macro-crate 3.5.0",
+ "proc-macro2",
+ "quote",
+ "syn 3.0.5",
+ "zvariant_utils 4.2.0",
]
[[package]]
@@ -6229,3 +6452,16 @@ dependencies = [
"quote",
"syn 2.0.119",
]
+
+[[package]]
+name = "zvariant_utils"
+version = "4.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bad0294361a320b694a328460dc73add56c306150f5cb6bfafc44446120008a3"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "serde",
+ "syn 3.0.5",
+ "winnow 1.0.4",
+]
diff --git a/crates/quince-core/src/alarms.rs b/crates/quince-core/src/alarms.rs
index 7553fcf..03d8695 100644
--- a/crates/quince-core/src/alarms.rs
+++ b/crates/quince-core/src/alarms.rs
@@ -34,6 +34,7 @@ pub struct DueAlarm {
/// The alarm's id, or `snooze:<reminder>` for one snoozed here.
pub key: String,
pub reminder_guid: String,
+ pub list_guid: String,
pub title: String,
pub notes: Option<String>,
pub list_title: Option<String>,
@@ -115,7 +116,7 @@ impl Library {
/// still outstanding: one ticked off anywhere says nothing more.
pub fn due_alarms(&self, now: i64) -> Result<Vec<DueAlarm>> {
let sql = format!(
- "SELECT p.key, p.reminder_guid, r.title, r.notes, l.title, p.fires_at
+ "SELECT p.key, p.reminder_guid, r.list_guid, r.title, r.notes, l.title, p.fires_at
FROM ({PENDING}) p
JOIN reminders r ON r.guid = p.reminder_guid
LEFT JOIN reminder_lists l ON l.guid = r.list_guid
@@ -129,10 +130,11 @@ impl Library {
Ok(DueAlarm {
key: row.get(0)?,
reminder_guid: row.get(1)?,
- title: row.get(2)?,
- notes: row.get(3)?,
- list_title: row.get(4)?,
- fires_at: row.get(5)?,
+ list_guid: row.get(2)?,
+ title: row.get(3)?,
+ notes: row.get(4)?,
+ list_title: row.get(5)?,
+ fires_at: row.get(6)?,
})
})?;
Ok(rows.collect::<std::result::Result<_, _>>()?)
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index c3276aa..bf23704 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -10,7 +10,7 @@ tauri-build = { version = "2", features = [] }
[dependencies]
futures-util = { version = "0.3", default-features = false, features = ["std"] }
-tauri = { version = "2", features = [] }
+tauri = { version = "2", features = ["tray-icon", "image-png"] }
quince-auth = { path = "../crates/quince-auth" }
quince-core = { path = "../crates/quince-core" }
quince-media = { workspace = true }
@@ -23,3 +23,9 @@ anyhow.workspace = true
jiff = "0.2.37"
uuid.workspace = true
tauri-plugin-dialog = "2.7.3"
+notify-rust = "4"
+zbus = "5"
+tauri-plugin-single-instance = "2"
+
+[dev-dependencies]
+tempfile = "3"
diff --git a/src-tauri/src/alerts.rs b/src-tauri/src/alerts.rs
new file mode 100644
index 0000000..f9425a1
--- /dev/null
+++ b/src-tauri/src/alerts.rs
@@ -0,0 +1,255 @@
+//! Reminder alerts on the desktop, rung when the phone would ring them.
+//!
+//! One task sleeps until the next alarm and wakes for it — no polling. It also wakes when the
+//! reminders change (a pass, or a write here), when the machine resumes from sleep (logind's
+//! `PrepareForSleep`), and at the latest every ten minutes, because a sleep measured on the
+//! monotonic clock does not count the time a machine spent suspended and a clock can be set.
+//! Every alert is recorded as rung before it is shown, so none is ever shown twice — not by
+//! two wakes racing, not after a restart.
+
+use crate::{Auth, Data};
+use quince_core::alarms::DueAlarm;
+use std::time::Duration;
+use tauri::{AppHandle, Emitter, Manager};
+use tokio::sync::Notify;
+
+/// Something that can move the next alarm has happened.
+static CHANGED: Notify = Notify::const_new();
+
+/// The longest the task sleeps without looking again.
+const LONGEST_SLEEP: Duration = Duration::from_secs(10 * 60);
+
+/// How late an alert may still be shown. An alarm missed by less — the machine was asleep,
+/// or Quince was not running — rings once when it can; one missed by more is recorded and
+/// left, so opening Quince after a week away is not a wall of old alerts.
+const STILL_WORTH_SAYING: i64 = 6 * 60 * 60;
+
+/// Snooze, as the phone offers it.
+const SNOOZE: i64 = 60 * 60;
+
+/// Emitted to the window to open a reminder an alert was clicked for.
+pub const OPEN_REMINDER: &str = "quince://open-reminder";
+
+/// Tell the task to look again: the reminders or their alarms may have changed.
+pub fn changed() {
+ CHANGED.notify_one();
+}
+
+fn now() -> i64 {
+ std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .map_or(0, |d| i64::try_from(d.as_secs()).unwrap_or(i64::MAX))
+}
+
+/// What is due now, each recorded as rung, and when to look next.
+///
+/// Recording happens here, under the library's lock, before anything is shown: whatever
+/// happens to the notification afterwards, this alert has had its one chance.
+pub fn take_due(library: &mut quince_core::Library, now: i64) -> (Vec<DueAlarm>, Option<i64>) {
+ let mut ring = Vec::new();
+ for due in library.due_alarms(now).unwrap_or_default() {
+ if library
+ .mark_alarm_fired(&due.key, due.fires_at, now)
+ .is_err()
+ {
+ // Not recorded means it could ring again; better to stay quiet than to repeat.
+ continue;
+ }
+ if now - due.fires_at <= STILL_WORTH_SAYING {
+ ring.push(due);
+ }
+ }
+ (ring, library.next_alarm_after(now).unwrap_or(None))
+}
+
+/// Start the task. It runs for the life of the process, window open or not.
+pub fn spawn(app: AppHandle) {
+ watch_for_resume();
+ tauri::async_runtime::spawn(async move {
+ loop {
+ let at = now();
+ let (ring, next) = {
+ let data = app.state::<Data>();
+ let mut library = data.0.lock().await;
+ take_due(&mut library, at)
+ };
+ for due in ring {
+ show(app.clone(), due);
+ }
+ let wait = next.map_or(LONGEST_SLEEP, |t| {
+ Duration::from_secs(u64::try_from(t - at).unwrap_or(1).max(1)).min(LONGEST_SLEEP)
+ });
+ tokio::select! {
+ () = tokio::time::sleep(wait) => {}
+ () = CHANGED.notified() => {}
+ }
+ }
+ });
+}
+
+/// Wake when the machine comes back from sleep, where logind says so. Where it cannot be
+/// asked — no system bus, no logind — the ten-minute ceiling still holds.
+fn watch_for_resume() {
+ tauri::async_runtime::spawn(async {
+ let Ok(bus) = zbus::Connection::system().await else {
+ return;
+ };
+ let Ok(logind) = zbus::Proxy::new(
+ &bus,
+ "org.freedesktop.login1",
+ "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ )
+ .await
+ else {
+ return;
+ };
+ let Ok(mut signals) = logind.receive_signal("PrepareForSleep").await else {
+ return;
+ };
+ use futures_util::StreamExt;
+ while let Some(signal) = signals.next().await {
+ // `true` on the way down, `false` on the way back up.
+ if let Ok(false) = signal.body().deserialize::<bool>() {
+ changed();
+ }
+ }
+ });
+}
+
+/// The alert, with the phone's two choices on it, waiting for an answer on its own thread.
+fn show(app: AppHandle, due: DueAlarm) {
+ std::thread::spawn(move || {
+ let body = due
+ .notes
+ .as_deref()
+ .map(str::trim)
+ .filter(|n| !n.is_empty())
+ .map(ToString::to_string)
+ .or_else(|| due.list_title.clone())
+ .unwrap_or_default();
+ let shown = notify_rust::Notification::new()
+ .appname("Quince")
+ .summary(&due.title)
+ .body(&body)
+ .icon("quince")
+ .hint(notify_rust::Hint::Category("reminder".into()))
+ .hint(notify_rust::Hint::DesktopEntry("quince".into()))
+ .hint(notify_rust::Hint::Resident(true))
+ .action("default", "Open")
+ .action("complete", "Mark as Completed")
+ .action("snooze", "Remind Me in 1 Hour")
+ .timeout(notify_rust::Timeout::Never)
+ .show();
+ let Ok(handle) = shown else {
+ return;
+ };
+ handle.wait_for_action(|action| match action {
+ "complete" => {
+ let app = app.clone();
+ let due = due.clone();
+ tauri::async_runtime::block_on(async move {
+ let auth = app.state::<Auth>();
+ let data = app.state::<Data>();
+ if let Err(e) =
+ crate::set_done(&auth, &data, &due.reminder_guid, &due.list_guid, true)
+ .await
+ {
+ eprintln!("could not complete {}: {e}", due.reminder_guid);
+ }
+ // Every open screen looks again, as after any pass.
+ let report = crate::refresh::status(&data.0).await;
+ app.emit(crate::SYNCED, &report).ok();
+ });
+ }
+ "snooze" => {
+ let app = app.clone();
+ let guid = due.reminder_guid.clone();
+ tauri::async_runtime::block_on(async move {
+ let data = app.state::<Data>();
+ let mut library = data.0.lock().await;
+ library.snooze_reminder(&guid, now() + SNOOZE).ok();
+ });
+ changed();
+ }
+ "default" => {
+ crate::show_window(&app);
+ app.emit(OPEN_REMINDER, &due.reminder_guid).ok();
+ }
+ _ => {}
+ });
+ });
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use quince_core::alarms::{Alarm, AlarmTrigger};
+ use quince_core::reminders::{Reminder, ReminderList};
+
+ fn library_with(fires: &[(&str, i64)]) -> quince_core::Library {
+ let dir = tempfile::tempdir().unwrap();
+ let mut lib = quince_core::Library::open(&dir.keep()).unwrap();
+ lib.put_reminder_lists(&[ReminderList {
+ guid: "L".into(),
+ title: "Home".into(),
+ enabled: true,
+ ..Default::default()
+ }])
+ .unwrap();
+ let mut reminders = Vec::new();
+ let mut alarms = Vec::new();
+ let mut triggers = Vec::new();
+ for (id, at) in fires {
+ reminders.push(Reminder {
+ guid: format!("R{id}"),
+ list_guid: "L".into(),
+ title: format!("Do {id}"),
+ ..Default::default()
+ });
+ alarms.push(Alarm {
+ id: format!("A{id}"),
+ reminder_guid: format!("R{id}"),
+ trigger_id: format!("T{id}"),
+ acknowledged_at: None,
+ });
+ triggers.push(AlarmTrigger {
+ id: format!("T{id}"),
+ fires_at: *at,
+ });
+ }
+ lib.put_reminders(&reminders).unwrap();
+ lib.put_alarms(&alarms, &triggers, &[], true).unwrap();
+ lib
+ }
+
+ #[test]
+ fn a_due_alert_is_taken_once_and_the_next_is_named() {
+ let mut lib = library_with(&[("now", 1_000_000), ("later", 1_003_600)]);
+ let (ring, next) = take_due(&mut lib, 1_000_000);
+ assert_eq!(
+ ring.iter().map(|d| d.title.as_str()).collect::<Vec<_>>(),
+ ["Do now"]
+ );
+ assert_eq!(next, Some(1_003_600));
+ // A second wake at the same moment — resume and a pass together — rings nothing.
+ let (again, _) = take_due(&mut lib, 1_000_000);
+ assert!(again.is_empty());
+ }
+
+ #[test]
+ fn missed_while_away_rings_once_but_long_gone_stays_quiet() {
+ let now = 10_000_000;
+ let mut lib = library_with(&[
+ ("an hour ago", now - 3_600),
+ ("last week", now - 7 * 86_400),
+ ]);
+ let (ring, _) = take_due(&mut lib, now);
+ assert_eq!(
+ ring.iter().map(|d| d.title.as_str()).collect::<Vec<_>>(),
+ ["Do an hour ago"]
+ );
+ // And the old one is recorded, not left to surface later.
+ assert!(lib.due_alarms(now).unwrap().is_empty());
+ }
+}
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 61e80ee..9c6d47f 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -1,6 +1,7 @@
// Quince — desktop shell.
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
+mod alerts;
mod refresh;
use quince_auth::{Client, SignInOutcome, TwoFactorOptions};
@@ -61,10 +62,12 @@ async fn resync_reminders(
data: &State<'_, Data>,
) -> Result<(), String> {
let mut library = data.0.lock().await;
- quince_icloud::reminders::sync_cloudkit(http, root, params, &mut library, None)
+ let synced = quince_icloud::reminders::sync_cloudkit(http, root, params, &mut library, None)
.await
.map(|_| ())
- .map_err(|e| e.to_string())
+ .map_err(|e| e.to_string());
+ alerts::changed();
+ synced
}
async fn cloudkit_context(
@@ -434,12 +437,23 @@ async fn reminder_set_done(
auth: State<'_, Auth>,
data: State<'_, Data>,
) -> UiResult<()> {
- let (http, root, params) = cloudkit_context(&auth).await?;
+ set_done(&auth, &data, &guid, &list_guid, done).await
+}
+
+/// Tick a reminder off or put it back — from the window, or from an alert's button.
+async fn set_done(
+ auth: &State<'_, Auth>,
+ data: &State<'_, Data>,
+ guid: &str,
+ list_guid: &str,
+ done: bool,
+) -> UiResult<()> {
+ let (http, root, params) = cloudkit_context(auth).await?;
let reminder = {
let library = data.0.lock().await;
library
- .reminders_in(&list_guid, true)
+ .reminders_in(list_guid, true)
.map_err(|e| e.to_string())?
.into_iter()
.find(|r| r.guid == guid)
@@ -455,6 +469,7 @@ async fn reminder_set_done(
quince_icloud::reminders::sync_cloudkit(&http, &root, params, &mut library, since.as_deref())
.await
.map_err(|e| e.to_string())?;
+ alerts::changed();
Ok(())
}
@@ -528,6 +543,7 @@ async fn reminder_create(
quince_icloud::reminders::sync_cloudkit(&http, &root, params, &mut library, since.as_deref())
.await
.map_err(|e| e.to_string())?;
+ alerts::changed();
Ok(())
}
@@ -559,6 +575,7 @@ async fn reminder_delete(
quince_icloud::reminders::sync_cloudkit(&http, &root, params, &mut library, since.as_deref())
.await
.map_err(|e| e.to_string())?;
+ alerts::changed();
Ok(())
}
@@ -610,6 +627,7 @@ async fn reminder_edit(
quince_icloud::reminders::sync_cloudkit(&http, &root, params, &mut library, since.as_deref())
.await
.map_err(|e| e.to_string())?;
+ alerts::changed();
Ok(())
}
@@ -1461,6 +1479,7 @@ async fn sync_all(
) -> UiResult<refresh::Refresh> {
let client = Arc::clone(&auth.client);
let result = refresh::all(&client, &data.0).await;
+ alerts::changed();
// Screens read the library, not the network, so they only need to be told to look again.
app.emit(SYNCED, &result).ok();
Ok(result)
@@ -1485,6 +1504,7 @@ fn spawn_auto_sync(app: tauri::AppHandle, client: Arc<Mutex<Client>>) {
}
let data = app.state::<Data>();
let result = refresh::all(&client, &data.0).await;
+ alerts::changed();
app.emit(SYNCED, &result).ok();
}
});
@@ -1621,9 +1641,68 @@ fn adopt_writer(library: &mut Library) {
quince_icloud::topotext::set_writer(*id.as_bytes());
}
+/// Bring the window back, wherever it went.
+fn show_window(app: &tauri::AppHandle) {
+ if let Some(window) = app.get_webview_window("main") {
+ window.show().ok();
+ window.unminimize().ok();
+ window.set_focus().ok();
+ }
+}
+
+/// A place in the tray, so Quince stays running — and ringing reminders — with its window
+/// closed, and can be opened again or quit from there.
+fn build_tray(app: &tauri::App) -> tauri::Result<()> {
+ use tauri::menu::{Menu, MenuItem};
+ use tauri::tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent};
+ let open = MenuItem::with_id(app, "open", "Open Quince", true, None::<&str>)?;
+ let quit = MenuItem::with_id(app, "quit", "Quit Quince", true, None::<&str>)?;
+ let menu = Menu::with_items(app, &[&open, &quit])?;
+ let mut tray = TrayIconBuilder::with_id("quince")
+ .tooltip("Quince")
+ .menu(&menu)
+ .show_menu_on_left_click(false)
+ .on_menu_event(|app, event| match event.id.as_ref() {
+ "open" => show_window(app),
+ "quit" => app.exit(0),
+ _ => {}
+ })
+ .on_tray_icon_event(|tray, event| {
+ if let TrayIconEvent::Click {
+ button: MouseButton::Left,
+ button_state: MouseButtonState::Up,
+ ..
+ } = event
+ {
+ show_window(tray.app_handle());
+ }
+ });
+ if let Some(icon) = app.default_window_icon() {
+ tray = tray.icon(icon.clone());
+ }
+ tray.build(app)?;
+ Ok(())
+}
+
fn main() {
tauri::Builder::default()
+ // One Quince at a time: opening it again brings back the one already running, which
+ // may be sitting in the tray with its window closed.
+ .plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
+ show_window(app);
+ }))
.plugin(tauri_plugin_dialog::init())
+ // Closing the window hides it rather than quitting, so reminders still ring. Quit is
+ // in the tray. Where no tray could be made there is nowhere to come back from, so
+ // there closing quits as it always did.
+ .on_window_event(|window, event| {
+ if let tauri::WindowEvent::CloseRequested { api, .. } = event {
+ if window.app_handle().tray_by_id("quince").is_some() {
+ api.prevent_close();
+ window.hide().ok();
+ }
+ }
+ })
// Images are served, not messaged. `quince://photo/<contact id>` is loaded by the
// webview itself, which is what keeps a scrolling list cheap.
.register_asynchronous_uri_scheme_protocol("quince", |ctx, request, responder| {
@@ -1691,6 +1770,10 @@ fn main() {
app.manage(Data(Mutex::new(library)));
spawn_heartbeat(Arc::clone(&client));
spawn_auto_sync(app.handle().clone(), client);
+ alerts::spawn(app.handle().clone());
+ if let Err(e) = build_tray(app) {
+ eprintln!("no tray on this desktop, so closing the window quits: {e}");
+ }
Ok(())
})
.invoke_handler(tauri::generate_handler![
diff --git a/src/lib/ipc.ts b/src/lib/ipc.ts
index c6f509f..720a636 100644
--- a/src/lib/ipc.ts
+++ b/src/lib/ipc.ts
@@ -48,6 +48,8 @@ export type UploadEvent = {
};
export const SYNCED = "quince://synced";
+/** An alert was clicked: open Reminders, where that reminder is. */
+export const OPEN_REMINDER = "quince://open-reminder";
export const api = {
/** One refresh for every service. Never rejects for a single service failing. */
diff --git a/src/screens/Library.tsx b/src/screens/Library.tsx
index 3bcd405..c28a0d9 100644
--- a/src/screens/Library.tsx
+++ b/src/screens/Library.tsx
@@ -1,5 +1,6 @@
import { useEffect, useRef, useState } from "react";
-import { api, messageOf } from "../lib/ipc";
+import { listen } from "@tauri-apps/api/event";
+import { api, messageOf, OPEN_REMINDER } from "../lib/ipc";
import { SyncProvider } from "../lib/sync";
import { SyncStatus } from "../components/SyncStatus";
import { CalendarView } from "./calendar/CalendarView";
@@ -60,6 +61,17 @@ export function Library({ onSignOut }: { onSignOut: () => void }) {
}
};
+ // Clicking a reminder's alert brings the window back on Reminders.
+ useEffect(() => {
+ const stop = listen<string>(OPEN_REMINDER, () => {
+ if (services.includes("reminders")) choose("reminders");
+ });
+ return () => {
+ void stop.then((unlisten) => unlisten()).catch(() => {});
+ };
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [services]);
+
// Native sidebars move with the arrow keys and occupy a single tab stop. Without this a
// keyboard user has to Tab through every row to reach the content.
const rows = useRef<(HTMLButtonElement | null)[]>([]);