Skip to content

Commit 0ead47a

Browse files
author
Marcin Mazurek
committed
Prevent app from crashing when cancelling save PDF dialog
1 parent 06fe03f commit 0ead47a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

source/renderer/app/stores/VotingStore.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ export default class VotingStore extends Store {
424424
const intl = i18nContext(currentLocale);
425425

426426
try {
427-
await votingPDFGenerator({
427+
const wasSaved = await votingPDFGenerator({
428428
nextVotingFundNumber,
429429
qrCode,
430430
walletName,
@@ -437,7 +437,10 @@ export default class VotingStore extends Store {
437437
intl,
438438
});
439439
// @ts-ignore ts-migrate(2554) FIXME: Expected 1 arguments, but got 0.
440-
this.actions.voting.saveAsPDFSuccess.trigger();
440+
441+
if (wasSaved) {
442+
this.actions.voting.saveAsPDFSuccess.trigger();
443+
}
441444
} catch (error) {
442445
throw new Error(error);
443446
}

source/renderer/app/utils/votingPDFGenerator.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const votingPDFGenerator = async ({
5757
network,
5858
isMainnet,
5959
intl,
60-
}: Params) => {
60+
}: Params): Promise<boolean> => {
6161
// Consolidate data
6262
const title = intl.formatMessage(messages.title, {
6363
nextVotingFundNumber,
@@ -93,6 +93,11 @@ export const votingPDFGenerator = async ({
9393
};
9494
const dialogPath = await showSaveDialogChannel.send(params);
9595
const filePath = dialogPath.filePath || '';
96+
97+
if (dialogPath.canceled || !!filePath) {
98+
return false;
99+
}
100+
96101
await generateVotingPDFChannel.send({
97102
title,
98103
currentLocale,
@@ -106,4 +111,6 @@ export const votingPDFGenerator = async ({
106111
filePath,
107112
author,
108113
});
114+
115+
return true;
109116
};

0 commit comments

Comments
 (0)