tauri icon indicating copy to clipboard operation
tauri copied to clipboard

feat: push notifications

Open sgammon opened this issue 3 months ago • 4 comments

Summary

Adds initial support wiring for Push Notifications (see: #11651).

This requires instrumentation down into tao, to call methods on the AppDelegate or NSApplication / UIApplication (for Apple platforms). Firebase Messaging (FCM) support is also under consideration.

  • [ ] tauri: Handle new events
    • (that's this pr)
    • [x] Forward/map PushRegistration event
    • [x] Forward/map PushRegistrationFailed event
    • [ ] General cleanup (don't repeat typedefs, etc)
  • [ ] tao: Hooks into UIApplication / NSApplication
    • tauri-apps/tao#1015
    • [x] Support for macOS
    • [ ] Support for iOS
    • [x] Any considerations for Android
    • [x] Considerations for Windows
  • [ ] tauri-plugin-push-notifications:
    • tauri-apps/plugins-workspace#2066
    • [x] Initially working plugin structure (here)
    • [x] Facade for await pushToken(...)
    • [x] Working local test to capture token
    • [x] Add plugin sources to plugins-workspace
    • [ ] Interface for callback-based token access
  • [ ] tauri-docs
    • tauri-apps/tauri-docs#2997
    • [x] Add initial Push Notifications plugin page
    • [ ] Validate configuration with example app
  • [ ] Platform support
    • [x] macOS (APNS)
    • [ ] iOS (APNS)
    • [ ] Windows (WNS)
    • [x] Android (FCM)

PR Tree

This PR is accompanied by a plugin, tauri-plugin-push-notifications, and a PR to tao:

  • Plugin repo
  • tauri-apps/tao#1015
  • tauri-apps/plugins-workspace#2066
  • tauri-apps/tauri-docs#2997

Known Issues

  • [ ] General
    • [ ] Token needs strong typing in guest code
  • [ ] Docs
    • [ ] macOS and iOS devices need an entitlement, which should be mentioned in the docs.
  • [ ] Tests
    • [ ] There are no tests yet.

[!WARNING] This functionality is experimental and is gated behind the push-notifications feature for now.

How it works

(1) tao and tauri forward two new events: PushRegistration(PushToken) and PushRegistrationFailed(Error). (2) a new plugin, tauri-plugin-push-notifications, listens for these events, holds the token or error, and exposes those values to guest code when requested.

sequenceDiagram
    tao->>+OS: Setup app delegate
    OS->>+tao: applicationDidFinishLaunching
    tao->>+OS: registerForRemoteNotifications()
    OS->>+tao: didFinishRegisteringWithToken()
    tao->>+tauri: PushRegistration(PushToken) Event
    tauri->>+Plugin: Forward event
    Plugin->>+Plugin: Retain token in-memory
    tauri->>+App: Launch app
    App<<->>+Plugin: await pushToken()

sgammon avatar Nov 12 '24 01:11 sgammon