fix: APNS token ids are lowercase ASCII (#46149)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2025-03-20 16:52:23 -05:00 committed by GitHub
parent cee2c2ceeb
commit 1ba56c8696
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 9 deletions

View file

@ -46,4 +46,7 @@ See: https://developer.apple.com/documentation/appkit/nsapplication/1428476-regi
### `pushNotifications.unregisterForAPNSNotifications()` _macOS_ ### `pushNotifications.unregisterForAPNSNotifications()` _macOS_
Unregisters the app from notifications received from APNS. Unregisters the app from notifications received from APNS.
Apps unregistered through this method can always reregister.
See: https://developer.apple.com/documentation/appkit/nsapplication/1428747-unregisterforremotenotifications?language=objc See: https://developer.apple.com/documentation/appkit/nsapplication/1428747-unregisterforremotenotifications?language=objc

View file

@ -19,10 +19,7 @@ v8::Local<v8::Promise> PushNotifications::RegisterForAPNSNotifications(
gin_helper::Promise<std::string> promise(isolate); gin_helper::Promise<std::string> promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle(); v8::Local<v8::Promise> handle = promise.GetHandle();
[[AtomApplication sharedApplication] [[AtomApplication sharedApplication] registerForRemoteNotifications];
registerForRemoteNotificationTypes:NSRemoteNotificationTypeBadge |
NSRemoteNotificationTypeAlert |
NSRemoteNotificationTypeSound];
PushNotifications::apns_promise_set_.emplace_back(std::move(promise)); PushNotifications::apns_promise_set_.emplace_back(std::move(promise));
return handle; return handle;
@ -30,8 +27,7 @@ v8::Local<v8::Promise> PushNotifications::RegisterForAPNSNotifications(
void PushNotifications::ResolveAPNSPromiseSetWithToken( void PushNotifications::ResolveAPNSPromiseSetWithToken(
const std::string& token_string) { const std::string& token_string) {
std::vector<gin_helper::Promise<std::string>> promises = auto promises = std::move(PushNotifications::apns_promise_set_);
std::move(PushNotifications::apns_promise_set_);
for (auto& promise : promises) { for (auto& promise : promises) {
promise.Resolve(token_string); promise.Resolve(token_string);
} }
@ -39,8 +35,7 @@ void PushNotifications::ResolveAPNSPromiseSetWithToken(
void PushNotifications::RejectAPNSPromiseSetWithError( void PushNotifications::RejectAPNSPromiseSetWithError(
const std::string& error_message) { const std::string& error_message) {
std::vector<gin_helper::Promise<std::string>> promises = auto promises = std::move(PushNotifications::apns_promise_set_);
std::move(PushNotifications::apns_promise_set_);
for (auto& promise : promises) { for (auto& promise : promises) {
promise.RejectWithErrorMessage(error_message); promise.RejectWithErrorMessage(error_message);
} }

View file

@ -180,8 +180,10 @@ static NSDictionary* UNNotificationResponseToNSDictionary(
didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken { didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
// Resolve outstanding APNS promises created during registration attempts // Resolve outstanding APNS promises created during registration attempts
if (auto* push_notifications = electron::api::PushNotifications::Get()) { if (auto* push_notifications = electron::api::PushNotifications::Get()) {
std::string encoded =
base::HexEncode(electron::util::as_byte_span(deviceToken));
push_notifications->ResolveAPNSPromiseSetWithToken( push_notifications->ResolveAPNSPromiseSetWithToken(
base::HexEncode(electron::util::as_byte_span(deviceToken))); base::ToLowerASCII(encoded));
} }
} }