You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-23 22:36:32 +02:00
Android: Improve location permission request (#13248)
This commit is contained in:
@@ -231,11 +231,11 @@ class ConfigScreenComponent extends BaseScreenComponent<ConfigScreenProps, Confi
|
||||
// Not implemented yet
|
||||
return true;
|
||||
}
|
||||
return await checkPermissions(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, {
|
||||
return await checkPermissions(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, { rationale: {
|
||||
title: _('Information'),
|
||||
message: _('In order to use file system synchronisation your permission to write to external storage is required.'),
|
||||
buttonPositive: _('OK'),
|
||||
});
|
||||
} });
|
||||
}
|
||||
|
||||
public UNSAFE_componentWillMount() {
|
||||
|
||||
@@ -543,8 +543,17 @@ class NoteScreenComponent extends BaseScreenComponent<ComponentProps, State> 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
|
||||
|
||||
@@ -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<boolean>;
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user