Add permission handling
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -30,14 +30,15 @@ const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||||||
const updateSettings = (newSettings: Partial<Settings>) => {
|
const updateSettings = (newSettings: Partial<Settings>) => {
|
||||||
const updatedSettings = { ...settings, ...newSettings };
|
const updatedSettings = { ...settings, ...newSettings };
|
||||||
|
|
||||||
if (settings.storageUri !== updatedSettings.storageUri) {
|
void getPersistedUriPermissions().then(permissions => {
|
||||||
void getPersistedUriPermissions().then(permissions => {
|
permissions.forEach(permission => {
|
||||||
if (permissions.includes(settings.storageUri)) {
|
if (!updatedSettings.storageUri.startsWith(permission + '/')) {
|
||||||
void releasePersistableUriPermission(settings.storageUri);
|
void releasePersistableUriPermission(permission);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
void AsyncStorage.setItem('storageUri', updatedSettings.storageUri);
|
});
|
||||||
}
|
|
||||||
|
void AsyncStorage.setItem('storageUri', updatedSettings.storageUri);
|
||||||
|
|
||||||
setSettings(updatedSettings);
|
setSettings(updatedSettings);
|
||||||
};
|
};
|
||||||
@@ -49,12 +50,23 @@ const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||||||
|
|
||||||
if (storageUri !== '') {
|
if (storageUri !== '') {
|
||||||
const permissions = await getPersistedUriPermissions();
|
const permissions = await getPersistedUriPermissions();
|
||||||
if (!permissions.includes(storageUri)) {
|
if (
|
||||||
|
!permissions.some(permission => storageUri.startsWith(permission + '/'))
|
||||||
|
) {
|
||||||
storageUri = '';
|
storageUri = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const exists = await FileSystem.exists(storageUri);
|
try {
|
||||||
if (!exists) {
|
const exists = await FileSystem.exists(storageUri);
|
||||||
|
if (!exists) {
|
||||||
|
throw new Error('Storage URI does not exist');
|
||||||
|
}
|
||||||
|
|
||||||
|
const isDirectory = await FileSystem.isDir(storageUri);
|
||||||
|
if (!isDirectory) {
|
||||||
|
throw new Error('Storage URI is not a directory');
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
storageUri = '';
|
storageUri = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,7 +87,7 @@ const SettingsProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||||||
settings.storageUri === '' ? (
|
settings.storageUri === '' ? (
|
||||||
<WelcomeScreen
|
<WelcomeScreen
|
||||||
selectStorageLocation={() => {
|
selectStorageLocation={() => {
|
||||||
void openDocumentTree().then(uri => {
|
void openDocumentTree(true).then(uri => {
|
||||||
updateSettings({ storageUri: uri.uri });
|
updateSettings({ storageUri: uri.uri });
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
@@ -60,7 +60,7 @@ const SettingsScreen = () => {
|
|||||||
mode="elevated"
|
mode="elevated"
|
||||||
style={styles.marginBottom}
|
style={styles.marginBottom}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
void openDocumentTree().then(uri => {
|
void openDocumentTree(true).then(uri => {
|
||||||
setSettings({ storageUri: uri.uri });
|
setSettings({ storageUri: uri.uri });
|
||||||
});
|
});
|
||||||
}}>
|
}}>
|
||||||
|
Reference in New Issue
Block a user