Skip to content

Commit

Permalink
fix(settings): settings migration from 1.3 to 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
NPavie committed Jun 10, 2024
1 parent 3ce5b3a commit a67600e
Showing 1 changed file with 55 additions and 6 deletions.
61 changes: 55 additions & 6 deletions src/shared/types/settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PipelineInstanceProperties, Webservice } from './pipeline'
import { TtsConfig } from './ttsConfig'
import { TtsConfig, TtsEngineProperty, TtsVoice } from './ttsConfig'

export enum ColorScheme {
system = 'System default mode',
Expand Down Expand Up @@ -40,7 +40,10 @@ export type ApplicationSettings = {
}

export function migrateSettings(
settings: ApplicationSettings | _ApplicationSettings_v0
settings:
| ApplicationSettings
| _ApplicationSettings_v130
| _ApplicationSettings_v0
): ApplicationSettings {
// Take the content of the settings file
// And apply migration process in order based on current settings version
Expand Down Expand Up @@ -72,9 +75,31 @@ const migrators: Map<string, (prev: any) => any> = new Map<
>([
// Insert new migrators here as [ 'version', (prev) => ApplicationSettings ]
// Don't forget to update the settings class of previous migrators
[
'1.4.0',
(prev: _ApplicationSettings_v130): ApplicationSettings => {
const {
// Removed, changed or renamed :
settingsVersion,
ttsConfig,
// remaining unchanged settings
...toKeep
} = prev
// changes in pipeline properties

return {
settingsVersion: '1.4.0',
ttsConfig: {
...prev.ttsConfig,
defaultVoices: [], // new default voices setting
},
...toKeep,
} as ApplicationSettings
},
],
[
'1.3.0',
(prev: _ApplicationSettings_v0): ApplicationSettings => {
(prev: _ApplicationSettings_v0): _ApplicationSettings_v130 => {
const {
// Removed, changed or renamed :
runLocalPipeline,
Expand All @@ -97,7 +122,7 @@ const migrators: Map<string, (prev: any) => any> = new Map<
}

return {
settingsVersion: '1.4.0',
settingsVersion: '1.3.0',
downloadFolder: prev.downloadFolder,
pipelineInstanceProps: {
pipelineType: 'embedded',
Expand All @@ -115,11 +140,31 @@ const migrators: Map<string, (prev: any) => any> = new Map<
? 'keepengine'
: 'keepall',
...toKeep,
} as ApplicationSettings
} as _ApplicationSettings_v130
},
],
])

export type _ApplicationSettings_v130 = {
settingsVersion: '1.3.0'
// Default folder to download the results on the user disk
downloadFolder?: string
// Pipeline instance properties for IPCs
pipelineInstanceProps?: PipelineInstanceProperties
// Dark mode selector
colorScheme: keyof typeof ColorScheme
// Actions to perform when closing the main window
onClosingMainWindow?: keyof typeof ClosingMainWindowAction
editJobOnNewTab?: boolean
// tts preferred voices
ttsConfig?: {
preferredVoices: Array<TtsVoice>
ttsEngineProperties: Array<TtsEngineProperty>
xmlFilepath?: string
}
autoCheckUpdate?: boolean
}

/////// Keeping previous applications settings here for history and for migrators
/**
* Initial version of settings
Expand Down Expand Up @@ -177,6 +222,10 @@ type _ApplicationSettings_v0 = {
appStateOnClosingMainWindow?: 'keep' | 'close' | 'ask'
jobsStateOnClosingMainWindow?: 'keep' | 'close'
// tts preferred voices
ttsConfig?: TtsConfig
ttsConfig?: {
preferredVoices: Array<TtsVoice>
ttsEngineProperties: Array<TtsEngineProperty>
xmlFilepath?: string
}
autoCheckUpdate?: boolean
}

0 comments on commit a67600e

Please sign in to comment.