From 13e97f0367badee79cd9e65cbfeaa3057772be1e Mon Sep 17 00:00:00 2001 From: Chirag Chandrashekhar Date: Fri, 27 Mar 2026 19:56:19 +0530 Subject: [PATCH] fix: preserve global environment color during script execution (#7427) When executing requests with pre-request or post-response scripts, the global environment color property was being stripped from YAML files. This happened because the save operation only passed `variables` through the IPC chain, and the workspace-environments store created a new environment object without preserving the existing `color` property. The fix passes the `color` property through the entire IPC chain: - Redux actions now include `color` in the save-global-environment IPC call - IPC handler accepts and forwards `color` to both stores - workspace-environments store includes `color` when creating the environment object - global-environments store preserves `color` when updating Fixes #7348 Co-authored-by: Chirag Chandrashekhar --- .../src/providers/ReduxStore/slices/global-environments.js | 2 ++ packages/bruno-electron/src/ipc/global-environments.js | 6 +++--- packages/bruno-electron/src/store/global-environments.js | 5 ++++- packages/bruno-electron/src/store/workspace-environments.js | 6 +++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js b/packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js index 92e191c73..ee622cf8c 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js @@ -226,6 +226,7 @@ export const saveGlobalEnvironment = ({ variables, environmentUid }) => (dispatc .then(() => ipcRenderer.invoke('renderer:save-global-environment', { environmentUid, variables, + color: environment.color, workspaceUid, workspacePath })) @@ -310,6 +311,7 @@ export const globalEnvironmentsUpdateEvent = ({ globalEnvironmentVariables }) => .then(() => ipcRenderer.invoke('renderer:save-global-environment', { environmentUid, variables, + color: environment.color, workspaceUid, workspacePath })) diff --git a/packages/bruno-electron/src/ipc/global-environments.js b/packages/bruno-electron/src/ipc/global-environments.js index a616b113c..e85376990 100644 --- a/packages/bruno-electron/src/ipc/global-environments.js +++ b/packages/bruno-electron/src/ipc/global-environments.js @@ -78,13 +78,13 @@ const registerGlobalEnvironmentsIpc = (mainWindow, workspaceEnvironmentsManager) } }); - ipcMain.handle('renderer:save-global-environment', async (event, { environmentUid, variables, workspaceUid, workspacePath }) => { + ipcMain.handle('renderer:save-global-environment', async (event, { environmentUid, variables, color, workspaceUid, workspacePath }) => { try { if (workspacePath && workspaceEnvironmentsManager) { - return await workspaceEnvironmentsManager.saveGlobalEnvironmentByPath(workspacePath, { environmentUid, variables }); + return await workspaceEnvironmentsManager.saveGlobalEnvironmentByPath(workspacePath, { environmentUid, variables, color }); } - globalEnvironmentsStore.saveGlobalEnvironment({ environmentUid, variables }); + globalEnvironmentsStore.saveGlobalEnvironment({ environmentUid, variables, color }); } catch (error) { console.error('Error in renderer:save-global-environment:', error); return Promise.reject(error); diff --git a/packages/bruno-electron/src/store/global-environments.js b/packages/bruno-electron/src/store/global-environments.js index 8b4447d8a..099feda3a 100644 --- a/packages/bruno-electron/src/store/global-environments.js +++ b/packages/bruno-electron/src/store/global-environments.js @@ -139,12 +139,15 @@ class GlobalEnvironmentsStore { this.setGlobalEnvironments(globalEnvironments); } - saveGlobalEnvironment({ environmentUid: globalEnvironmentUid, variables }) { + saveGlobalEnvironment({ environmentUid: globalEnvironmentUid, variables, color }) { let globalEnvironments = this.getGlobalEnvironments(); const environment = globalEnvironments.find((env) => env?.uid == globalEnvironmentUid); globalEnvironments = globalEnvironments.filter((env) => env?.uid !== globalEnvironmentUid); if (environment) { environment.variables = variables; + if (color !== undefined) { + environment.color = color; + } } globalEnvironments.push(environment); this.setGlobalEnvironments(globalEnvironments); diff --git a/packages/bruno-electron/src/store/workspace-environments.js b/packages/bruno-electron/src/store/workspace-environments.js index 688678ab4..27c455db0 100644 --- a/packages/bruno-electron/src/store/workspace-environments.js +++ b/packages/bruno-electron/src/store/workspace-environments.js @@ -161,7 +161,7 @@ class GlobalEnvironmentsManager { } } - async saveGlobalEnvironment(workspacePath, { environmentUid, variables }) { + async saveGlobalEnvironment(workspacePath, { environmentUid, variables, color }) { try { if (!workspacePath) { throw new Error('Workspace path is required'); @@ -178,6 +178,10 @@ class GlobalEnvironmentsManager { variables: variables }; + if (color) { + environment.color = color; + } + if (this.envHasSecrets(environment)) { environmentSecretsStore.storeEnvSecrets(workspacePath, environment); }