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,
})

View File

@@ -13,6 +13,8 @@ import { connect } from 'react-redux'
import { globalActions, settingsActions } from '../actions'
import { Theme, withStyles } from '@material-ui/core/styles'
(window as any).global = window
const Settings = React.lazy(() => import('./SettingsDrawer/Settings'))
const ContentView = React.lazy(() => import('./Layout/ContentView'))
@@ -66,6 +68,8 @@ class App extends React.PureComponent<Props, {}> {
return null
}
const anyProps: any = {};
return (
<div className={centerContent}>
<CssBaseline />
@@ -73,7 +77,7 @@ class App extends React.PureComponent<Props, {}> {
<ConfirmationDialog confirmationRequests={this.props.confirmationRequests} />
{this.renderNotification()}
<React.Suspense fallback={<div></div>}>
<Settings />
<Settings {...anyProps} />
</React.Suspense>
<div className={centerContent}>
<div className={`${settingsVisible ? contentShift : content}`}>

View File

@@ -1,6 +1,6 @@
import * as React from 'react'
import { Theme, withStyles } from '@material-ui/core'
import cursor from './cursor.png'
const cursor = require('./cursor.png')
interface State {
enabled: boolean
@@ -43,15 +43,15 @@ class Demo extends React.Component<{ classes: any }, State> {
}
public componentDidMount() {
;(window as any).demo.enableMouse = () => {
; (window as any).demo.enableMouse = () => {
this.setState({ enabled: true })
}
;(window as any).demo.moveMouse = (x: number, y: number, animationTime: number) => {
const stepSizeX = Math.abs(this.state.position.x - x) / (animationTime / this.frameInterval)
const stepSizeY = Math.abs(this.state.position.y - y) / (animationTime / this.frameInterval)
this.setState({ stepSizeX, stepSizeY, enabled: true, target: { x, y } })
this.moveCloser()
}
; (window as any).demo.moveMouse = (x: number, y: number, animationTime: number) => {
const stepSizeX = Math.abs(this.state.position.x - x) / (animationTime / this.frameInterval)
const stepSizeY = Math.abs(this.state.position.y - y) / (animationTime / this.frameInterval)
this.setState({ stepSizeX, stepSizeY, enabled: true, target: { x, y } })
this.moveCloser()
}
}
public render() {

View File

@@ -5,14 +5,14 @@ let heapdump: any
function writeHeapdump(path?: string) {
if (!heapdump) {
heapdump = require('heapdump')
//heapdump = require('heapdump')
}
heapdump.writeSnapshot(path || `${Date.now()}.heapsnapshot`)
return path
}
;(window as any).demo = {
; (window as any).demo = {
writeHeapdump,
}

View File

@@ -2,7 +2,6 @@ import * as React from 'react'
import PersistentStorage from '../utils/PersistentStorage'
import SentimentDissatisfied from '@material-ui/icons/SentimentDissatisfied'
import Warning from '@material-ui/icons/Warning'
import { electronRendererTelemetry } from 'electron-telemetry'
import { Theme, withStyles } from '@material-ui/core/styles'
import { Button, Modal, Paper, Toolbar, Typography } from '@material-ui/core'
@@ -33,7 +32,7 @@ class ErrorBoundary extends React.PureComponent<Props, State> {
}
public componentDidCatch(error: Error, errorInfo: any) {
electronRendererTelemetry.trackError(error)
// electronRendererTelemetry.trackError(error)
console.log('did catch', error)
}

View File

@@ -3,10 +3,10 @@ import DateFormatter from '../helper/DateFormatter'
import { AppState } from '../../reducers'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { Input, InputLabel, MenuItem, Select, StyleRulesCallback, Theme } from '@material-ui/core'
import { Input, InputLabel, MenuItem, Select, Theme } from '@material-ui/core'
import { settingsActions } from '../../actions'
import { withStyles } from '@material-ui/styles'
const moment = require('moment/min/moment-with-locales')
const moment = require('moment')
interface Props {
actions: {

View File

@@ -122,7 +122,7 @@ const EditorMode = memo(function EditorMode(props: {
const str = JSON.stringify(JSON.parse(props.payload), undefined, ' ')
updatePayload(str)
} catch (error) {
props.globalActions.showError(`Format error: ${error.message}`)
props.globalActions.showError(`Format error: ${(error as Error)?.message}`)
}
}
}, [props.payload])

View File

@@ -50,7 +50,7 @@ class UpdateNotifier extends React.PureComponent<Props, State> {
super(props)
this.state = { newerVersions: [] }
const ownVersion = electron.remote.app.getVersion()
const ownVersion = electron.app.getVersion()
this.fetchReleases().then(releases => {
const newerVersions = releases
.filter(release => this.allowPrereleaseIfOwnVersionIsBeta(release, ownVersion))

View File

@@ -1,4 +1,4 @@
import { electronRendererTelemetry } from 'electron-telemetry'
// import { electronRendererTelemetry } from 'electron-telemetry'
const telemetry = electronRendererTelemetry
electronRendererTelemetry.registerErrorHandler()
// const telemetry = electronRendererTelemetry
// electronRendererTelemetry.registerErrorHandler()

View File

@@ -1,4 +1,4 @@
import { electronRendererTelemetry } from 'electron-telemetry'
// import { electronRendererTelemetry } from 'electron-telemetry'
// Used to determine long-time-stability and memory leaks
function trackProcessStatistics() {
@@ -30,6 +30,6 @@ export function trackEvent(name: string) {
}
const blacklist = ['CONNECTION_SET_HEALTH']
if (blacklist.indexOf(name) === -1) {
electronRendererTelemetry.trackEvent(name)
// electronRendererTelemetry.trackEvent(name)
}
}