(value: unknown)
| 239 | } |
| 240 | |
| 241 | function sanitizePreferences(value: unknown): PreferencesStore { |
| 242 | const source = asRecord(value) |
| 243 | const appearanceSource = asRecord(source.appearance) |
| 244 | const localizationSource = asRecord(source.localization) |
| 245 | const apiSource = asRecord(source.api) |
| 246 | const storageSource = asRecord(source.storage) |
| 247 | const editorSource = asRecord(source.editor) |
| 248 | const codeEditorSource |
| 249 | = Object.keys(asRecord(editorSource.code)).length > 0 |
| 250 | ? asRecord(editorSource.code) |
| 251 | : editorSource |
| 252 | const notesEditorSource |
| 253 | = Object.keys(asRecord(editorSource.notes)).length > 0 |
| 254 | ? asRecord(editorSource.notes) |
| 255 | : asRecord(source.notesEditor) |
| 256 | const markdownSource |
| 257 | = Object.keys(asRecord(editorSource.markdown)).length > 0 |
| 258 | ? asRecord(editorSource.markdown) |
| 259 | : asRecord(source.markdown) |
| 260 | const mathSource = asRecord(source.math) |
| 261 | const httpSource = asRecord(source.http) |
| 262 | |
| 263 | return { |
| 264 | appearance: { |
| 265 | theme: readString( |
| 266 | appearanceSource, |
| 267 | 'theme', |
| 268 | readString(source, 'theme', PREFERENCES_DEFAULTS.appearance.theme), |
| 269 | ), |
| 270 | }, |
| 271 | updates: { |
| 272 | autoUpdate: |
| 273 | typeof asRecord(source.updates).autoUpdate === 'boolean' |
| 274 | ? Boolean(asRecord(source.updates).autoUpdate) |
| 275 | : PREFERENCES_DEFAULTS.updates.autoUpdate, |
| 276 | }, |
| 277 | localization: { |
| 278 | locale: readString( |
| 279 | localizationSource, |
| 280 | 'locale', |
| 281 | readString( |
| 282 | source, |
| 283 | 'language', |
| 284 | PREFERENCES_DEFAULTS.localization.locale, |
| 285 | ), |
| 286 | ), |
| 287 | }, |
| 288 | api: { |
| 289 | port: readNumber( |
| 290 | apiSource, |
| 291 | 'port', |
| 292 | readNumber(source, 'apiPort', PREFERENCES_DEFAULTS.api.port), |
| 293 | ), |
| 294 | integrations: sanitizeApiIntegrationsSettings(apiSource.integrations), |
| 295 | }, |
| 296 | storage: { |
| 297 | rootPath: readString( |
| 298 | storageSource, |
no test coverage detected