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: Enable APNS registration + notification delivery in macOS apps #33574

Merged
merged 34 commits into from Jul 12, 2022

Conversation

joanx
Copy link
Contributor

@joanx joanx commented Apr 1, 2022

Description of Change

Want to pick up on previous attempts #13777 and #18286 by @frantic and @kevinhu88 to enable APNS in Electron.

My understanding is that #18286 was blocked on concerns over supporting UserNotification and NSUserNotifications at the same time. This subset (APNS registration + notification receipt) doesn't actually seem to reference the UserNotification object (the relevant UserNotification -related code appears to have been handled in @miniak 's #25950.)

I've ported over the remaining functionality to register + receive APNS notifications into a separate fork (as the previous PR appears to be blocked on merge conflicts) and have confirmed successful registration + notification receipt via APNs with this sample app using Apple's command-line tools (note, I needed to create a provisioning profile + code-sign this app for successful APNS registration).

Would love to re-start the conversation around what it would take to enable APNS in Electron. Thanks in advance!

Checklist

Release Notes

Notes: Added support for push notifications from APNs for macOS apps.

@welcome
Copy link

welcome bot commented Apr 1, 2022

💖 Thanks for opening this pull request! 💖

We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix.

Examples of commit messages with semantic prefixes:

  • fix: don't overwrite prevent_default if default wasn't prevented
  • feat: add app.isPackaged() method
  • docs: app.isDefaultProtocolClient is now available on Linux

Things that will help get your PR across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Apr 1, 2022
@joanx joanx changed the title Feat: Enable APNS registration + notification delivery in macOS apps feat: Enable APNS registration + notification delivery in macOS apps Apr 1, 2022
@@ -532,4 +532,34 @@ void RemoveFromLoginItems() {
}
}

void Browser::RegisterForRemoteNotifications() {
[[AtomApplication sharedApplication]
registerForRemoteNotificationTypes:NSRemoteNotificationTypeBadge |
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attempting to use the updated API (registerForRemoteNotifications) resulted in this error:

'registerForRemoteNotifications' has been marked as being introduced in macOS 10.14 here, but the deployment target is macOS 10.11.0

Copy link
Member

@zcbenz zcbenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

@joanx
Copy link
Contributor Author

joanx commented Apr 5, 2022

@zcbenz thanks so much for the review! Is there any guidance on next steps to get this merged?

@zcbenz
Copy link
Member

zcbenz commented Apr 6, 2022

We just need to wait for a few more reviews from maintainers.

@nornagon
Copy link
Member

cc @miniak and @MarshallOfSound who have worked in this area previously

@zcbenz zcbenz self-assigned this Apr 13, 2022
@michal-bednarz
Copy link

michal-bednarz commented Apr 28, 2022

Hey 👋 @nornagon @zcbenz @miniak @MarshallOfSound I just wanted to kindly ping you about this PR :) What are the next steps? Can we help somehow with pushing it into the release version?

@MarshallOfSound
Copy link
Member

Haven't had a chance to look this over yet but I don't see CI runs this PR yet. @joanx can you try signing in to circleci and pushing a new commit to this PR. Builds should kick off after that

@joanx
Copy link
Contributor Author

joanx commented May 2, 2022

@MarshallOfSound just did!

@MarshallOfSound
Copy link
Member

Few things:

  • Code looks fine in principle, the lint is unhappy and should be fixed
  • Idea is fine as well, I'm relatively OK with this API being added as it fundamentally has to be added into Electron if someone wants to use APNS
  • This is the part where I bikeshed over where to put the API:

I'm not a fan of lumping everything in with app.*, it's kinda a catch-all that is incredibly oversaturated at this point. I have two suggestions:

  • import { apns } from 'electron', specific to APNS
  • import { pushNotifications } from 'electron' if we think we may implement the windows equivalent
  • The existing Notification module, maybe Notification.push or Notification.apns

I'm open to arguments for either or an alternative, but I'm -0.5 on lumping this into app

@joanx
Copy link
Contributor Author

joanx commented May 9, 2022

@MarshallOfSound , thanks for the review. I'm unfortunately not familiar with the code organization and languages used here and unable to achieve a working binary with the refactor though I'd hugely appreciate any guidance on the in-progress changes.

Wondering if you have thoughts on any of these options:

  1. Keep logic in app
  2. Possible for me to pair with someone in the Electron maintainers group?
  3. Possible for someone in the Electron maintainers group to own the refactor?
  4. I continue to own these changes; there may be somewhat long iteration cycles as I ramp up on the necessary context to get this to a merge-ready state

Thank you!

@joanx
Copy link
Contributor Author

joanx commented Jun 17, 2022

Hi @nornagon , thanks so much for the review. I believe I've addressed the comments, though am seeing some build failures that I'm not sure are related to my changes; would love any guidance. thanks!

edit: build is green now 🤔

Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looking pretty good! Now that I'm looking more closely at the API, I think the registerForAPNSNotifications function might be better expressed as a Promise, rather than as a function which returns void and triggers one of two events later on. It might be a little trickier to implement in the C++ side, though.

shell/browser/api/electron_api_push_notifications.cc Outdated Show resolved Hide resolved
shell/browser/api/electron_api_push_notifications.cc Outdated Show resolved Hide resolved
shell/browser/api/electron_api_push_notifications.cc Outdated Show resolved Hide resolved
shell/browser/mac/electron_application_delegate.mm Outdated Show resolved Hide resolved
docs/api/push-notifications.md Outdated Show resolved Hide resolved
docs/api/push-notifications.md Show resolved Hide resolved
@joanx
Copy link
Contributor Author

joanx commented Jun 29, 2022

Updated to promisify APNS registration method, and tested here

Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome awesome. did you happen to check how macOS behaves if you call registerForAPNSNotifications() twice?

e.g. does this work with the new code?

const token1 = await pushNotifications.registerForAPNSNotifications()
const token2 = await pushNotifications.registerForAPNSNotifications()

does the 2nd promise properly resolve (or reject)? i.e. is it not left hanging forever? Also, is the token returned the same?

[edit] confirmed out-of-band that the above works as expected :)

shell/browser/api/electron_api_push_notifications_mac.mm Outdated Show resolved Hide resolved
shell/browser/api/electron_api_push_notifications.h Outdated Show resolved Hide resolved
@joanx
Copy link
Contributor Author

joanx commented Jun 29, 2022

Updated + re-tested!

@tiagoporto
Copy link

Great job @joanx , looking forward to this merge.

@nornagon nornagon merged commit afd08c9 into electron:main Jul 12, 2022
@welcome
Copy link

welcome bot commented Jul 12, 2022

Congrats on merging your first pull request! 🎉🎉🎉

@release-clerk
Copy link

release-clerk bot commented Jul 12, 2022

Release Notes Persisted

Added support for push notifications from APNs for macOS apps.

@KishanBagaria
Copy link
Contributor

Could this be backported to v20?

@erickzhao
Copy link
Member

@KishanBagaria Unfortunately, we generally don't backport features to older branches at this point of the release cycle.

For more information on the process: https://github.com/electron/governance/blob/main/wg-releases/feature-backport-requests.md

@joanx
Copy link
Contributor Author

joanx commented Sep 28, 2022

Hi @nornagon or @erickzhao , do you know when we'd expect to see this in an upcoming release?

@KishanBagaria
Copy link
Contributor

@joanx out in https://github.com/electron/electron/releases/tag/v21.0.0

@JCBsystem
Copy link

@joanx great work!

Is it possible to get the more detailed doc on this ?
whats needed to use it? entitlements / certs / signing .. mas build ...
im stuck on how to get it in to my mas build.
thank you

@sumersao
Copy link

sumersao commented Jan 5, 2024

I have the same question ^ what entitlements do I need to add to get this to work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-review/requested 🗳 new-pr 🌱 PR opened in the last 24 hours no-backport semver/minor backwards-compatible functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants