Skip to content

Improve Web Push notification UX (icon, length, SW debug visibility)#112

Merged
HamptonMakes merged 2 commits into
mainfrom
05-13-improve_web_push_notification_ux_icon_length_sw_debug_visibility_
May 13, 2026
Merged

Improve Web Push notification UX (icon, length, SW debug visibility)#112
HamptonMakes merged 2 commits into
mainfrom
05-13-improve_web_push_notification_ux_icon_length_sw_debug_visibility_

Conversation

@HamptonMakes
Copy link
Copy Markdown
Collaborator

Stacks on #111. Three small fixes shaken out by end-to-end testing the Web Push delivery path locally.

1. CoPlan icon on notifications

The SW used to omit icon so Chrome rendered its own app chrome (the puzzle-piece icon) on incoming notifications. Now the SW always sets icon and badge to the engine's CoPlan logo asset. The URL is templated into the SW body at request time (__COPLAN_NOTIFICATION_ICON__ token in the .js file → view_context.asset_path("coplan/coplan-logo-sm.png") in the controller), so it always picks up the current digested asset path.

2. SW push handler no longer silently bails

The DevTools Application → Service Workers → Push button sends a push with no payload. The previous handler did if (!event.data) return, which meant that test button just did nothing — useless for debugging. Now the handler:

  • Shows a fallback notification when there's no payload (so the DevTools Push button is actually useful)
  • Logs every push event to the SW console so future issues are visible
  • Catches showNotification failures and logs them instead of letting them disappear

3. Body truncation 140 → 90 chars

Chrome / macOS show roughly 80–100 chars of body before they truncate further with their own ellipsis. Setting BODY_TRUNCATE to 90 means we control where the cut happens (with a word-boundary ellipsis) instead of letting the OS chop mid-word with no visual hint.

Verification

  • 834 specs pass; service_workers_spec.rb and payload_for_notification_spec.rb still green.
  • Manual end-to-end tested locally: send a real push → desktop notification appears with CoPlan icon, body fits in one line, click deep-links to the right thread.
  • Verified the substituted SW body: curl -s http://localhost:3000/coplan_service_worker.js | grep icon shows the digested asset URL.

Generated with Amp

Wraps the per-device list in a turbo-frame and reloads it from the
Stimulus controller after subscribe/unsubscribe succeeds, so the new
browser appears (or disappears) without a full page refresh.

Changes
- Extracts the device list into _devices.html.erb wrapped in a
  <turbo-frame id=web-push-devices>.
- Adds GET /web_push/devices that renders just that partial back into
  the same frame.
- web_push_settings_controller.js: new devicesUrl Stimulus value;
  after enable/disable success, sets the frame's src to refetch.

Generated with Amp
Three small fixes shaken out by end-to-end testing:

1. Service worker now shows the CoPlan logo as the notification icon
   instead of falling back to the browser's app chrome (Chrome's puzzle
   piece in the test). The icon URL is templated into the SW body at
   request time so it always points at the current digested asset.

2. SW push handler no longer silently bails when event.data is empty —
   it shows a fallback notification. This makes the DevTools Application
   → Service Workers → Push button useful for verifying the handler is
   wired up without needing to send a real push. Also adds a console
   log on every push and a .catch on showNotification so future failures
   surface immediately instead of disappearing.

3. PayloadForNotification body truncation 140 → 90 chars. Chrome /
   macOS show roughly 80–100 chars before they truncate further; setting
   it lower means we control where the cut happens (and add an ellipsis
   on a word boundary) instead of ending mid-word with no visual hint.

Generated with Amp
Base automatically changed from 05-13-auto-refresh_device_list_on_settings_after_enable_disable to main May 13, 2026 18:20
@HamptonMakes HamptonMakes merged commit e21aaad into main May 13, 2026
2 checks passed
@HamptonMakes HamptonMakes deleted the 05-13-improve_web_push_notification_ux_icon_length_sw_debug_visibility_ branch May 13, 2026 18:20
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