Skip to content

Commit 0db80d4

Browse files
committed
fix(messaging): promise resolve
1 parent 1a4a0fe commit 0db80d4

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/firebase-messaging-core/index.android.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const onNotificationTapCallbacks: Set<(message: any) => void> = new Set();
5454

5555
let lastActivity: WeakRef<androidx.appcompat.app.AppCompatActivity>;
5656
let requestPermissionLauncher: androidx.activity.result.ActivityResultLauncher<any>;
57-
let _resolve;
57+
let _permissionQueue: { resolve: Function; reject: Function }[] = [];
5858

5959
function register(args: any) {
6060
if (!lastActivity) {
@@ -63,8 +63,10 @@ function register(args: any) {
6363
new androidx.activity.result.contract.ActivityResultContracts.RequestPermission(),
6464
new androidx.activity.result.ActivityResultCallback({
6565
onActivityResult(isGranted: boolean) {
66-
_resolve?.(isGranted ? 0 : 1);
67-
_resolve = undefined;
66+
_permissionQueue.forEach((callback) => {
67+
callback.resolve(isGranted ? 0 : 1);
68+
});
69+
_permissionQueue.splice(0);
6870
},
6971
})
7072
);
@@ -307,7 +309,10 @@ export class MessagingCore implements IMessagingCore {
307309

308310
return new Promise((resolve, reject) => {
309311
const launch = (activity) => {
310-
_resolve = resolve;
312+
_permissionQueue.push({
313+
resolve,
314+
reject,
315+
});
311316
requestPermissionLauncher.launch((android as any).Manifest.permission.POST_NOTIFICATIONS);
312317
};
313318

0 commit comments

Comments
 (0)