You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-29 22:48:10 +02:00
Android: Check filesystem permission if filesystem sync target is selected (#1665)
* Android: Check filesystem permission if filesystem sync target is selected * Android: Change permission error text, don't prevent user from saving settings
This commit is contained in:
committed by
Laurent Cozic
parent
85bf89fd97
commit
f6b0da3f5e
@@ -17,6 +17,7 @@ const { time } = require('lib/time-utils');
|
|||||||
const SearchEngine = require('lib/services/SearchEngine');
|
const SearchEngine = require('lib/services/SearchEngine');
|
||||||
const RNFS = require('react-native-fs');
|
const RNFS = require('react-native-fs');
|
||||||
|
|
||||||
|
import { PermissionsAndroid } from 'react-native';
|
||||||
import Slider from '@react-native-community/slider';
|
import Slider from '@react-native-community/slider';
|
||||||
|
|
||||||
class ConfigScreenComponent extends BaseScreenComponent {
|
class ConfigScreenComponent extends BaseScreenComponent {
|
||||||
@@ -43,7 +44,22 @@ class ConfigScreenComponent extends BaseScreenComponent {
|
|||||||
NavService.go('EncryptionConfig');
|
NavService.go('EncryptionConfig');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.saveButton_press = () => {
|
this.saveButton_press = async () => {
|
||||||
|
if (
|
||||||
|
this.state.changedSettingKeys.includes('sync.target')
|
||||||
|
&& this.state.settings['sync.target'] === SyncTargetRegistry.nameToId('filesystem')
|
||||||
|
&& !await this.checkFilesystemPermission()
|
||||||
|
) {
|
||||||
|
Alert.alert(
|
||||||
|
_('Warning'),
|
||||||
|
_(
|
||||||
|
'Joplin does not have permission to access "%s". ' +
|
||||||
|
'Either choose a different sync target, ' +
|
||||||
|
'or give Joplin the "Storage" permission.',
|
||||||
|
this.state.settings['sync.2.path'],
|
||||||
|
));
|
||||||
|
// Save settings anyway, even if permission has not been granted
|
||||||
|
}
|
||||||
return shared.saveSettings(this);
|
return shared.saveSettings(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -90,6 +106,30 @@ class ConfigScreenComponent extends BaseScreenComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async checkFilesystemPermission() {
|
||||||
|
if (Platform.OS !== 'android') {
|
||||||
|
// Not implemented yet
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const hasPermission = await PermissionsAndroid.check(
|
||||||
|
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE);
|
||||||
|
if (hasPermission) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const requestResult = await PermissionsAndroid.request(
|
||||||
|
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
|
||||||
|
{
|
||||||
|
title: _('Permission to write to external storage'),
|
||||||
|
message: _(
|
||||||
|
'In order to use file system synchronization your ' +
|
||||||
|
'permission to write to external storage is required.'
|
||||||
|
),
|
||||||
|
buttonPositive: _('OK'),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return (requestResult === PermissionsAndroid.RESULTS.GRANTED);
|
||||||
|
}
|
||||||
|
|
||||||
UNSAFE_componentWillMount() {
|
UNSAFE_componentWillMount() {
|
||||||
this.setState({ settings: this.props.settings });
|
this.setState({ settings: this.props.settings });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user