From a67600e67547c2a2d3524cc2e508d33046b98c0e Mon Sep 17 00:00:00 2001 From: Nicolas Pavie Date: Mon, 10 Jun 2024 15:09:30 +0200 Subject: [PATCH] fix(settings): settings migration from 1.3 to 1.4 --- src/shared/types/settings.ts | 61 ++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/src/shared/types/settings.ts b/src/shared/types/settings.ts index b8d4a9c..33f6d31 100644 --- a/src/shared/types/settings.ts +++ b/src/shared/types/settings.ts @@ -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', @@ -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 @@ -72,9 +75,31 @@ const migrators: Map 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, @@ -97,7 +122,7 @@ const migrators: Map any> = new Map< } return { - settingsVersion: '1.4.0', + settingsVersion: '1.3.0', downloadFolder: prev.downloadFolder, pipelineInstanceProps: { pipelineType: 'embedded', @@ -115,11 +140,31 @@ const migrators: Map 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 + ttsEngineProperties: Array + xmlFilepath?: string + } + autoCheckUpdate?: boolean +} + /////// Keeping previous applications settings here for history and for migrators /** * Initial version of settings @@ -177,6 +222,10 @@ type _ApplicationSettings_v0 = { appStateOnClosingMainWindow?: 'keep' | 'close' | 'ask' jobsStateOnClosingMainWindow?: 'keep' | 'close' // tts preferred voices - ttsConfig?: TtsConfig + ttsConfig?: { + preferredVoices: Array + ttsEngineProperties: Array + xmlFilepath?: string + } autoCheckUpdate?: boolean }