Migrate legacy connections
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import { AppState } from '../reducers'
|
import { AppState } from '../reducers'
|
||||||
import { ConnectionOptions, createEmptyConnection, defaultConnections } from '../model/ConnectionOptions'
|
import { ConnectionOptions, createEmptyConnection, makeDefaultConnections } from '../model/ConnectionOptions'
|
||||||
import { default as persistantStorage, StorageIdentifier } from '../PersistantStorage'
|
import { default as persistantStorage, StorageIdentifier } from '../PersistantStorage'
|
||||||
import { Dispatch } from 'redux'
|
import { Dispatch } from 'redux'
|
||||||
import { loadLegacyConnectionSettings } from '../model/LegacyConnectionSettings'
|
import { loadLegacyConnectionOptions } from '../model/LegacyConnectionSettings'
|
||||||
import {
|
import {
|
||||||
ActionTypes,
|
ActionTypes,
|
||||||
Action,
|
Action,
|
||||||
@@ -13,13 +13,9 @@ const storedConnectionsIdentifier: StorageIdentifier<{[s: string]: ConnectionOpt
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const loadConnectionSettings = () => (dispatch: Dispatch<any>, getState: () => AppState) => {
|
export const loadConnectionSettings = () => (dispatch: Dispatch<any>, getState: () => AppState) => {
|
||||||
const requiresMigration = true
|
ensureConnectionsHaveBeenInitialized()
|
||||||
if (requiresMigration) {
|
|
||||||
const connections = defaultConnections()
|
|
||||||
persistantStorage.store(storedConnectionsIdentifier, connections)
|
|
||||||
}
|
|
||||||
|
|
||||||
const connections = persistantStorage.load(storedConnectionsIdentifier)
|
const connections = persistantStorage.load(storedConnectionsIdentifier)
|
||||||
|
|
||||||
if (!connections) {
|
if (!connections) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -96,19 +92,17 @@ export const deleteConnection = (connectionId: string) => (dispatch: Dispatch<an
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function migrateLegacyConfiguration() {
|
export function ensureConnectionsHaveBeenInitialized() {
|
||||||
const storage = persistantStorage.load(storedConnectionsIdentifier)
|
const connections = persistantStorage.load(storedConnectionsIdentifier)
|
||||||
if (storage) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const connections = loadLegacyConnectionSettings()
|
|
||||||
defaultConnections()
|
|
||||||
}
|
|
||||||
|
|
||||||
export function addDefaultConnections() {
|
const requiresInitialization = !connections
|
||||||
const storage = persistantStorage.load(storedConnectionsIdentifier)
|
if (requiresInitialization) {
|
||||||
if (storage) {
|
console.log('requires initialization')
|
||||||
return
|
const migratedConnection = loadLegacyConnectionOptions()
|
||||||
|
const defaultConnections = makeDefaultConnections()
|
||||||
|
persistantStorage.store(storedConnectionsIdentifier, {
|
||||||
|
...migratedConnection,
|
||||||
|
...defaultConnections,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
defaultConnections()
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class TreeNodeSubnodes extends React.Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public componentWillUnmount() {
|
public componentWillUnmount() {
|
||||||
window.cancelAnimationFrame(this.renderMoreAnimationFrame)
|
window.cancelIdleCallback(this.renderMoreAnimationFrame)
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
|
|||||||
@@ -13,17 +13,21 @@ interface LegacyConnectionSettings {
|
|||||||
password: string
|
password: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadLegacyConnectionSettings(): ConnectionOptions | undefined {
|
export function clearLegacyConnectionOptions() {
|
||||||
|
window.localStorage.setItem('connectionSettings', '')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function loadLegacyConnectionOptions(): {[s: string]: ConnectionOptions} | {} {
|
||||||
const legacySettingsString = window.localStorage.getItem('connectionSettings')
|
const legacySettingsString = window.localStorage.getItem('connectionSettings')
|
||||||
if (!legacySettingsString) {
|
if (!legacySettingsString) {
|
||||||
return
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
let legacyConnection
|
let legacyConnection
|
||||||
try {
|
try {
|
||||||
legacyConnection = JSON.parse(legacySettingsString) as LegacyConnectionSettings
|
legacyConnection = JSON.parse(legacySettingsString) as LegacyConnectionSettings
|
||||||
} catch {
|
} catch {
|
||||||
return
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
const protocolMap: {[s: string]: string} = {
|
const protocolMap: {[s: string]: string} = {
|
||||||
@@ -44,8 +48,12 @@ export function loadLegacyConnectionSettings(): ConnectionOptions | undefined {
|
|||||||
encryption: legacyConnection.tls,
|
encryption: legacyConnection.tls,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const emptyConnection = createEmptyConnection()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...createEmptyConnection(),
|
[emptyConnection.id]: {
|
||||||
...migratedOptions,
|
...emptyConnection,
|
||||||
|
...migratedOptions,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user