Skip to content

Commit 7a243f4

Browse files
committed
fix executing state on PermissionUtils
There was an early return on shouldBeUpdated that caused executing to never become false again. To prevent this issue with future code changes made a new privateTriggerNotificationPermissionChanged to encapsulate the executing state. Also added a try..finally to prevent throwing from creating a bad state.
1 parent 4df9146 commit 7a243f4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/utils/PermissionUtils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,17 @@ export class PermissionUtils {
1414
if (PermissionUtils.executing) {
1515
return;
1616
}
17+
1718
PermissionUtils.executing = true;
19+
try {
20+
await PermissionUtils.privateTriggerNotificationPermissionChanged(updateIfIdentical);
21+
}
22+
finally {
23+
PermissionUtils.executing = false;
24+
}
25+
}
1826

27+
private static async privateTriggerNotificationPermissionChanged(updateIfIdentical: boolean) {
1928
const newPermission = await OneSignal.privateGetNotificationPermission();
2029
const previousPermission = await Database.get('Options', 'notificationPermission');
2130

@@ -26,6 +35,5 @@ export class PermissionUtils {
2635

2736
await Database.put('Options', { key: 'notificationPermission', value: newPermission });
2837
Event.trigger(OneSignal.EVENTS.NATIVE_PROMPT_PERMISSIONCHANGED, { to: newPermission });
29-
PermissionUtils.executing = false;
3038
}
3139
}

0 commit comments

Comments
 (0)