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