Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.
Keep old calls and cleared notifications from coming back
Bee313e33ffca6d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b0c093d..c0a4cea 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -21,6 +21,12 @@ change things that need a step from you, and its notes say so.([#6](https://github.com/thtbee/nectarlink/issues/6)).- Windows: button tooltips, such as **Pause** on the media card, show next totheir button again instead of in the window's top-left corner.+- **Old calls and notifications no longer come back** after the PC sleeps or+ restarts. A call whose end the phone never recorded rang again on every+ reconnect; it now counts as over after 90 seconds of ringing. Notifications+ you clear on the PC stay cleared when the phone resends its list (on+ reconnect or Refresh), even when the phone can't remove them, as with missed+ calls and alarms. A new post from the same app shows as usual.## 0.1.3 (2026-10-15)diff --git a/core/nectarlink-core/src/calls.rs b/core/nectarlink-core/src/calls.rsindex 1210c7d..aba342d 100644--- a/core/nectarlink-core/src/calls.rs+++ b/core/nectarlink-core/src/calls.rs@@ -3,7 +3,10 @@//! is answered and ends; a PC can answer, decline or silence it. The call's//! audio stays on the phone.-use std::sync::{Arc, Mutex};+use std::{+ sync::{Arc, Mutex},+ time::{Duration, Instant},+};use nectarlink_protocol::{Envelope, ErrorCode,@@ -101,19 +104,36 @@ impl CallCommand {}}+/// How long a call can ring. Phones stop ringing within a minute or so; a+/// call still "ringing" after this is one whose end was never reported (the+/// app was stopped, say), and must not ring again on a PC that connects.+const RINGING_AT_MOST: Duration = Duration::from_secs(90);+/// The phone's call in progress (ringing or active), for PCs that connect-/// while it's going on.+/// while it's going on, with when it started ringing.#[derive(Debug, Default)]-pub(crate) struct Current(Mutex<Option<CallState>>);+pub(crate) struct Current(Mutex<Option<(CallState, Instant)>>);impl Current {fn get(&self) -> Option<CallState> {- self.0.lock().unwrap_or_else(|e| e.into_inner()).clone()+ self.get_at(Instant::now())+ }++ fn get_at(&self, now: Instant) -> Option<CallState> {+ let current = self.0.lock().unwrap_or_else(|e| e.into_inner());+ let (call, since) = current.as_ref()?;+ let stale = call.state == calls::RINGING && now.saturating_duration_since(*since) > RINGING_AT_MOST;+ (!stale).then(|| call.clone())}fn set(&self, call: &CallState) {- *self.0.lock().unwrap_or_else(|e| e.into_inner()) =- (call.state != calls::ENDED).then(|| call.clone());+ let mut current = self.0.lock().unwrap_or_else(|e| e.into_inner());+ // The same call ringing again (an update) keeps when it started.+ let since = current+ .as_ref()+ .filter(|(c, _)| c.id == call.id && c.state == call.state)+ .map_or_else(Instant::now, |(_, since)| *since);+ *current = (call.state != calls::ENDED).then(|| (call.clone(), since));}}@@ -380,4 +400,31 @@ mod tests {current.set(&CallState { state: calls::ENDED.into(), ..call });assert!(current.get().is_none());}++ #[test]+ fn a_call_left_ringing_goes_stale() {+ let current = Current::default();+ let ringing = CallState {+ id: "7".into(),+ state: calls::RINGING.into(),+ incoming: true,+ number: None,+ name: None,+ photo: None,+ missed: false,+ since: None,+ controls: None,+ };+ let start = Instant::now();+ current.set(&ringing);+ // Still ringing a minute in, and after an update for the same call.+ current.set(&ringing);+ assert!(current.get_at(start + Duration::from_secs(60)).is_some());+ // Its end never reported: a PC connecting later isn't told it rings.+ assert!(current.get_at(start + Duration::from_secs(120)).is_none());++ // A call in progress stays, however long it lasts.+ current.set(&CallState { state: calls::ACTIVE.into(), ..ringing });+ assert!(current.get_at(start + Duration::from_secs(3600)).is_some());+ }}diff --git a/desktop/app/src/notifications.rs b/desktop/app/src/notifications.rsindex 4cbbe25..1589b89 100644--- a/desktop/app/src/notifications.rs+++ b/desktop/app/src/notifications.rs@@ -349,6 +349,10 @@ fn live_toast_progress(n: &Notification) -> Option<toast::Progress> {}fn show(device: DeviceId, n: &Notification) {+ // Cleared here already: the same post sent again doesn't pop up again.+ if core_host::host().hub.read(|s| s.is_cleared(device, n)) {+ return;+ }let otp = notification_otp(n);if let Some(code) = &otp {otp_codes(|c| c.insert((device, n.key.clone()), code.clone()));@@ -548,7 +552,10 @@ pub fn set_app_rule(app: &str, rule: AppRule) {/// Dismisses a phone notification there (and here right away).pub fn dismiss(device: &str, key: String) {let (Ok(device), Some(node)) = (device.parse::<DeviceId>(), core_host::node()) else { return };- core_host::host().hub.update(|s| s.apply(&NodeEvent::NotificationRemoved { device, key: key.clone() }));+ core_host::host().hub.update(|s| {+ s.mark_cleared(device, &key);+ s.apply(&NodeEvent::NotificationRemoved { device, key: key.clone() })+ });toasted(|t| t.get_mut(&device).map(|keys| keys.remove(&key)));live_toasts(|l| l.remove(&(device, key.clone())));otp_codes(|c| c.remove(&(device, key.clone())));diff --git a/desktop/app/src/state.rs b/desktop/app/src/state.rsindex d722831..f8661a0 100644--- a/desktop/app/src/state.rs+++ b/desktop/app/src/state.rs@@ -270,6 +270,11 @@ pub struct AppState {/// Most recently dismissed notification(s) for in-feed undo.pub last_dismissed: Vec<NotificationView>,pub last_dismissed_label: String,+ /// Notifications cleared here, by device and key, with the post time they+ /// had. The phone can't always remove them (missed calls, alarms) or+ /// isn't reachable yet, and its next list (after a reconnect, or Refresh)+ /// mustn't bring them back. A newer post under the same key shows again.+ pub cleared: HashMap<(DeviceId, String), i64>,/// Notifications that went away, newest first, while history is kept.pub history: Vec<HistoryEntry>,pub history_enabled: bool,@@ -481,6 +486,8 @@ impl AppState {}NodeEvent::Pairing(event) => self.apply_pairing(event),NodeEvent::NotificationsReset { device, items } => {+ // What the phone no longer shows can't come back as the same post.+ self.cleared.retain(|(d, key), _| d != device || items.iter().any(|i| i.key == *key));let before = self.notifications.len();// What's gone since the last list went away on the phone.let gone: Vec<NotificationView> = self@@ -495,11 +502,17 @@ impl AppState {}let mut changes = Changes::NOTIFICATIONS;for n in items {- changes |= self.insert_notification(*device, n.clone());+ if !self.is_cleared(*device, n) {+ changes |= self.insert_notification(*device, n.clone());+ }}changes | self.remember(gone)}NodeEvent::NotificationPosted { device, notification } => {+ if self.is_cleared(*device, notification) {+ return Changes::NONE;+ }+ self.cleared.remove(&(*device, notification.key.clone()));Changes::NOTIFICATIONS | self.upsert_notification(*device, notification.clone())}NodeEvent::NotificationRemoved { device, key } => {@@ -757,6 +770,18 @@ impl AppState {}/// Records a user-initiated dismissal so the feed can offer Undo.+ /// Whether `n` is a post the user cleared here.+ pub fn is_cleared(&self, device: DeviceId, n: &Notification) -> bool {+ self.cleared.get(&(device, n.key.clone())).is_some_and(|&when| when == n.when)+ }++ /// Remembers that the user cleared a notification here (before it's removed).+ pub fn mark_cleared(&mut self, device: DeviceId, key: &str) {+ if let Some(n) = self.notifications.iter().find(|n| n.device == device && n.notification.key == key) {+ self.cleared.insert((device, key.to_owned()), n.notification.when);+ }+ }+pub fn record_dismissed(&mut self, views: Vec<NotificationView>, label: String) -> Changes {if views.is_empty() {return Changes::NONE;@@ -783,6 +808,7 @@ impl AppState {}self.notifications.retain(|n| !(n.device == view.device && n.notification.key == view.notification.key));+ self.cleared.remove(&(view.device, view.notification.key.clone()));changes |= self.insert_notification(view.device, view.notification);}changes@@ -1499,6 +1525,69 @@ mod tests {assert!(s.toggles.is_empty());}+ #[test]+ fn cleared_notifications_stay_cleared_until_a_new_post() {+ let phone = DeviceId([1; 32]);+ let mut s = AppState::default();+ let missed_call = note("call", 10);+ let alarm = note("alarm", 20);+ s.apply(&NodeEvent::NotificationsReset {+ device: phone,+ items: vec![missed_call.clone(), alarm.clone()],+ });++ // Cleared here; the phone couldn't remove it (or wasn't reachable).+ s.mark_cleared(phone, "call");+ s.apply(&NodeEvent::NotificationRemoved { device: phone, key: "call".into() });+ assert_eq!(keys(&s), ["alarm"]);++ // A reconnect or Refresh sends the phone's list again: it stays gone.+ s.apply(&NodeEvent::NotificationsReset {+ device: phone,+ items: vec![missed_call.clone(), alarm.clone()],+ });+ assert_eq!(keys(&s), ["alarm"]);+ // So does the same post sent again on its own.+ assert_eq!(+ s.apply(&NodeEvent::NotificationPosted { device: phone, notification: missed_call.clone() }),+ Changes::NONE+ );+ assert_eq!(keys(&s), ["alarm"]);++ // A newer post under the same key (another missed call) shows.+ s.apply(&NodeEvent::NotificationPosted { device: phone, notification: note("call", 30) });+ assert!(keys(&s).contains(&"call"));+ assert!(s.cleared.is_empty());+ }++ #[test]+ fn clears_are_forgotten_once_the_phone_drops_them() {+ let phone = DeviceId([1; 32]);+ let mut s = AppState::default();+ s.apply(&NodeEvent::NotificationsReset { device: phone, items: vec![note("a", 10)] });+ s.mark_cleared(phone, "a");+ s.apply(&NodeEvent::NotificationRemoved { device: phone, key: "a".into() });+ assert_eq!(s.cleared.len(), 1);+ // Gone from the phone too: nothing left to hold back.+ s.apply(&NodeEvent::NotificationsReset { device: phone, items: vec![] });+ assert!(s.cleared.is_empty());+ }++ #[test]+ fn undo_brings_a_cleared_notification_back_for_good() {+ let phone = DeviceId([1; 32]);+ let mut s = AppState { history_enabled: true, ..AppState::default() };+ s.apply(&NodeEvent::NotificationsReset { device: phone, items: vec![note("a", 10)] });+ let views = s.notifications.clone();+ s.mark_cleared(phone, "a");+ s.apply(&NodeEvent::NotificationRemoved { device: phone, key: "a".into() });+ s.record_dismissed(views, "Notification dismissed".into());+ s.undo_dismiss();+ assert_eq!(keys(&s), ["a"]);+ s.apply(&NodeEvent::NotificationsReset { device: phone, items: vec![note("a", 10)] });+ assert_eq!(keys(&s), ["a"]);+ }+#[test]fn app_group_expansion_and_undo_dismiss_work() {let phone = DeviceId([1; 32]);