Skip to content

Commit

Permalink
fix re-prompting of notifications permission after denied
Browse files Browse the repository at this point in the history
  • Loading branch information
JGreenlee committed Oct 8, 2024
1 parent 944abe8 commit 661ba41
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions www/js/usePermissionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { useTranslation } from 'react-i18next';
import { useAppTheme } from './appTheme';
import { logDebug, logWarn } from './plugin/logger';
import { AlertManager } from './components/AlertBar';
import { storageGet } from './plugin/storage';

const HAS_REQUESTED_NOTIFS_KEY = 'HasRequestedNotificationPermission';

Check warning on line 10 in www/js/usePermissionStatus.ts

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L10

Added line #L10 was not covered by tests

let DEVICE_PLATFORM: 'android' | 'ios';
let DEVICE_VERSION: number;
Expand Down Expand Up @@ -224,7 +227,7 @@ const usePermissionStatus = () => {
}
}

function setupNotificationChecks() {
function setupNotificationChecks(hasRequestedNotifs) {

Check warning on line 230 in www/js/usePermissionStatus.ts

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L230

Added line #L230 was not covered by tests
let fixPerms = () => {
logDebug('fix and refresh notification permissions');
appAndChannelNotificationsCheck.wasRequested = true;
Expand Down Expand Up @@ -252,7 +255,7 @@ const usePermissionStatus = () => {
fix: fixPerms,
refresh: checkPerms,
isOptional: true,
wasRequested: false,
wasRequested: hasRequestedNotifs,
};
let tempChecks = checkList;
tempChecks.push(appAndChannelNotificationsCheck);
Expand Down Expand Up @@ -344,7 +347,7 @@ const usePermissionStatus = () => {
logDebug('Explanation = ' + explanationList);
}

function createChecklist() {
function createChecklist(hasRequestedNotifs) {

Check warning on line 350 in www/js/usePermissionStatus.ts

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L350

Added line #L350 was not covered by tests
setupLocChecks();
setupFitnessChecks();
if (DEVICE_PLATFORM == 'android') {
Expand All @@ -353,7 +356,7 @@ const usePermissionStatus = () => {
}
setupAndroidBackgroundRestrictionChecks();
}
setupNotificationChecks();
setupNotificationChecks(hasRequestedNotifs);

Check warning on line 359 in www/js/usePermissionStatus.ts

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L359

Added line #L359 was not covered by tests
refreshAllChecks(checkList);
}

Expand All @@ -365,11 +368,13 @@ const usePermissionStatus = () => {
//load when ready
useEffect(() => {
if (appConfig && window['device']?.platform) {
DEVICE_PLATFORM = window['device'].platform.toLowerCase();
DEVICE_VERSION = window['device'].version.split('.')[0];
setupPermissionText();
logDebug('setting up permissions');
createChecklist();
storageGet(HAS_REQUESTED_NOTIFS_KEY).then((hasRequestedNotifs) => {
DEVICE_PLATFORM = window['device'].platform.toLowerCase();
DEVICE_VERSION = window['device'].version.split('.')[0];
setupPermissionText();
logDebug('setting up permissions');
createChecklist(hasRequestedNotifs);

Check warning on line 376 in www/js/usePermissionStatus.ts

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L371-L376

Added lines #L371 - L376 were not covered by tests
});
}
}, [appConfig]);

Expand Down

0 comments on commit 661ba41

Please sign in to comment.