Skip to content

Commit

Permalink
fix(messaging): promise resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz committed Sep 4, 2022
1 parent 1a4a0fe commit 0db80d4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/firebase-messaging-core/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const onNotificationTapCallbacks: Set<(message: any) => void> = new Set();

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

function register(args: any) {
if (!lastActivity) {
Expand All @@ -63,8 +63,10 @@ function register(args: any) {
new androidx.activity.result.contract.ActivityResultContracts.RequestPermission(),
new androidx.activity.result.ActivityResultCallback({
onActivityResult(isGranted: boolean) {
_resolve?.(isGranted ? 0 : 1);
_resolve = undefined;
_permissionQueue.forEach((callback) => {
callback.resolve(isGranted ? 0 : 1);
});
_permissionQueue.splice(0);
},
})
);
Expand Down Expand Up @@ -307,7 +309,10 @@ export class MessagingCore implements IMessagingCore {

return new Promise((resolve, reject) => {
const launch = (activity) => {
_resolve = resolve;
_permissionQueue.push({
resolve,
reject,
});
requestPermissionLauncher.launch((android as any).Manifest.permission.POST_NOTIFICATIONS);
};

Expand Down

0 comments on commit 0db80d4

Please sign in to comment.