Skip to content

Commit

Permalink
Fix possibility to open the same env multiple times
Browse files Browse the repository at this point in the history
Closes #1381
  • Loading branch information
255kb committed Apr 30, 2024
1 parent c006917 commit 09e2c13
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions packages/desktop/src/renderer/app/services/environments.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,42 +885,40 @@ export class EnvironmentsService extends Logger {
return this.dialogsService
.showOpenDialog('Open environment JSON file', 'json', true, true)
.pipe(
filter((filePaths) => {
switchMap((filePaths) => {
if (!filePaths) {
return false;
return EMPTY;
}
const environments = this.store.get('settings').environments;

// set environment as active if already opened
if (filePaths.length === 1) {
const openedEnvironment = this.store
.get('settings')
.environments.find(
(environmentItem) => environmentItem.path === filePaths[0]
);
const observables: Observable<Environment>[] = [];

filePaths.forEach((filePath) => {
const openedEnvironment = environments.find(
(environmentItem) => environmentItem.path === filePath
);

if (openedEnvironment !== undefined) {
if (openedEnvironment === undefined) {
observables.push(
this.storageService.loadEnvironment(filePath).pipe(
switchMap((environment) => this.verifyData(environment)),
tap((environment) => {
this.validateAndAddToStore(environment, filePath);
})
)
);
} else if (
openedEnvironment !== undefined &&
filePaths.length === 1
) {
this.store.update(
setActiveEnvironmentAction(openedEnvironment.uuid)
);

return false;
}
}
});

return true;
}),
switchMap((filePaths) =>
concat(
...filePaths.map((filePath) =>
this.storageService.loadEnvironment(filePath).pipe(
switchMap((environment) => this.verifyData(environment)),
tap((environment) => {
this.validateAndAddToStore(environment, filePath);
})
)
)
)
)
return concat(...observables);
})
);
}

Expand Down

0 comments on commit 09e2c13

Please sign in to comment.