fix certificate selection
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user