mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-22 20:25:38 +00:00
fixes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const { dialog, ipcMain } = require('electron');
|
||||
const { normalizeAndResolvePath } = require('../utils/filesystem');
|
||||
const { generateUidBasedOnHash } = require('../utils/common');
|
||||
const { generateYamlContent } = require('../utils/workspace-config');
|
||||
const { generateYamlContent, getWorkspaceUid } = require('../utils/workspace-config');
|
||||
|
||||
const normalizeWorkspaceConfig = (config) => {
|
||||
return {
|
||||
@@ -75,8 +75,12 @@ const openApiSpec = async (win, watcher, apiSpecPath, options = {}) => {
|
||||
fs.writeFileSync(workspaceFilePath, updatedYamlContent);
|
||||
|
||||
const normalizedConfig = normalizeWorkspaceConfig(workspaceConfig);
|
||||
const workspaceUid = generateUidBasedOnHash(options.workspacePath);
|
||||
win.webContents.send('main:workspace-config-updated', options.workspacePath, workspaceUid, normalizedConfig);
|
||||
const workspaceUid = getWorkspaceUid(options.workspacePath);
|
||||
const isDefault = workspaceUid === 'default';
|
||||
win.webContents.send('main:workspace-config-updated', options.workspacePath, workspaceUid, {
|
||||
...normalizedConfig,
|
||||
type: isDefault ? 'default' : normalizedConfig.type
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,21 +4,13 @@ const path = require('path');
|
||||
const chokidar = require('chokidar');
|
||||
const yaml = require('js-yaml');
|
||||
const { generateUidBasedOnHash, uuid } = require('../utils/common');
|
||||
const { getWorkspaceUid } = require('../utils/workspace-config');
|
||||
const { parseEnvironment } = require('@usebruno/filestore');
|
||||
const EnvironmentSecretsStore = require('../store/env-secrets');
|
||||
const { decryptStringSafe } = require('../utils/encryption');
|
||||
const { defaultWorkspaceManager } = require('../store/default-workspace');
|
||||
|
||||
const environmentSecretsStore = new EnvironmentSecretsStore();
|
||||
|
||||
const getWorkspaceUid = (workspacePath) => {
|
||||
const defaultWorkspacePath = defaultWorkspaceManager.getDefaultWorkspacePath();
|
||||
if (defaultWorkspacePath && path.normalize(workspacePath) === path.normalize(defaultWorkspacePath)) {
|
||||
return defaultWorkspaceManager.getDefaultWorkspaceUid();
|
||||
}
|
||||
return generateUidBasedOnHash(workspacePath);
|
||||
};
|
||||
|
||||
const envHasSecrets = (environment) => {
|
||||
const secrets = _.filter(environment.variables, (v) => v.secret === true);
|
||||
return secrets && secrets.length > 0;
|
||||
@@ -52,8 +44,12 @@ const handleWorkspaceFileChange = (win, workspacePath) => {
|
||||
}
|
||||
|
||||
const workspaceUid = getWorkspaceUid(workspacePath);
|
||||
const isDefault = workspaceUid === 'default';
|
||||
|
||||
win.webContents.send('main:workspace-config-updated', workspacePath, workspaceUid, workspaceConfig);
|
||||
win.webContents.send('main:workspace-config-updated', workspacePath, workspaceUid, {
|
||||
...workspaceConfig,
|
||||
type: isDefault ? 'default' : workspaceConfig.type
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error handling workspace file change:', error);
|
||||
}
|
||||
|
||||
@@ -3,13 +3,11 @@ const path = require('path');
|
||||
const fsExtra = require('fs-extra');
|
||||
const { ipcMain, dialog } = require('electron');
|
||||
const { createDirectory, sanitizeName } = require('../utils/filesystem');
|
||||
const { generateUidBasedOnHash } = require('../utils/common');
|
||||
const yaml = require('js-yaml');
|
||||
const LastOpenedWorkspaces = require('../store/last-opened-workspaces');
|
||||
const { defaultWorkspaceManager } = require('../store/default-workspace');
|
||||
const { globalEnvironmentsManager } = require('../store/workspace-environments');
|
||||
|
||||
// Workspace configuration module (includes path and validation utilities)
|
||||
const {
|
||||
createWorkspaceConfig,
|
||||
readWorkspaceConfig,
|
||||
@@ -22,22 +20,13 @@ const {
|
||||
getWorkspaceCollections,
|
||||
normalizeCollectionEntry,
|
||||
validateWorkspacePath,
|
||||
validateWorkspaceDirectory
|
||||
validateWorkspaceDirectory,
|
||||
getWorkspaceUid
|
||||
} = require('../utils/workspace-config');
|
||||
|
||||
const registerWorkspaceIpc = (mainWindow, workspaceWatcher) => {
|
||||
const lastOpenedWorkspaces = new LastOpenedWorkspaces();
|
||||
|
||||
// Helper to get the correct workspace UID
|
||||
// For default workspace, always use 'default', otherwise generate hash
|
||||
const getWorkspaceUid = (workspacePath) => {
|
||||
const defaultWorkspacePath = defaultWorkspaceManager.getDefaultWorkspacePath();
|
||||
if (defaultWorkspacePath && path.normalize(workspacePath) === path.normalize(defaultWorkspacePath)) {
|
||||
return defaultWorkspaceManager.getDefaultWorkspaceUid();
|
||||
}
|
||||
return generateUidBasedOnHash(workspacePath);
|
||||
};
|
||||
|
||||
ipcMain.handle('renderer:create-workspace',
|
||||
async (event, workspaceName, workspaceFolderName, workspaceLocation) => {
|
||||
try {
|
||||
@@ -59,21 +48,25 @@ const registerWorkspaceIpc = (mainWindow, workspaceWatcher) => {
|
||||
|
||||
await createDirectory(path.join(dirPath, 'collections'));
|
||||
|
||||
const workspaceUid = generateUidBasedOnHash(dirPath);
|
||||
const workspaceUid = getWorkspaceUid(dirPath);
|
||||
const isDefault = workspaceUid === 'default';
|
||||
const workspaceConfig = createWorkspaceConfig(workspaceName);
|
||||
|
||||
await writeWorkspaceConfig(dirPath, workspaceConfig);
|
||||
|
||||
lastOpenedWorkspaces.add(dirPath);
|
||||
|
||||
mainWindow.webContents.send('main:workspace-opened', dirPath, workspaceUid, workspaceConfig);
|
||||
mainWindow.webContents.send('main:workspace-opened', dirPath, workspaceUid, {
|
||||
...workspaceConfig,
|
||||
type: isDefault ? 'default' : workspaceConfig.type
|
||||
});
|
||||
|
||||
if (workspaceWatcher) {
|
||||
workspaceWatcher.addWatcher(mainWindow, dirPath);
|
||||
}
|
||||
|
||||
return {
|
||||
workspaceConfig,
|
||||
workspaceConfig: { ...workspaceConfig, type: isDefault ? 'default' : workspaceConfig.type },
|
||||
workspaceUid,
|
||||
workspacePath: dirPath
|
||||
};
|
||||
@@ -89,18 +82,20 @@ const registerWorkspaceIpc = (mainWindow, workspaceWatcher) => {
|
||||
const workspaceConfig = readWorkspaceConfig(workspacePath);
|
||||
validateWorkspaceConfig(workspaceConfig);
|
||||
|
||||
const workspaceUid = generateUidBasedOnHash(workspacePath);
|
||||
const workspaceUid = getWorkspaceUid(workspacePath);
|
||||
const isDefault = workspaceUid === 'default';
|
||||
const configWithType = { ...workspaceConfig, type: isDefault ? 'default' : workspaceConfig.type };
|
||||
|
||||
lastOpenedWorkspaces.add(workspacePath);
|
||||
|
||||
mainWindow.webContents.send('main:workspace-opened', workspacePath, workspaceUid, workspaceConfig);
|
||||
mainWindow.webContents.send('main:workspace-opened', workspacePath, workspaceUid, configWithType);
|
||||
|
||||
if (workspaceWatcher) {
|
||||
workspaceWatcher.addWatcher(mainWindow, workspacePath);
|
||||
}
|
||||
|
||||
return {
|
||||
workspaceConfig,
|
||||
workspaceConfig: configWithType,
|
||||
workspaceUid,
|
||||
workspacePath
|
||||
};
|
||||
@@ -127,18 +122,20 @@ const registerWorkspaceIpc = (mainWindow, workspaceWatcher) => {
|
||||
const workspaceConfig = readWorkspaceConfig(workspacePath);
|
||||
validateWorkspaceConfig(workspaceConfig);
|
||||
|
||||
const workspaceUid = generateUidBasedOnHash(workspacePath);
|
||||
const workspaceUid = getWorkspaceUid(workspacePath);
|
||||
const isDefault = workspaceUid === 'default';
|
||||
const configWithType = { ...workspaceConfig, type: isDefault ? 'default' : workspaceConfig.type };
|
||||
|
||||
lastOpenedWorkspaces.add(workspacePath);
|
||||
|
||||
mainWindow.webContents.send('main:workspace-opened', workspacePath, workspaceUid, workspaceConfig);
|
||||
mainWindow.webContents.send('main:workspace-opened', workspacePath, workspaceUid, configWithType);
|
||||
|
||||
if (workspaceWatcher) {
|
||||
workspaceWatcher.addWatcher(mainWindow, workspacePath);
|
||||
}
|
||||
|
||||
return {
|
||||
workspaceConfig,
|
||||
workspaceConfig: configWithType,
|
||||
workspaceUid,
|
||||
workspacePath
|
||||
};
|
||||
@@ -349,7 +346,11 @@ const registerWorkspaceIpc = (mainWindow, workspaceWatcher) => {
|
||||
|
||||
const workspaceConfig = readWorkspaceConfig(workspacePath);
|
||||
const workspaceUid = getWorkspaceUid(workspacePath);
|
||||
mainWindow.webContents.send('main:workspace-config-updated', workspacePath, workspaceUid, workspaceConfig);
|
||||
const isDefault = workspaceUid === 'default';
|
||||
mainWindow.webContents.send('main:workspace-config-updated', workspacePath, workspaceUid, {
|
||||
...workspaceConfig,
|
||||
type: isDefault ? 'default' : workspaceConfig.type
|
||||
});
|
||||
|
||||
return updatedCollections;
|
||||
} catch (error) {
|
||||
@@ -384,13 +385,16 @@ const registerWorkspaceIpc = (mainWindow, workspaceWatcher) => {
|
||||
try {
|
||||
const result = await removeCollectionFromWorkspace(workspacePath, collectionPath);
|
||||
|
||||
// Delete collection files if it's a workspace collection
|
||||
if (result.shouldDeleteFiles && result.removedCollection && fs.existsSync(collectionPath)) {
|
||||
await fsExtra.remove(collectionPath);
|
||||
}
|
||||
|
||||
const correctWorkspaceUid = getWorkspaceUid(workspacePath);
|
||||
mainWindow.webContents.send('main:workspace-config-updated', workspacePath, correctWorkspaceUid, result.updatedConfig);
|
||||
const isDefault = correctWorkspaceUid === 'default';
|
||||
mainWindow.webContents.send('main:workspace-config-updated', workspacePath, correctWorkspaceUid, {
|
||||
...result.updatedConfig,
|
||||
type: isDefault ? 'default' : result.updatedConfig.type
|
||||
});
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
@@ -485,9 +489,13 @@ const registerWorkspaceIpc = (mainWindow, workspaceWatcher) => {
|
||||
try {
|
||||
const workspaceConfig = readWorkspaceConfig(workspacePath);
|
||||
validateWorkspaceConfig(workspaceConfig);
|
||||
const workspaceUid = generateUidBasedOnHash(workspacePath);
|
||||
const workspaceUid = getWorkspaceUid(workspacePath);
|
||||
const isDefault = workspaceUid === 'default';
|
||||
|
||||
win.webContents.send('main:workspace-opened', workspacePath, workspaceUid, workspaceConfig);
|
||||
win.webContents.send('main:workspace-opened', workspacePath, workspaceUid, {
|
||||
...workspaceConfig,
|
||||
type: isDefault ? 'default' : workspaceConfig.type
|
||||
});
|
||||
|
||||
if (workspaceWatcher) {
|
||||
workspaceWatcher.addWatcher(win, workspacePath);
|
||||
|
||||
@@ -70,8 +70,8 @@ class DefaultWorkspaceManager {
|
||||
|
||||
const existingPath = this.getDefaultWorkspacePath();
|
||||
|
||||
// If existing path is valid, return it
|
||||
if (this.isValidDefaultWorkspace(existingPath)) {
|
||||
this.defaultWorkspacePath = existingPath;
|
||||
return {
|
||||
workspacePath: existingPath,
|
||||
workspaceUid: this.getDefaultWorkspaceUid()
|
||||
|
||||
@@ -2,6 +2,8 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const yaml = require('js-yaml');
|
||||
const { writeFile, validateName } = require('./filesystem');
|
||||
const { defaultWorkspaceManager } = require('../store/default-workspace');
|
||||
const { generateUidBasedOnHash } = require('./common');
|
||||
|
||||
const WORKSPACE_TYPE = 'workspace';
|
||||
const OPENCOLLECTION_VERSION = '1.0.0';
|
||||
@@ -354,6 +356,14 @@ const removeApiSpecFromWorkspace = async (workspacePath, apiSpecPath) => {
|
||||
};
|
||||
};
|
||||
|
||||
const getWorkspaceUid = (workspacePath) => {
|
||||
const defaultWorkspacePath = defaultWorkspaceManager.getDefaultWorkspacePath();
|
||||
if (defaultWorkspacePath && path.normalize(workspacePath) === path.normalize(defaultWorkspacePath)) {
|
||||
return defaultWorkspaceManager.getDefaultWorkspaceUid();
|
||||
}
|
||||
return generateUidBasedOnHash(workspacePath);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
makeRelativePath,
|
||||
normalizeCollectionEntry,
|
||||
@@ -371,5 +381,6 @@ module.exports = {
|
||||
getWorkspaceApiSpecs,
|
||||
addApiSpecToWorkspace,
|
||||
removeApiSpecFromWorkspace,
|
||||
generateYamlContent
|
||||
generateYamlContent,
|
||||
getWorkspaceUid
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user