Skip to content

Commit

Permalink
Merge pull request #214 from daisy/issue-129
Browse files Browse the repository at this point in the history
feat(settings): new settings migration utility for evolutions
  • Loading branch information
marisademeglio authored Apr 15, 2024
2 parents 307c915 + 325f506 commit 41643d5
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 234 deletions.
52 changes: 22 additions & 30 deletions src/main/data/middlewares/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
EngineProperty,
TtsEngineProperty,
TtsVoice,
migrateSettings,
} from 'shared/types'
import { RootState } from 'shared/types/store'
import { resolveUnpacked } from 'shared/utils'
Expand All @@ -23,38 +24,29 @@ import { propertyToXml } from 'shared/parser/pipelineXmlConverter/propertyToXml'
const settingsFile = resolve(app.getPath('userData'), 'settings.json')

export function readSettings() {
let settings = {
// Default folder to download the results on the user disk
let settings: ApplicationSettings = {
settingsVersion: '1.3.0',
downloadFolder: pathToFileURL(
resolve(app.getPath('home'), 'Documents', 'DAISY Pipeline results')
).href,
// Local pipeline server
// - Run or not a local pipeline server
runLocalPipeline: true,
// - Local pipeline settings
localPipelineProps: {
localPipelineHome: resolveUnpacked('resources', 'daisy-pipeline'),
jrePath: resolveUnpacked('resources', 'daisy-pipeline', 'jre'),
// Note : [49152 ; 65535] is the range of dynamic port, 0 is reserved for error case
pipelineInstanceProps: {
pipelineType: 'embedded',
webservice: {
// Note : localhost resolve as ipv6 ':::' in nodejs, but we need ipv4 for the pipeline
// Notes :
// - [49152 ; 65535] is the range of dynamic port, 0 is reserved for error case
// - localhost resolve as ipv6 ':::' in nodejs, but we need ipv4 for the pipeline
host: '127.0.0.1',
port: 0,
path: '/ws',
},
pipelineHome: resolveUnpacked('resources', 'daisy-pipeline'),
jrePath: resolveUnpacked('resources', 'daisy-pipeline', 'jre'),
appDataFolder: app.getPath('userData'),
logsFolder: resolve(app.getPath('userData'), 'pipeline-logs'),
},
// Remote pipeline settings
// - Use a remote pipeline instead of the local one
useRemotePipeline: false,
// - Remote pipeline connection settings to be defined
/*remotePipelineWebservice: {
}*/
colorScheme: 'system',
appStateOnClosingMainWindow: undefined,
jobsStateOnClosingMainWindow: 'close',
onClosingMainWindow: undefined, // Undeterminate to display the app-opening dialog
editJobOnNewTab: true,
ttsConfig: {
preferredVoices: [],
xmlFilepath: pathToFileURL(
Expand All @@ -63,21 +55,21 @@ export function readSettings() {
ttsEngineProperties: [],
},
autoCheckUpdate: true,
} as ApplicationSettings
}
try {
if (existsSync(settingsFile)) {
const loaded: ApplicationSettings = JSON.parse(
readFileSync(settingsFile, 'utf8')
) as ApplicationSettings
const loaded: ApplicationSettings = migrateSettings(
JSON.parse(readFileSync(settingsFile, 'utf8'))
)
settings = {
...settings,
...loaded,
localPipelineProps: {
...settings.localPipelineProps,
...loaded?.localPipelineProps,
pipelineInstanceProps: {
...settings.pipelineInstanceProps,
...loaded?.pipelineInstanceProps,
webservice: {
...settings.localPipelineProps.webservice,
...loaded?.localPipelineProps?.webservice,
...settings.pipelineInstanceProps.webservice,
...loaded?.pipelineInstanceProps?.webservice,
},
},
ttsConfig: {
Expand Down Expand Up @@ -115,7 +107,7 @@ export function readSettings() {
}

// Remove pipeline props loading for dev
if (ENVIRONMENT.IS_DEV) settings.localPipelineProps = undefined
if (ENVIRONMENT.IS_DEV) settings.pipelineInstanceProps = undefined

return settings
}
Expand Down
37 changes: 14 additions & 23 deletions src/main/factories/ipcs/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@ import {
Webservice,
PipelineStatus,
PipelineState,
ApplicationSettings,
PipelineInstanceProperties,
} from 'shared/types'
import { ENVIRONMENT, IPC } from 'shared/constants'
import { spawn, ChildProcessWithoutNullStreams } from 'child_process'
import { existsSync, mkdirSync, readFileSync, rmSync } from 'fs'

import { getAvailablePort, Pipeline2Error, walk } from './utils'

import { resolveUnpacked } from 'shared/utils'

import { info, error } from 'electron-log'

import { pathToFileURL } from 'url'

import { store } from 'main/data/store'
import {
selectPipeline,
Expand Down Expand Up @@ -52,13 +47,13 @@ export class PipelineInstance {
*/
constructor(props?: PipelineInstanceProperties) {
this.props = {
localPipelineHome:
pipelineHome:
// Add `(props && props.pipelineType == 'system' && props.localPipelineHome) ||` if system wide pipeline control requested
// (!props || props.pipelineType == 'embedded') &&
(!props || props.pipelineType == 'embedded') &&
resolveUnpacked('resources', 'daisy-pipeline'),
jrePath:
// Add `(props && props.pipelineType == 'system' && props.jrePath) ||` if system wide pipeline control requested
// (!props || props.pipelineType == 'embedded') &&
(!props || props.pipelineType == 'embedded') &&
resolveUnpacked('resources', 'daisy-pipeline', 'jre'),
// Note : [49152 ; 65535] is the range of dynamic port, 0 is reserved for error case
webservice: (props &&
Expand Down Expand Up @@ -130,7 +125,7 @@ export class PipelineInstance {
}

if (
this.props.localPipelineHome === null ||
this.props.pipelineHome === null ||
!existsSync(this.props.jrePath)
) {
throw new Pipeline2Error(
Expand Down Expand Up @@ -253,8 +248,8 @@ Then close the program using the port and restart this application.`,
`Launching pipeline on ${this.props.webservice.host}:${this.props.webservice.port}`
)
let ClassFolders = [
resolve(this.props.localPipelineHome, 'system'),
resolve(this.props.localPipelineHome, 'modules'),
resolve(this.props.pipelineHome, 'system'),
resolve(this.props.pipelineHome, 'modules'),
]
let jarFiles = ClassFolders.reduce(
(acc: Array<string>, path: string) => {
Expand All @@ -271,7 +266,7 @@ Then close the program using the port and restart this application.`,
let relativeJarFiles = jarFiles.reduce(
(acc: Array<string>, path: string) => {
let relativeDirPath = relative(
this.props.localPipelineHome,
this.props.pipelineHome,
path
)
if (!acc.includes(relativeDirPath)) {
Expand Down Expand Up @@ -314,19 +309,15 @@ Then close the program using the port and restart this application.`,
let SystemProps = [
'-Dorg.daisy.pipeline.properties="' +
resolve(
this.props.localPipelineHome,
this.props.pipelineHome,
'etc',
'pipeline.properties'
) +
'"',
// Logback configuration file
'-Dlogback.configurationFile=' +
pathToFileURL(
resolve(
this.props.localPipelineHome,
'etc',
'logback.xml'
)
resolve(this.props.pipelineHome, 'etc', 'logback.xml')
).href +
'',
// XMLCalabash base configuration file
Expand All @@ -340,17 +331,17 @@ Then close the program using the port and restart this application.`,
// Updater configuration
'-Dorg.daisy.pipeline.updater.bin="' +
resolve(
this.props.localPipelineHome,
this.props.pipelineHome,
'updater',
'pipeline-updater'
).replaceAll('\\', '/') +
'"',
'-Dorg.daisy.pipeline.updater.deployPath="' +
this.props.localPipelineHome.replaceAll('\\', '/') +
this.props.pipelineHome.replaceAll('\\', '/') +
'/"',
'-Dorg.daisy.pipeline.updater.releaseDescriptor="' +
resolve(
this.props.localPipelineHome,
this.props.pipelineHome,
'etc',
'releaseDescriptor.xml'
).replaceAll('\\', '/') +
Expand All @@ -367,7 +358,7 @@ Then close the program using the port and restart this application.`,
'-Dorg.daisy.pipeline.ws.authentication=false',
'-Dorg.daisy.pipeline.ws.host=' + this.props.webservice.host,
'-Dorg.daisy.pipeline.ws.cors=true',
'-Dorg.daisy.pipeline.home=' + this.props.localPipelineHome,
'-Dorg.daisy.pipeline.home=' + this.props.pipelineHome,
'-Dorg.daisy.pipeline.tts.host.protection=false', // so we can send TTS engine properties
]
if (this.props.webservice.path) {
Expand Down Expand Up @@ -416,7 +407,7 @@ Then close the program using the port and restart this application.`,
${command} ${args.join(' ')}`
)
this.instance = spawn(command, args, {
cwd: this.props.localPipelineHome,
cwd: this.props.pipelineHome,
})
// NP Replace stdout analysis by webservice monitoring
this.instance.stdout.on('data', (data) => {
Expand Down
1 change: 1 addition & 0 deletions src/main/factories/windows/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { selectPipeline } from 'shared/data/slices/pipeline'
import { selectSettings } from 'shared/data/slices/settings'
import { WindowProps } from 'shared/types'
import { APP_CONFIG } from '~/app.config'

import { PipelineInstance } from '../ipcs/pipeline'

/**
Expand Down
Loading

0 comments on commit 41643d5

Please sign in to comment.