From 9c3cf4d47b1d28442b21c491e7443c48969b5140 Mon Sep 17 00:00:00 2001 From: acaldas Date: Mon, 22 Jul 2024 13:42:32 +0100 Subject: [PATCH] feat: ignore AbortError when user cancels file picker --- src/utils/file.ts | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/utils/file.ts b/src/utils/file.ts index 72b32a00..2c111b61 100644 --- a/src/utils/file.ts +++ b/src/utils/file.ts @@ -36,19 +36,25 @@ export async function exportFile( await downloadFile(document); return; } + try { + const fileHandle = await window.showSaveFilePicker({ + suggestedName: `${document.name || 'Untitled'}.${ + extension ? `${extension}.` : '' + }zip`, + }); - const fileHandle = await window.showSaveFilePicker({ - suggestedName: `${document.name || 'Untitled'}.${ - extension ? `${extension}.` : '' - }zip`, - }); - - await documentModel.utils.saveToFileHandle(document, fileHandle); - const path = (await fileHandle.getFile()).path; - if (typeof window !== 'undefined') { - window.electronAPI?.fileSaved(document, path); + await documentModel.utils.saveToFileHandle(document, fileHandle); + const path = (await fileHandle.getFile()).path; + if (typeof window !== 'undefined') { + window.electronAPI?.fileSaved(document, path); + } + return path; + } catch (e) { + // ignores error if user cancelled the file picker + if (!(e instanceof DOMException && e.name === 'AbortError')) { + throw e; + } } - return path; } export async function loadFile(