tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
85.38k stars 2.58k forks source link

feat: push notifications #11652

Open sgammon opened 1 week ago

sgammon commented 1 week ago

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.

PR Tree

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

Known Issues

[!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()
ChrisCates commented 5 days ago

Any way I can help ship this? That or, what's your ETA for completion brotha?

sgammon commented 4 days ago

@ChrisCates Very close to completion, i'm testing on macOS shortly. I haven't explored Android yet, so some research there might help (how best to integrate Firebase Cloud Messaging - FCM - into tao and tauri; ideally it could work within the plugin only).

Windows is looking solid but I'm not sure how to extract the token yet. That may remain experimental until later if only because I can't find any third party push services that support WNS at this time.

tl;dr I'd say we could get macOS and potentially iOS working within a few days. Android and WNS are probably easier/less complex, but may take a few days longer for research about how best to integrate. Regarding review and merge, I've no clue, this is my first PR to Tauri.