fix certificate selection

This commit is contained in:
Thomas Nordquist
2022-02-27 13:33:22 +01:00
parent e4add31793
commit 13b8f8d5da
42 changed files with 23477 additions and 5471 deletions

View File

@@ -9,12 +9,14 @@ import {
import { default as persistentStorage, StorageIdentifier } from '../utils/PersistentStorage'
import { Dispatch } from 'redux'
import { showError } from './Global'
import { remote } from 'electron'
import * as electron from 'electron'
import { promises as fsPromise } from 'fs'
import * as path from 'path'
import { ActionTypes, Action } from '../reducers/ConnectionManager'
import { Subscription } from '../../../backend/src/DataSource/MqttSource'
import { connectionsMigrator } from './migrations/Connection'
import { EventDispatcher, openDialogResponse, OpenDialogResponse, rendererEvents, requestOpenDialog } from '../../../events'
import { v4 } from 'uuid'
export interface ConnectionDictionary {
[s: string]: ConnectionOptions
@@ -72,11 +74,29 @@ async function openCertificate(): Promise<CertificateParameters> {
certificateSizeDoesNotMatch: 'Certificate size larger/smaller then expected.',
}
const openDialogReturnValue = await remote.dialog.showOpenDialog(remote.getCurrentWindow(), {
properties: ['openFile'],
securityScopedBookmarks: true,
let requestId = v4();
const response = new Promise<OpenDialogResponse>((resolve, reject) => {
let callback = (result: OpenDialogResponse) => {
rendererEvents.unsubscribe(openDialogResponse(), callback)
if (result.identifier == requestId) {
resolve(result)
} else {
reject(new Error("Unexpected file select"))
}
}
rendererEvents.subscribe(openDialogResponse(), callback)
})
rendererEvents.emit(requestOpenDialog(), {
identifier: requestId,
options: {
properties: ['openFile'],
securityScopedBookmarks: true,
}
})
const openDialogReturnValue = (await response).result;
const selectedFile = openDialogReturnValue.filePaths && openDialogReturnValue.filePaths[0]
if (!selectedFile) {
throw rejectReasons.noCertificateSelected

View File

@@ -1,7 +1,7 @@
import { ActionTypes, ConfirmationRequest } from '../reducers/Global'
import { Dispatch } from 'redux'
export const showError = (error?: string) => ({
export const showError = (error?: string | unknown) => ({
error,
type: ActionTypes.showError,
})