Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Push Notifications #11651

Open
sgammon opened this issue Nov 12, 2024 · 7 comments
Open

[feat] Push Notifications #11651

sgammon opened this issue Nov 12, 2024 · 7 comments

Comments

@sgammon
Copy link

sgammon commented Nov 12, 2024

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
  • Usually the developer will want to send this token to a server
  • Callbacks or even just a method to retrieve the latest push token (if any) would work fine for callers, probably

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:

  • Requests a token
  • Receives the token/receives updated tokens
  • Receives pushed messages directed to the app

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.

sgammon added a commit to sgammon/tao that referenced this issue Nov 12, 2024
- feat(apns): add responders and events for APNS registration and
  error callbacks
- feat(apns): call `registerForRemoteNotifications` within
  `did_finish_launching`
- feat(apns): dispatch event to app for apns registration
- feat(apns): gate push notifications behind `push-notifications`
  feature

Relates-To: tauri-apps/tauri#11651
Signed-off-by: Sam Gammon <sam@elide.ventures>
sgammon added a commit to sgammon/tauri-plugin-push-notifications that referenced this issue Nov 12, 2024
Relates-To: tauri-apps/tauri#11651
Signed-off-by: Sam Gammon <sam@elide.ventures>
sgammon added a commit to sgammon/tauri that referenced this issue Nov 12, 2024
- feat(push): relay events for push notifications registration and
  errors to app
- feat(push): gate apns by `push-notifications` feature

Relates-To: tauri-apps#11651
Signed-off-by: Sam Gammon <sam@elide.ventures>
@sgammon sgammon mentioned this issue Nov 12, 2024
29 tasks
sgammon added a commit to sgammon/plugins-workspace that referenced this issue Nov 18, 2024
- feat: add push notifications plugin
- chore: adjust for inline to workspace

Relates-To: tauri-apps/tauri#11651
Signed-off-by: Sam Gammon <s@mg.sv>
sgammon added a commit to sgammon/tauri-docs that referenced this issue Nov 18, 2024
Relates-To: tauri-apps/tauri#11652
Relates-To: tauri-apps/tauri#11651
Signed-off-by: Sam Gammon <s@mg.sv>
@osdiab
Copy link

osdiab commented Dec 18, 2024

Someone published this undocumented plugin, but no idea if it works or what, haven’t tried it and don’t know anything about how mobile platforms work really.

https://github.com/guillemcordoba/tauri-plugin-fcm-push-notifications

Hoping that this feature gets added - seems like table stakes for Tauri to be usable for serious mobile apps!

@osdiab
Copy link

osdiab commented Dec 18, 2024

Not sure the current status of this but @gordongrech claims to have made FCM work on Android and iOS, so sounds like it’s feasible with the plugin system.

#8423

@eatenpancreas
Copy link

eatenpancreas commented Dec 18, 2024

I have managed to get FCM working on Android, attempted IOS but didn't get far for now due to time constraints

This person has worked on a FCM plugin before and it seems to be further along on IOS. Haven't tested it myself but it could be useful:

https://github.com/flapili/tauri-plugin-fcm

@sgammon
Copy link
Author

sgammon commented Dec 18, 2024

@osdiab / @eatenpancreas

The blocker right now is iOS, which is structured differently in Tauri's internals than macOS (Mac is much more straightforward to implement). It may indeed be possible to implement some platforms with only a plugin, but Mac and iOS probably need this deeper integration for the reasons outlined in the PR (FCM does not use the same APIs as you guys probably know).

I've raised the iOS questions on Tauri's contributor Discord, but so far haven't found any expertise. I think what I will do is split off the iOS changes et. al so they can be worked on in a separate PR.

This would mean that macOS and Android, at least, can be delivered here, and then iOS and potentially WNS can follow shortly thereafter, after some advice from whoever wrote the iOS code.

@sgammon
Copy link
Author

sgammon commented Dec 18, 2024

Also, I'd be happy to collaborate with anyone who is interested. My main hopes right now are to get this PR tree to stable, and to make this entire changeset less invasive by eliminating any changes that can be dropped.

@jd-carroll
Copy link

Nice work on all of this. As someone who is still trying to grasp the Tauri architecture, it might be nice to have a very brief write-up of the different pieces you needed to touch to make this happen (more for educational purposes). While I think all of the PR's are above, there seemed to be a lot of PR's to your personal repo too so it was a little hard to follow.

But broadly, nice work!

@jd-carroll
Copy link

Separately and why I am really here... Since this change involves accessing the AppDelegate, I'd like to make a plug for broader access or hooks into the AppDelegate.

For example, I am building a banking app and I would like to display a loading / splash screen when the app is re-opened. The documentation I've found says I should hook into the WillEnterForeground event.

To my knowledge, this is not currently exposed in Tauri. It would be great to be able to redirect to a loading screen and then redirect back when this event is triggered.

I'm not trying to suggest that this be included in these changes, but merely that as this change involves the AppDelegate some consideration to additional AppDelegate use cases would be appreciated! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
  NODES
COMMUNITY 2
Idea 1
idea 1
INTERN 1
Project 5
USERS 1