Skip to content

Commit

Permalink
fix: use return value of importSelfKeys instead of ImexProgress event
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
link2xt committed Sep 12, 2023
1 parent 2d71371 commit 1ad6e2e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Changed

### Fixed
- Display the toast after successful key import.


<a id="1_40_3"></a>
Expand Down
22 changes: 7 additions & 15 deletions src/renderer/components/dialogs/Settings-ManageKeys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 })
},
})
}
Expand Down

0 comments on commit 1ad6e2e

Please sign in to comment.