Skip to content

Commit

Permalink
feat: ignore AbortError when user cancels file picker
Browse files Browse the repository at this point in the history
  • Loading branch information
acaldas committed Jul 22, 2024
1 parent 50796f2 commit 9c3cf4d
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/utils/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 9c3cf4d

Please sign in to comment.