1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/packages/app-mobile/utils/checkPermissions.ts
2023-07-27 16:08:11 +01:00

26 lines
827 B
TypeScript

import Logger from '@joplin/utils/Logger';
const { Platform, PermissionsAndroid } = require('react-native');
const logger = Logger.create('checkPermissions');
type rationale = {
title: string;
message: string;
buttonPositive?: string;
buttonNegative?: string;
buttonNeutral?: string;
};
export default async (permissions: string, rationale?: rationale) => {
// 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);
logger.info('Requested permission:', result);
}
return result;
};