diff --git a/packages/app-mobile/components/screens/ConfigScreen/ConfigScreen.tsx b/packages/app-mobile/components/screens/ConfigScreen/ConfigScreen.tsx index 79abad7c77..11914e4c97 100644 --- a/packages/app-mobile/components/screens/ConfigScreen/ConfigScreen.tsx +++ b/packages/app-mobile/components/screens/ConfigScreen/ConfigScreen.tsx @@ -231,11 +231,11 @@ class ConfigScreenComponent extends BaseScreenComponent imp if (Platform.OS === 'web') return; const response = await checkPermissions(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, { - message: _('In order to associate a geo-location with the note, the app needs your permission to access your location.\n\nYou may turn off this option at any time in the Configuration screen.'), - title: _('Permission needed'), + onRequestConfirmation: async () => { + const yesIndex = 0; + const result = await shim.showMessageBox( + _('Joplin supports saving the location at which notes are saved or created. Do you want to enable it? This can be changed at any time in settings.'), + { + buttons: [_('Yes'), _('No')], + title: _('Save geolocation?'), + }, + ); + return result === yesIndex; + }, }); // If the user simply pressed "Deny", we don't automatically switch it off because they might accept diff --git a/packages/app-mobile/utils/checkPermissions.ts b/packages/app-mobile/utils/checkPermissions.ts index 67402ccc65..cc93d393bc 100644 --- a/packages/app-mobile/utils/checkPermissions.ts +++ b/packages/app-mobile/utils/checkPermissions.ts @@ -1,25 +1,36 @@ import Logger from '@joplin/utils/Logger'; -const { Platform, PermissionsAndroid } = require('react-native'); +import { Platform, PermissionsAndroid, Permission } from 'react-native'; const logger = Logger.create('checkPermissions'); -type rationale = { +type Rationale = { title: string; message: string; - buttonPositive?: string; + buttonPositive: string; buttonNegative?: string; buttonNeutral?: string; }; -export default async (permissions: string, rationale?: rationale) => { +interface Options { + rationale?: Rationale; + onRequestConfirmation?: ()=> Promise; +} + +export default async (permissions: Permission, { rationale, onRequestConfirmation }: Options = {}) => { // On iOS, permissions are prompted for by the system, so here we assume it's granted. if (Platform.OS !== 'android') return PermissionsAndroid.RESULTS.GRANTED; - let result = await PermissionsAndroid.check(permissions); - logger.info('Checked permission:', result); - if (result !== PermissionsAndroid.RESULTS.GRANTED) { - result = await PermissionsAndroid.request(permissions, rationale); + const granted = await PermissionsAndroid.check(permissions); + logger.info('Checked permission:', granted); + if (granted) { + return PermissionsAndroid.RESULTS.GRANTED; + } else { + if (onRequestConfirmation && !await onRequestConfirmation()) { + return PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN; + } + + const result = await PermissionsAndroid.request(permissions, rationale); logger.info('Requested permission:', result); + return result; } - return result; };