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
|
// Not implemented yet
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return await checkPermissions(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, {
|
return await checkPermissions(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, { rationale: {
|
||||||
title: _('Information'),
|
title: _('Information'),
|
||||||
message: _('In order to use file system synchronisation your permission to write to external storage is required.'),
|
message: _('In order to use file system synchronisation your permission to write to external storage is required.'),
|
||||||
buttonPositive: _('OK'),
|
buttonPositive: _('OK'),
|
||||||
});
|
} });
|
||||||
}
|
}
|
||||||
|
|
||||||
public UNSAFE_componentWillMount() {
|
public UNSAFE_componentWillMount() {
|
||||||
|
|||||||
@@ -543,8 +543,17 @@ class NoteScreenComponent extends BaseScreenComponent<ComponentProps, State> imp
|
|||||||
if (Platform.OS === 'web') return;
|
if (Platform.OS === 'web') return;
|
||||||
|
|
||||||
const response = await checkPermissions(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, {
|
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.'),
|
onRequestConfirmation: async () => {
|
||||||
title: _('Permission needed'),
|
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
|
// 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';
|
import Logger from '@joplin/utils/Logger';
|
||||||
|
|
||||||
const { Platform, PermissionsAndroid } = require('react-native');
|
import { Platform, PermissionsAndroid, Permission } from 'react-native';
|
||||||
const logger = Logger.create('checkPermissions');
|
const logger = Logger.create('checkPermissions');
|
||||||
|
|
||||||
type rationale = {
|
type Rationale = {
|
||||||
title: string;
|
title: string;
|
||||||
message: string;
|
message: string;
|
||||||
buttonPositive?: string;
|
buttonPositive: string;
|
||||||
buttonNegative?: string;
|
buttonNegative?: string;
|
||||||
buttonNeutral?: 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.
|
// On iOS, permissions are prompted for by the system, so here we assume it's granted.
|
||||||
if (Platform.OS !== 'android') return PermissionsAndroid.RESULTS.GRANTED;
|
if (Platform.OS !== 'android') return PermissionsAndroid.RESULTS.GRANTED;
|
||||||
|
|
||||||
let result = await PermissionsAndroid.check(permissions);
|
const granted = await PermissionsAndroid.check(permissions);
|
||||||
logger.info('Checked permission:', result);
|
logger.info('Checked permission:', granted);
|
||||||
if (result !== PermissionsAndroid.RESULTS.GRANTED) {
|
if (granted) {
|
||||||
result = await PermissionsAndroid.request(permissions, rationale);
|
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);
|
logger.info('Requested permission:', result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user