Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: crash after export is complete on android

ammarahm-ede3ffa534807e
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 {
</style>`;
+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');