From 1ad6e2e15ab78dc03316d37520610a0e674f7b51 Mon Sep 17 00:00:00 2001 From: link2xt Date: Tue, 12 Sep 2023 16:00:59 +0000 Subject: [PATCH] fix: use return value of importSelfKeys instead of ImexProgress event This makes the code similar to the export code. Without this fix the toast "Secret keys imported from ..." is not displayed when I tested, probably due to the race condition between getting the ImexProgress event and removing the handler. --- CHANGELOG.md | 1 + .../dialogs/Settings-ManageKeys.tsx | 22 ++++++------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0f0a6a7dc..8f0148021b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Changed ### Fixed +- Display the toast after successful key import. diff --git a/src/renderer/components/dialogs/Settings-ManageKeys.tsx b/src/renderer/components/dialogs/Settings-ManageKeys.tsx index 78ff0026a0..a6b3deb04a 100644 --- a/src/renderer/components/dialogs/Settings-ManageKeys.tsx +++ b/src/renderer/components/dialogs/Settings-ManageKeys.tsx @@ -5,7 +5,6 @@ import type { OpenDialogOptions } from 'electron' import { runtime } from '../../runtime' import { BackendRemote } from '../../backend-com' import { selectedAccountId } from '../../ScreenController' -import { DcEventType } from '@deltachat/jsonrpc-client' async function onKeysImport() { const tx = window.static_translate @@ -25,24 +24,17 @@ async function onKeysImport() { message: tx('pref_managekeys_import_explain', filename), confirmLabel: tx('yes'), cancelLabel: tx('no'), - cb: (yes: boolean) => { + cb: async (yes: boolean) => { if (!yes) { return } const text = tx('pref_managekeys_secret_keys_imported_from_x', filename) - const onImexProgress = ({ progress }: DcEventType<'ImexProgress'>) => { - if (progress !== 1000) { - return - } - window.__userFeedback({ type: 'success', text }) - } - const emitter = BackendRemote.getContextEvents(selectedAccountId()) - emitter.on('ImexProgress', onImexProgress) - BackendRemote.rpc - .importSelfKeys(selectedAccountId(), filename, null) - .finally(() => { - emitter.off('ImexProgress', onImexProgress) - }) + await BackendRemote.rpc.importSelfKeys( + selectedAccountId(), + filename, + null + ) + window.__userFeedback({ type: 'success', text }) }, }) }