diff options
Diffstat (limited to 'packages/main/src/stores/config')
-rw-r--r-- | packages/main/src/stores/config/loadConfig.ts | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/packages/main/src/stores/config/loadConfig.ts b/packages/main/src/stores/config/loadConfig.ts index 770d675..55d15c8 100644 --- a/packages/main/src/stores/config/loadConfig.ts +++ b/packages/main/src/stores/config/loadConfig.ts | |||
@@ -106,22 +106,13 @@ export default function loadConfig( | |||
106 | target: { | 106 | target: { |
107 | readonly profiles: IMSTArray<IReferenceType<typeof Profile>>; | 107 | readonly profiles: IMSTArray<IReferenceType<typeof Profile>>; |
108 | readonly profilesById: IMSTMap<typeof Profile>; | 108 | readonly profilesById: IMSTMap<typeof Profile>; |
109 | selectedService: Service | undefined; | ||
110 | readonly services: IMSTArray<IReferenceType<typeof Service>>; | 109 | readonly services: IMSTArray<IReferenceType<typeof Service>>; |
111 | readonly servicesById: IMSTMap<typeof Service>; | 110 | readonly servicesById: IMSTMap<typeof Service>; |
112 | readonly settings: GlobalSettings; | 111 | readonly settings: GlobalSettings; |
113 | }, | 112 | }, |
114 | config: Config, | 113 | config: Config, |
115 | ): void { | 114 | ): void { |
116 | const { | 115 | const { profiles, profilesById, services, servicesById, settings } = target; |
117 | profiles, | ||
118 | profilesById, | ||
119 | selectedService, | ||
120 | services, | ||
121 | servicesById, | ||
122 | settings, | ||
123 | } = target; | ||
124 | const { id: selectedServiceId } = selectedService ?? { id: undefined }; | ||
125 | const { | 116 | const { |
126 | profiles: profilesConfig, | 117 | profiles: profilesConfig, |
127 | services: servicesConfig, | 118 | services: servicesConfig, |
@@ -134,13 +125,16 @@ export default function loadConfig( | |||
134 | ); | 125 | ); |
135 | applySettings(profiles, profilesById, profilesToApply); | 126 | applySettings(profiles, profilesById, profilesToApply); |
136 | applySettings(services, servicesById, servicesToApply); | 127 | applySettings(services, servicesById, servicesToApply); |
137 | applySnapshot(settings, settingsToApply); | 128 | const { selectedService } = settingsToApply; |
138 | let newSelectedService: Service | undefined; | 129 | // Be more robust against when a deleted service is selected. |
139 | if (selectedServiceId !== undefined) { | 130 | if ( |
140 | newSelectedService = servicesById.get(selectedServiceId); | 131 | typeof selectedService !== 'string' || |
132 | !servicesById.has(selectedService) | ||
133 | ) { | ||
134 | settingsToApply.selectedService = undefined; | ||
141 | } | 135 | } |
142 | if (newSelectedService === undefined && services.length > 0) { | 136 | applySnapshot(settings, settingsToApply); |
143 | [newSelectedService] = services; | 137 | if (settings.selectedService === undefined && services.length > 0) { |
138 | [settings.selectedService] = services; | ||
144 | } | 139 | } |
145 | target.selectedService = newSelectedService; | ||
146 | } | 140 | } |