mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-27 08:21:03 +02:00
Ask permission to use geo-location
This commit is contained in:
parent
66059939a3
commit
cfd63fe46f
@ -3,7 +3,7 @@ const { Platform, PermissionsAndroid } = require('react-native');
|
||||
type rationale = {
|
||||
title: string,
|
||||
message: string,
|
||||
buttonPositive: string,
|
||||
buttonPositive?: string,
|
||||
buttonNegative?: string
|
||||
buttonNeutral?: string
|
||||
}
|
||||
@ -15,5 +15,5 @@ export default async (permissions: string, rationale?: rationale) => {
|
||||
if (result !== PermissionsAndroid.RESULTS.GRANTED) {
|
||||
result = await PermissionsAndroid.request(permissions, rationale);
|
||||
}
|
||||
return result === PermissionsAndroid.RESULTS.GRANTED;
|
||||
return result;
|
||||
};
|
||||
|
@ -4,10 +4,11 @@ import uuid from 'lib/uuid';
|
||||
import Setting from 'lib/models/Setting';
|
||||
import shim from 'lib/shim';
|
||||
import NoteBodyViewer from 'lib/components/NoteBodyViewer/NoteBodyViewer';
|
||||
import checkPermissions from 'lib/checkPermissions';
|
||||
|
||||
const FileViewer = require('react-native-file-viewer').default;
|
||||
const React = require('react');
|
||||
const { Platform, Keyboard, View, TextInput, StyleSheet, Linking, Image, Share } = require('react-native');
|
||||
const { Platform, Keyboard, View, TextInput, StyleSheet, Linking, Image, Share, PermissionsAndroid } = require('react-native');
|
||||
const { connect } = require('react-redux');
|
||||
const { MarkdownEditor } = require('../../../MarkdownEditor/index.js');
|
||||
const RNFS = require('react-native-fs');
|
||||
@ -364,6 +365,23 @@ class NoteScreenComponent extends BaseScreenComponent {
|
||||
};
|
||||
}
|
||||
|
||||
async requestGeoLocationPermissions() {
|
||||
if (!Setting.value('trackLocation')) 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'),
|
||||
});
|
||||
|
||||
// If the user simply pressed "Deny", we don't automatically switch it off because they might accept
|
||||
// once we show the rationale again on second try. If they press "Never again" however we switch it off.
|
||||
// https://github.com/zoontek/react-native-permissions/issues/385#issuecomment-563132396
|
||||
if (response === PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN) {
|
||||
reg.logger().info('Geo-location tracking has been automatically disabled');
|
||||
Setting.setValue('trackLocation', false);
|
||||
}
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
BackButtonService.addHandler(this.backHandler);
|
||||
NavService.addHandler(this.navHandler);
|
||||
@ -380,6 +398,11 @@ class NoteScreenComponent extends BaseScreenComponent {
|
||||
const resourceIds = await Note.linkedResourceIds(this.state.note.body);
|
||||
await ResourceFetcher.instance().markForDownload(resourceIds);
|
||||
}
|
||||
|
||||
// Although it is async, we don't wait for the answer so that if permission
|
||||
// has already been granted, it doesn't slow down opening the note. If it hasn't
|
||||
// been granted, the popup will open anyway.
|
||||
this.requestGeoLocationPermissions();
|
||||
}
|
||||
|
||||
onMarkForDownload(event:any) {
|
||||
|
@ -100,8 +100,8 @@ class ConfigScreenComponent extends BaseScreenComponent {
|
||||
const exportPath = this.state.profileExportPath;
|
||||
const resourcePath = `${exportPath}/resources`;
|
||||
try {
|
||||
const hasPermissions = await checkPermissions(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE);
|
||||
if (!hasPermissions) {
|
||||
const response = await checkPermissions(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE);
|
||||
if (response !== PermissionsAndroid.RESULTS.GRANTED) {
|
||||
throw new Error('Permission denied');
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,9 @@ const { PermissionsAndroid } = require('react-native');
|
||||
export default async (sharedData: SharedData, folderId: string, dispatch: Function) => {
|
||||
|
||||
if (!!sharedData.resources && sharedData.resources.length > 0) {
|
||||
const hasPermissions = await checkPermissions(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE);
|
||||
const response = await checkPermissions(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE);
|
||||
|
||||
if (!hasPermissions) {
|
||||
if (response !== PermissionsAndroid.RESULTS.GRANTED) {
|
||||
ToastAndroid.show('Cannot receive shared data - permission denied', ToastAndroid.SHORT);
|
||||
ShareExtension.close();
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user