Skip to content

Add configurable macOS glucose notifications - #1

Merged
edusantosdev merged 1 commit into
mainfrom
glucose-notifications
Nov 25, 2026
Merged

edusantosdev merged 1 commit into
mainfrom
glucose-notifications

Conversation

@edusantosdev

Copy link
Copy Markdown
Owner

What

Adds opt-in macOS notifications for glucose events, configured from a new Notifications ▸ submenu:

  • Low / High / Very High: separate toggles. Menu labels show the active threshold in the account's unit (mg/dL or mmol/L).
  • Rising or Falling Fast: fires on LibreView's ↑ / ↓ trend only, once per episode, with a 15-minute cooldown per direction.
  • No New Data: Off, or after 10 / 20 / 30 / 60 minutes without a new sensor reading.
  • Thresholds ▸: Default (70 / 180 / 250 mg/dL) or Custom…, which opens an NSPanel dialog in the account's unit. Custom values affect notifications only; the menu bar colors are unchanged.
  • Repeat Alerts ▸: Only Once, or every 10 / 15 / 30 / 60 minutes while out of range.
  • Play Sound toggle and Send Test Notification.

Notifications are off by default. Turning them on requests macOS permission; if the user denies it, the toggle reverts and a dialog points to System Settings.

Why

Gluco only showed glucose passively in the menu bar. Users asked to be alerted when glucose crosses thresholds they care about.

How

  • macos_frontend/notifications.py: alert rules (AlertEngine), prefs persisted to ~/.glucobar/notifications.json, unit conversion and threshold parsing/validation. Pure Python, no AppKit.
  • macos_frontend/notifier.py: delivery via UNUserNotificationCenter. Each category (range / rapid / signal) uses a fixed request identifier, so a reminder replaces the previous banner instead of stacking.
  • macos_frontend/notifications_menu.py and macos_frontend/thresholds_dialog.py: the submenu and the custom-threshold dialog.
  • app.py: runs the alert check after each 30s poll. CurrentReading now carries trend.
  • New dependency pyobjc-framework-UserNotifications, added to the py2app package list.

Reviewer notes

  • Repeats: a zone is only left once the reading is 5 mg/dL back across the line, so a value hovering at a threshold doesn't re-alert. Going from High to Very High alerts again; coming back down doesn't.
  • Stale data: range and rapid alerts only act on status == "ok". While data is stale the no-data rule takes over, and the range state is kept so recovery doesn't re-alert.
  • No-data alert: it needs both wall-clock age and awake time (time.monotonic) past the limit, so waking the Mac doesn't fire it before the daemon has fetched. It uses a last-known sensor timestamp that survives a daemon restart (e.g. from OfflineRestartPolicy) that comes back with no reading.
  • Outside the bundle: the notifier requires the bundle id com.glucobar.frontend. From plain python, UNUserNotificationCenter aborts the process, so alerts are only logged there.
  • Focus: low alerts set the time-sensitive interruption level, but that needs an entitlement ad-hoc signing can't provide, so for now they arrive as normal notifications.
  • LibreView data lags a few minutes. These alerts are a convenience, not a replacement for the Libre app's alarms.

Testing

  • pytest tests/: 132 passed, including the new tests/test_notifications.py (zones and repeats, escalation, reminders, rapid-change cooldown, no-data alert after sleep, unit parsing, prefs sanitizing).
  • ruff check .: clean.
  • scripts/build_portable_app.sh builds, and UserNotifications is present in the bundle.
  • Not yet checked by hand in the running app: the permission prompt, the test banner and the threshold dialog.

🤖 Generated with Claude Code

Add a Notifications submenu that lets the user opt in to macOS alerts for
low, high and very high glucose, rapid rise/fall (fast trend arrows) and
no new data for a chosen number of minutes.

- Thresholds: defaults (70/180/250 mg/dL) or custom values entered in the
  account's unit; custom values affect notifications only, not the menu
  bar colors.
- Repeat: once per excursion or every 10/15/30/60 minutes while out of
  range, with a 5 mg/dL hysteresis band so readings hovering on a
  threshold don't re-alert.
- Rapid change fires once per episode with a 15-minute cooldown; the
  no-data alert ignores time the Mac spent asleep.
- Sound toggle and a test notification item.

Alert rules and prefs (~/.glucobar/notifications.json) live in
macos_frontend/notifications.py and are unit-tested. Delivery uses
UNUserNotificationCenter via the new pyobjc-framework-UserNotifications
dependency, falling back to logging when not running from Gluco.app.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@edusantosdev
edusantosdev merged commit a43dbc5 into main Nov 25, 2026
4 checks passed
@edusantosdev
edusantosdev deleted the glucose-notifications branch November 25, 2026 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant