From e3ffa534807e4015b3811c74bcd2bd8420ba1ad8 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Mon, 15 Aug 2022 20:43:34 +0500 Subject: [PATCH] fix: crash after export is complete on android --- apps/mobile/src/services/exporter.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/apps/mobile/src/services/exporter.js b/apps/mobile/src/services/exporter.js index 99603ce6e..52646882b 100644 --- a/apps/mobile/src/services/exporter.js +++ b/apps/mobile/src/services/exporter.js @@ -312,6 +312,15 @@ hr { `; +async function releasePermissions(path) { + const uris = await ScopedStorage.getPersistedUriPermissions(); + for (let uri of uris) { + if (path.startsWith(uri)) { + await ScopedStorage.releasePersistableUriPermission(uri); + } + } +} + async function saveToPDF(note) { let androidSavePath = '/Notesnook/exported/PDF'; if (Platform.OS === 'android') { @@ -358,12 +367,14 @@ async function saveToPDF(note) { 'base64', false ); - await ScopedStorage.releasePersistableUriPermission(androidSavePath); + if (res.filePath) { await RNFetchBlob.fs.unlink(res.filePath); } } + await releasePermissions(androidSavePath); + return { filePath: fileUri || res.filePath, type: 'application/pdf', @@ -393,7 +404,7 @@ async function saveToMarkdown(note) { 'utf8', false ); - await ScopedStorage.releasePersistableUriPermission(path); + await releasePermissions(path); } else { path = path + fileName + '.md'; await RNFetchBlob.fs.writeFile(path, markdown, 'utf8'); @@ -428,7 +439,7 @@ async function saveToText(note) { 'utf8', false ); - await ScopedStorage.releasePersistableUriPermission(path); + await releasePermissions(path); } else { path = path + fileName + '.txt'; await RNFetchBlob.fs.writeFile(path, text, 'utf8'); @@ -469,7 +480,7 @@ async function saveToHTML(note) { 'utf8', false ); - await ScopedStorage.releasePersistableUriPermission(path); + await releasePermissions(path); } else { path = path + fileName + '.html'; await RNFetchBlob.fs.writeFile(path, html3, 'utf8');