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 #11651

Open sgammon opened 1 week ago

sgammon commented 1 week ago

Describe the problem

Several platforms supported by Tauri - macOS, iOS, and Android, to name a few - have some kind of built-in push notifications system. For Apple systems, of course there is APNS, and for Android and Firebase-enabled apps, there is FCM.

Tauri isn't yet able to support these APIs, as far as I can tell. On Apple platforms, the developer must register a method with the AppDelegate and call a method on NSApplication, which isn't easy to do from Rust. iOS uses a similar flow, but with UIApplication instead.

Push Notifications are likely to be a common need for Tauri developers, especially on mobile platforms.

Describe the solution you'd like

I think Tauri should add calls to the UIApplication and/or NSApplication to register for push notification support on behalf of the developer; or, Tauri should make available such calls so the developer can implement support themselves.

Alternatives considered

1) I looked for plugins and found none 2) I looked for easy Rust bindings to register for APNS, and found none because these APIs use {NS,UI}Application 3) I looked into alternative push systems (3rd-party), but these aren't integrated well with underlying operating systems like Android and iOS, as compared to native push infrastructure

Additional context

General support

In most cases, "registering" for these push systems consists of a few relatively simple steps:

1) "Registering" or "requesting" a token from the application, using system APIs, potentially within the app entrypoint 2) "Receiving" the token via some callback or delegate mechanism (the token is typically just some raw bytes or a string) 3) Making the received token available to the developer

Apple Platforms

macOS

It looks like tao already sets up an AppDelegate, where we would need to call registerForRemoteNotifications, and then receive the token at the delegate method application(_:didRegisterForRemoteNotificationsWithDeviceToken:).

iOS

Nearly identical to macOS, but with UIApplication.registerForRemoteNotifications() and the equivalent delegate method.

Android

Firebase uses a Service on Android to implement messaging within an app. This service is declared in the AndroidManifest.xml and then implemented within app code; the service:

This would be implemented in Kotlin as part of an Android mobile plugin for Tauri. Luckily there are no changes anticipated for tao or tauri itself; Android push can happen through the plugin alone.

Windows

Windows apparently has Windows Notifications System (WNS), which is accessible via the windows crate. So far it appears to function similar to Android, in that a library can obtain a push channel without special code in the app entrypoint.

Linux

I'm not aware of native push infrastructure for Linux. Other SDKs can be used on Linux which do not require instrumentation in the app entrypoint.