From 1d28703a3dbe388af29e248adb6462dd7e4b5fb6 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Sat, 12 Aug 2023 10:07:38 +0500 Subject: [PATCH] mobile: fix crash if file not found on export --- apps/mobile/app/services/exporter.js | 34 ++++++++++++++++------------ 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/apps/mobile/app/services/exporter.js b/apps/mobile/app/services/exporter.js index 4b4644a62..86f57fb86 100644 --- a/apps/mobile/app/services/exporter.js +++ b/apps/mobile/app/services/exporter.js @@ -82,21 +82,25 @@ async function getPath(type) { */ async function save(path, data, fileName, extension) { let uri; - if (Platform.OS === "android") { - uri = await ScopedStorage.writeFile( - path, - data, - `${fileName}.${extension}`, - MIMETypes[extension], - extension === "pdf" ? "base64" : "utf8", - false - ); - await releasePermissions(path); - } else { - path = path + fileName + `.${extension}`; - await RNFetchBlob.fs.writeFile(path, data, "utf8"); + try { + if (Platform.OS === "android") { + uri = await ScopedStorage.writeFile( + path, + data, + `${fileName}.${extension}`, + MIMETypes[extension], + extension === "pdf" ? "base64" : "utf8", + false + ); + await releasePermissions(path); + } else { + path = path + fileName + `.${extension}`; + await RNFetchBlob.fs.writeFile(path, data, "utf8"); + } + return uri || path; + } catch (e) { + return undefined; } - return uri || path; } async function makeHtml(note) { @@ -176,6 +180,8 @@ async function exportNote(note, type) { path = await save(path, result, fileName, type); } + if (!path) return null; + return { filePath: path, type: "text/plain",