Merge branch 'main' into feature/save-prompt-tab-context-menu

This commit is contained in:
Ricardo Silverio 2024-09-30 21:42:13 -03:00
commit 0926f1583a
17 changed files with 325 additions and 33 deletions

View File

@ -10,6 +10,12 @@ const StyledWrapper = styled.div`
flex: 1 1 0; flex: 1 1 0;
} }
/* Removes the glow outline around the folded json */
.CodeMirror-foldmarker {
text-shadow: none;
color: ${(props) => props.theme.textLink};
}
.CodeMirror-overlayscroll-horizontal div, .CodeMirror-overlayscroll-horizontal div,
.CodeMirror-overlayscroll-vertical div { .CodeMirror-overlayscroll-vertical div {
background: #d2d7db; background: #d2d7db;

View File

@ -0,0 +1,46 @@
import styled from 'styled-components';
const StyledWrapper = styled.div`
table {
width: 100%;
border-collapse: collapse;
thead,
td {
border: 2px solid ${(props) => props.theme.table.border};
}
thead {
color: ${(props) => props.theme.table.thead.color};
font-size: 1rem;
user-select: none;
}
td {
padding: 4px 8px;
}
thead th {
font-weight: 600;
padding: 10px;
text-align: left;
}
}
.table-container {
max-height: 400px;
overflow-y: scroll;
}
.key-button {
display: inline-block;
color: ${(props) => props.theme.colors.text.white};
border-radius: 4px;
padding: 1px 5px;
font-family: monospace;
margin-right: 8px;
border: 1px solid #ccc;
}
`;
export default StyledWrapper;

View File

@ -0,0 +1,45 @@
import StyledWrapper from './StyledWrapper';
import React from 'react';
import { getKeyBindingsForOS } from 'providers/Hotkeys/keyMappings';
import { isMacOS } from 'utils/common/platform';
const Keybindings = ({ close }) => {
const keyMapping = getKeyBindingsForOS(isMacOS() ? 'mac' : 'windows');
return (
<StyledWrapper className="w-full">
<div className="table-container">
<table>
<thead>
<tr>
<th>Command</th>
<th>Keybinding</th>
</tr>
</thead>
<tbody>
{keyMapping ? (
Object.entries(keyMapping).map(([action, { name, keys }], index) => (
<tr key={index}>
<td>{name}</td>
<td>
{keys.split('+').map((key, i) => (
<div className="key-button" key={i}>
{key}
</div>
))}
</td>
</tr>
))
) : (
<tr>
<td colSpan="2">No key bindings available</td>
</tr>
)}
</tbody>
</table>
</div>
</StyledWrapper>
);
};
export default Keybindings;

View File

@ -1,11 +1,14 @@
import Modal from 'components/Modal/index'; import Modal from 'components/Modal/index';
import classnames from 'classnames'; import classnames from 'classnames';
import React, { useState } from 'react'; import React, { useState } from 'react';
import Support from './Support'; import Support from './Support';
import General from './General'; import General from './General';
import Proxy from './ProxySettings'; import Proxy from './ProxySettings';
import Display from './Display';
import Keybindings from './Keybindings';
import StyledWrapper from './StyledWrapper'; import StyledWrapper from './StyledWrapper';
import Display from './Display/index';
const Preferences = ({ onClose }) => { const Preferences = ({ onClose }) => {
const [tab, setTab] = useState('general'); const [tab, setTab] = useState('general');
@ -30,6 +33,10 @@ const Preferences = ({ onClose }) => {
return <Display close={onClose} />; return <Display close={onClose} />;
} }
case 'keybindings': {
return <Keybindings close={onClose} />;
}
case 'support': { case 'support': {
return <Support />; return <Support />;
} }
@ -50,6 +57,9 @@ const Preferences = ({ onClose }) => {
<div className={getTabClassname('proxy')} role="tab" onClick={() => setTab('proxy')}> <div className={getTabClassname('proxy')} role="tab" onClick={() => setTab('proxy')}>
Proxy Proxy
</div> </div>
<div className={getTabClassname('keybindings')} role="tab" onClick={() => setTab('keybindings')}>
Keybindings
</div>
<div className={getTabClassname('support')} role="tab" onClick={() => setTab('support')}> <div className={getTabClassname('support')} role="tab" onClick={() => setTab('support')}>
Support Support
</div> </div>

View File

@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState, useCallback } from 'react'; import React, { useEffect, useRef, useState, useMemo } from 'react';
import { IconGripVertical, IconMinusVertical } from '@tabler/icons'; import { IconGripVertical, IconMinusVertical } from '@tabler/icons';
/** /**
@ -13,17 +13,17 @@ import { IconGripVertical, IconMinusVertical } from '@tabler/icons';
const ReorderTable = ({ children, updateReorderedItem }) => { const ReorderTable = ({ children, updateReorderedItem }) => {
const tbodyRef = useRef(); const tbodyRef = useRef();
const [rowsOrder, setRowsOrder] = useState(React.Children.toArray(children));
const [hoveredRow, setHoveredRow] = useState(null); const [hoveredRow, setHoveredRow] = useState(null);
const [dragStart, setDragStart] = useState(null); const [dragStart, setDragStart] = useState(null);
const rowsOrder = useMemo(() => React.Children.toArray(children), [children]);
/** /**
* useEffect hook to update the rows order and handle row hover states * useEffect hook to handle row hover states
*/ */
useEffect(() => { useEffect(() => {
setRowsOrder(React.Children.toArray(children));
handleRowHover(null, false); handleRowHover(null, false);
}, [children, dragStart]); }, [children]);
const handleRowHover = (index, hoverstatus = true) => { const handleRowHover = (index, hoverstatus = true) => {
setHoveredRow(hoverstatus ? index : null); setHoveredRow(hoverstatus ? index : null);
@ -48,7 +48,6 @@ const ReorderTable = ({ children, updateReorderedItem }) => {
const updatedRowsOrder = [...rowsOrder]; const updatedRowsOrder = [...rowsOrder];
const [movedRow] = updatedRowsOrder.splice(fromIndex, 1); const [movedRow] = updatedRowsOrder.splice(fromIndex, 1);
updatedRowsOrder.splice(toIndex, 0, movedRow); updatedRowsOrder.splice(toIndex, 0, movedRow);
setRowsOrder(updatedRowsOrder);
updateReorderedItem({ updateReorderedItem({
updateReorderedItem: updatedRowsOrder.map((row) => row.props['data-uid']) updateReorderedItem: updatedRowsOrder.map((row) => row.props['data-uid'])

View File

@ -185,7 +185,7 @@ const Sidebar = () => {
Star Star
</GitHubButton> */} </GitHubButton> */}
</div> </div>
<div className="flex flex-grow items-center justify-end text-xs mr-2">v1.30.1</div> <div className="flex flex-grow items-center justify-end text-xs mr-2">v1.31.0</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -19,7 +19,7 @@ import {
runRequestEvent, runRequestEvent,
scriptEnvironmentUpdateEvent scriptEnvironmentUpdateEvent
} from 'providers/ReduxStore/slices/collections'; } from 'providers/ReduxStore/slices/collections';
import { collectionAddEnvFileEvent, openCollectionEvent } from 'providers/ReduxStore/slices/collections/actions'; import { collectionAddEnvFileEvent, openCollectionEvent, hydrateCollectionsWithUiStateSnapshot } from 'providers/ReduxStore/slices/collections/actions';
import toast from 'react-hot-toast'; import toast from 'react-hot-toast';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
import { isElectron } from 'utils/common/platform'; import { isElectron } from 'utils/common/platform';
@ -149,6 +149,10 @@ const useIpcEvents = () => {
dispatch(updateCookies(val)); dispatch(updateCookies(val));
}); });
const removeSnapshotHydrationListener = ipcRenderer.on('main:hydrate-app-with-ui-state-snapshot', (val) => {
dispatch(hydrateCollectionsWithUiStateSnapshot(val));
})
return () => { return () => {
removeCollectionTreeUpdateListener(); removeCollectionTreeUpdateListener();
removeOpenCollectionListener(); removeOpenCollectionListener();
@ -165,6 +169,7 @@ const useIpcEvents = () => {
removePreferencesUpdatesListener(); removePreferencesUpdatesListener();
removeCookieUpdateListener(); removeCookieUpdateListener();
removeSystemProxyEnvUpdatesListener(); removeSystemProxyEnvUpdatesListener();
removeSnapshotHydrationListener();
}; };
}, [isElectron]); }, [isElectron]);
}; };

View File

@ -60,7 +60,7 @@ const trackStart = () => {
event: 'start', event: 'start',
properties: { properties: {
os: platformLib.os.family, os: platformLib.os.family,
version: '1.30.1' version: '1.31.0'
} }
}); });
}; };

View File

@ -10,6 +10,7 @@ import NewRequest from 'components/Sidebar/NewRequest';
import { sendRequest, saveRequest, saveCollectionRoot } from 'providers/ReduxStore/slices/collections/actions'; import { sendRequest, saveRequest, saveCollectionRoot } from 'providers/ReduxStore/slices/collections/actions';
import { findCollectionByUid, findItemInCollection } from 'utils/collections'; import { findCollectionByUid, findItemInCollection } from 'utils/collections';
import { closeTabs, switchTab } from 'providers/ReduxStore/slices/tabs'; import { closeTabs, switchTab } from 'providers/ReduxStore/slices/tabs';
import { getKeyBindingsForActionAllOS } from './keyMappings';
export const HotkeysContext = React.createContext(); export const HotkeysContext = React.createContext();
@ -43,7 +44,7 @@ export const HotkeysProvider = (props) => {
// save hotkey // save hotkey
useEffect(() => { useEffect(() => {
Mousetrap.bind(['command+s', 'ctrl+s'], (e) => { Mousetrap.bind([...getKeyBindingsForActionAllOS('save')], (e) => {
if (isEnvironmentSettingsModalOpen) { if (isEnvironmentSettingsModalOpen) {
console.log('todo: save environment settings'); console.log('todo: save environment settings');
} else { } else {
@ -68,13 +69,13 @@ export const HotkeysProvider = (props) => {
}); });
return () => { return () => {
Mousetrap.unbind(['command+s', 'ctrl+s']); Mousetrap.unbind([...getKeyBindingsForActionAllOS('save')]);
}; };
}, [activeTabUid, tabs, saveRequest, collections, isEnvironmentSettingsModalOpen]); }, [activeTabUid, tabs, saveRequest, collections, isEnvironmentSettingsModalOpen]);
// send request (ctrl/cmd + enter) // send request (ctrl/cmd + enter)
useEffect(() => { useEffect(() => {
Mousetrap.bind(['command+enter', 'ctrl+enter'], (e) => { Mousetrap.bind([...getKeyBindingsForActionAllOS('sendRequest')], (e) => {
const activeTab = find(tabs, (t) => t.uid === activeTabUid); const activeTab = find(tabs, (t) => t.uid === activeTabUid);
if (activeTab) { if (activeTab) {
const collection = findCollectionByUid(collections, activeTab.collectionUid); const collection = findCollectionByUid(collections, activeTab.collectionUid);
@ -95,13 +96,13 @@ export const HotkeysProvider = (props) => {
}); });
return () => { return () => {
Mousetrap.unbind(['command+enter', 'ctrl+enter']); Mousetrap.unbind([...getKeyBindingsForActionAllOS('sendRequest')]);
}; };
}, [activeTabUid, tabs, saveRequest, collections]); }, [activeTabUid, tabs, saveRequest, collections]);
// edit environments (ctrl/cmd + e) // edit environments (ctrl/cmd + e)
useEffect(() => { useEffect(() => {
Mousetrap.bind(['command+e', 'ctrl+e'], (e) => { Mousetrap.bind([...getKeyBindingsForActionAllOS('editEnvironment')], (e) => {
const activeTab = find(tabs, (t) => t.uid === activeTabUid); const activeTab = find(tabs, (t) => t.uid === activeTabUid);
if (activeTab) { if (activeTab) {
const collection = findCollectionByUid(collections, activeTab.collectionUid); const collection = findCollectionByUid(collections, activeTab.collectionUid);
@ -115,13 +116,13 @@ export const HotkeysProvider = (props) => {
}); });
return () => { return () => {
Mousetrap.unbind(['command+e', 'ctrl+e']); Mousetrap.unbind([...getKeyBindingsForActionAllOS('editEnvironment')]);
}; };
}, [activeTabUid, tabs, collections, setShowEnvSettingsModal]); }, [activeTabUid, tabs, collections, setShowEnvSettingsModal]);
// new request (ctrl/cmd + b) // new request (ctrl/cmd + b)
useEffect(() => { useEffect(() => {
Mousetrap.bind(['command+b', 'ctrl+b'], (e) => { Mousetrap.bind([...getKeyBindingsForActionAllOS('newRequest')], (e) => {
const activeTab = find(tabs, (t) => t.uid === activeTabUid); const activeTab = find(tabs, (t) => t.uid === activeTabUid);
if (activeTab) { if (activeTab) {
const collection = findCollectionByUid(collections, activeTab.collectionUid); const collection = findCollectionByUid(collections, activeTab.collectionUid);
@ -135,13 +136,13 @@ export const HotkeysProvider = (props) => {
}); });
return () => { return () => {
Mousetrap.unbind(['command+b', 'ctrl+b']); Mousetrap.unbind([...getKeyBindingsForActionAllOS('newRequest')]);
}; };
}, [activeTabUid, tabs, collections, setShowNewRequestModal]); }, [activeTabUid, tabs, collections, setShowNewRequestModal]);
// close tab hotkey // close tab hotkey
useEffect(() => { useEffect(() => {
Mousetrap.bind(['command+w', 'ctrl+w'], (e) => { Mousetrap.bind([...getKeyBindingsForActionAllOS('closeTab')], (e) => {
dispatch( dispatch(
closeTabs({ closeTabs({
tabUids: [activeTabUid] tabUids: [activeTabUid]
@ -152,13 +153,13 @@ export const HotkeysProvider = (props) => {
}); });
return () => { return () => {
Mousetrap.unbind(['command+w', 'ctrl+w']); Mousetrap.unbind([...getKeyBindingsForActionAllOS('closeTab')]);
}; };
}, [activeTabUid]); }, [activeTabUid]);
// Switch to the previous tab // Switch to the previous tab
useEffect(() => { useEffect(() => {
Mousetrap.bind(['command+pageup', 'ctrl+pageup'], (e) => { Mousetrap.bind([...getKeyBindingsForActionAllOS('switchToPreviousTab')], (e) => {
dispatch( dispatch(
switchTab({ switchTab({
direction: 'pageup' direction: 'pageup'
@ -169,13 +170,13 @@ export const HotkeysProvider = (props) => {
}); });
return () => { return () => {
Mousetrap.unbind(['command+pageup', 'ctrl+pageup']); Mousetrap.unbind([...getKeyBindingsForActionAllOS('switchToPreviousTab')]);
}; };
}, [dispatch]); }, [dispatch]);
// Switch to the next tab // Switch to the next tab
useEffect(() => { useEffect(() => {
Mousetrap.bind(['command+pagedown', 'ctrl+pagedown'], (e) => { Mousetrap.bind([...getKeyBindingsForActionAllOS('switchToNextTab')], (e) => {
dispatch( dispatch(
switchTab({ switchTab({
direction: 'pagedown' direction: 'pagedown'
@ -186,13 +187,13 @@ export const HotkeysProvider = (props) => {
}); });
return () => { return () => {
Mousetrap.unbind(['command+pagedown', 'ctrl+pagedown']); Mousetrap.unbind([...getKeyBindingsForActionAllOS('switchToNextTab')]);
}; };
}, [dispatch]); }, [dispatch]);
// Close all tabs // Close all tabs
useEffect(() => { useEffect(() => {
Mousetrap.bind(['command+shift+w', 'ctrl+shift+w'], (e) => { Mousetrap.bind([...getKeyBindingsForActionAllOS('closeAllTabs')], (e) => {
const activeTab = find(tabs, (t) => t.uid === activeTabUid); const activeTab = find(tabs, (t) => t.uid === activeTabUid);
if (activeTab) { if (activeTab) {
const collection = findCollectionByUid(collections, activeTab.collectionUid); const collection = findCollectionByUid(collections, activeTab.collectionUid);
@ -211,7 +212,7 @@ export const HotkeysProvider = (props) => {
}); });
return () => { return () => {
Mousetrap.unbind(['command+shift+w', 'ctrl+shift+w']); Mousetrap.unbind([...getKeyBindingsForActionAllOS('closeAllTabs')]);
}; };
}, [activeTabUid, tabs, collections, dispatch]); }, [activeTabUid, tabs, collections, dispatch]);

View File

@ -0,0 +1,60 @@
const KeyMapping = {
save: { mac: 'command+s', windows: 'ctrl+s', name: 'Save' },
sendRequest: { mac: 'command+enter', windows: 'ctrl+enter', name: 'Send Request' },
editEnvironment: { mac: 'command+e', windows: 'ctrl+e', name: 'Edit Environment' },
newRequest: { mac: 'command+b', windows: 'ctrl+b', name: 'New Request' },
closeTab: { mac: 'command+w', windows: 'ctrl+w', name: 'Close Tab' },
openPreferences: { mac: 'command+,', windows: 'ctrl+,', name: 'Open Preferences' },
minimizeWindow: {
mac: 'command+Shift+Q',
windows: 'control+Shift+Q',
name: 'Minimize Window'
},
switchToPreviousTab: {
mac: 'command+pageup',
windows: 'ctrl+pageup',
name: 'Switch to Previous Tab'
},
switchToNextTab: {
mac: 'command+pagedown',
windows: 'ctrl+pagedown',
name: 'Switch to Next Tab'
},
closeAllTabs: { mac: 'command+shift+w', windows: 'ctrl+shift+w', name: 'Close All Tabs' }
};
/**
* Retrieves the key bindings for a specific operating system.
*
* @param {string} os - The operating system (e.g., 'mac', 'windows').
* @returns {Object} An object containing the key bindings for the specified OS.
*/
export const getKeyBindingsForOS = (os) => {
const keyBindings = {};
for (const [action, { name, ...keys }] of Object.entries(KeyMapping)) {
if (keys[os]) {
keyBindings[action] = {
keys: keys[os],
name
};
}
}
return keyBindings;
};
/**
* Retrieves the key bindings for a specific action across all operating systems.
*
* @param {string} action - The action for which to retrieve key bindings.
* @returns {Object|null} An object containing the key bindings for macOS, Windows, or null if the action is not found.
*/
export const getKeyBindingsForActionAllOS = (action) => {
const actionBindings = KeyMapping[action];
if (!actionBindings) {
console.warn(`Action "${action}" not found in KeyMapping.`);
return null;
}
return [actionBindings.mac, actionBindings.windows];
};

View File

@ -44,6 +44,7 @@ import { parsePathParams, parseQueryParams, splitOnFirst } from 'utils/url/index
import { sendCollectionOauth2Request as _sendCollectionOauth2Request } from 'utils/network/index'; import { sendCollectionOauth2Request as _sendCollectionOauth2Request } from 'utils/network/index';
import { name } from 'file-loader'; import { name } from 'file-loader';
import slash from 'utils/common/slash'; import slash from 'utils/common/slash';
import { findCollectionByPathname, findEnvironmentInCollectionByName } from 'utils/collections/index';
export const renameCollection = (newName, collectionUid) => (dispatch, getState) => { export const renameCollection = (newName, collectionUid) => (dispatch, getState) => {
const state = getState(); const state = getState();
@ -972,13 +973,15 @@ export const selectEnvironment = (environmentUid, collectionUid) => (dispatch, g
const collectionCopy = cloneDeep(collection); const collectionCopy = cloneDeep(collection);
if (environmentUid) { if (environmentUid) {
const environment = findEnvironmentInCollection(collectionCopy, environmentUid); const environment = findEnvironmentInCollection(collectionCopy, environmentUid);
if (!environment) { if (environment) {
ipcRenderer.invoke('renderer:update-ui-state-snapshot', { type: 'COLLECTION_ENVIRONMENT', data: { collectionPath: collection?.pathname, environmentName: environment?.name } })
dispatch(_selectEnvironment({ environmentUid, collectionUid }));
resolve();
}
else {
return reject(new Error('Environment not found')); return reject(new Error('Environment not found'));
} }
} }
dispatch(_selectEnvironment({ environmentUid, collectionUid }));
resolve();
}); });
}; };
@ -1141,3 +1144,33 @@ export const saveCollectionSecurityConfig = (collectionUid, securityConfig) => (
.catch(reject); .catch(reject);
}); });
}; };
export const hydrateCollectionsWithUiStateSnapshot = (payload) => (dispatch, getState) => {
const collectionSnapshotData = payload;
return new Promise((resolve, reject) => {
const state = getState();
try {
if(!collectionSnapshotData) resolve();
const { pathname, selectedEnvironment } = collectionSnapshotData;
const collection = findCollectionByPathname(state.collections.collections, pathname);
const collectionCopy = cloneDeep(collection);
const collectionUid = collectionCopy?.uid;
// update selected environment
if (selectedEnvironment) {
const environment = findEnvironmentInCollectionByName(collectionCopy, selectedEnvironment);
if (environment) {
dispatch(_selectEnvironment({ environmentUid: environment?.uid, collectionUid }));
}
}
// todo: add any other redux state that you want to save
resolve();
}
catch(error) {
reject(error);
}
});
};

View File

@ -132,6 +132,10 @@ export const findEnvironmentInCollection = (collection, envUid) => {
return find(collection.environments, (e) => e.uid === envUid); return find(collection.environments, (e) => e.uid === envUid);
}; };
export const findEnvironmentInCollectionByName = (collection, name) => {
return find(collection.environments, (e) => e.name === name);
};
export const moveCollectionItem = (collection, draggedItem, targetItem) => { export const moveCollectionItem = (collection, draggedItem, targetItem) => {
let draggedItemParent = findParentItemInCollection(collection, draggedItem.uid); let draggedItemParent = findParentItemInCollection(collection, draggedItem.uid);

View File

@ -1,5 +1,5 @@
{ {
"version": "v1.30.1", "version": "v1.31.0",
"name": "bruno", "name": "bruno",
"description": "Opensource API Client for Exploring and Testing APIs", "description": "Opensource API Client for Exploring and Testing APIs",
"homepage": "https://www.usebruno.com", "homepage": "https://www.usebruno.com",

View File

@ -12,6 +12,7 @@ const { decryptString } = require('../utils/encryption');
const { setDotEnvVars } = require('../store/process-env'); const { setDotEnvVars } = require('../store/process-env');
const { setBrunoConfig } = require('../store/bruno-config'); const { setBrunoConfig } = require('../store/bruno-config');
const EnvironmentSecretsStore = require('../store/env-secrets'); const EnvironmentSecretsStore = require('../store/env-secrets');
const UiStateSnapshot = require('../store/ui-state-snapshot');
const environmentSecretsStore = new EnvironmentSecretsStore(); const environmentSecretsStore = new EnvironmentSecretsStore();
@ -201,7 +202,6 @@ const add = async (win, pathname, collectionUid, collectionPath) => {
const payload = { const payload = {
collectionUid, collectionUid,
processEnvVariables: { processEnvVariables: {
...process.env,
...jsonData ...jsonData
} }
}; };
@ -331,7 +331,6 @@ const change = async (win, pathname, collectionUid, collectionPath) => {
const payload = { const payload = {
collectionUid, collectionUid,
processEnvVariables: { processEnvVariables: {
...process.env,
...jsonData ...jsonData
} }
}; };
@ -423,6 +422,13 @@ const unlinkDir = (win, pathname, collectionUid, collectionPath) => {
win.webContents.send('main:collection-tree-updated', 'unlinkDir', directory); win.webContents.send('main:collection-tree-updated', 'unlinkDir', directory);
}; };
const onWatcherSetupComplete = (win, collectionPath) => {
const UiStateSnapshotStore = new UiStateSnapshot();
const collectionsSnapshotState = UiStateSnapshotStore.getCollections();
const collectionSnapshotState = collectionsSnapshotState?.find(c => c?.pathname == collectionPath);
win.webContents.send('main:hydrate-app-with-ui-state-snapshot', collectionSnapshotState);
};
class Watcher { class Watcher {
constructor() { constructor() {
this.watchers = {}; this.watchers = {};
@ -458,6 +464,7 @@ class Watcher {
let startedNewWatcher = false; let startedNewWatcher = false;
watcher watcher
.on('ready', () => onWatcherSetupComplete(win, watchPath))
.on('add', (pathname) => add(win, pathname, collectionUid, watchPath)) .on('add', (pathname) => add(win, pathname, collectionUid, watchPath))
.on('addDir', (pathname) => addDirectory(win, pathname, collectionUid, watchPath)) .on('addDir', (pathname) => addDirectory(win, pathname, collectionUid, watchPath))
.on('change', (pathname) => change(win, pathname, collectionUid, watchPath)) .on('change', (pathname) => change(win, pathname, collectionUid, watchPath))

View File

@ -25,9 +25,11 @@ const { moveRequestUid, deleteRequestUid } = require('../cache/requestUids');
const { deleteCookiesForDomain, getDomainsWithCookies } = require('../utils/cookies'); const { deleteCookiesForDomain, getDomainsWithCookies } = require('../utils/cookies');
const EnvironmentSecretsStore = require('../store/env-secrets'); const EnvironmentSecretsStore = require('../store/env-secrets');
const CollectionSecurityStore = require('../store/collection-security'); const CollectionSecurityStore = require('../store/collection-security');
const UiStateSnapshot = require('../store/ui-state-snapshot');
const environmentSecretsStore = new EnvironmentSecretsStore(); const environmentSecretsStore = new EnvironmentSecretsStore();
const collectionSecurityStore = new CollectionSecurityStore(); const collectionSecurityStore = new CollectionSecurityStore();
const UiStateSnapshotStore = new UiStateSnapshot();
const envHasSecrets = (environment = {}) => { const envHasSecrets = (environment = {}) => {
const secrets = _.filter(environment.variables, (v) => v.secret); const secrets = _.filter(environment.variables, (v) => v.secret);
@ -695,6 +697,14 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
return Promise.reject(error); return Promise.reject(error);
} }
}); });
ipcMain.handle('renderer:update-ui-state-snapshot', (event, { type, data }) => {
try {
UiStateSnapshotStore.update({ type, data });
} catch (error) {
throw new Error(error.message);
}
});
}; };
const registerMainEventHandlers = (mainWindow, watcher, lastOpenedCollections) => { const registerMainEventHandlers = (mainWindow, watcher, lastOpenedCollections) => {

View File

@ -68,6 +68,12 @@ const interpolateVars = (request, envVariables = {}, runtimeVariables = {}, proc
if (request.data.length) { if (request.data.length) {
request.data = _interpolate(request.data); request.data = _interpolate(request.data);
} }
} else if (typeof request.data === 'object') {
try {
let parsed = JSON.stringify(request.data);
parsed = _interpolate(parsed);
request.data = JSON.parse(parsed);
} catch (err) {}
} }
} else if (contentType === 'application/x-www-form-urlencoded') { } else if (contentType === 'application/x-www-form-urlencoded') {
if (typeof request.data === 'object') { if (typeof request.data === 'object') {

View File

@ -0,0 +1,60 @@
const Store = require('electron-store');
class UiStateSnapshot {
constructor() {
this.store = new Store({
name: 'ui-state-snapshot',
clearInvalidConfig: true
});
}
getCollections() {
return this.store.get('collections') || [];
}
saveCollections(collections) {
this.store.set('collections', collections);
}
getCollectionByPathname({ pathname }) {
let collections = this.getCollections();
let collection = collections.find(c => c?.pathname === pathname);
if (!collection) {
collection = { pathname };
collections.push(collection);
this.saveCollections(collections);
}
return collection;
}
setCollectionByPathname({ collection }) {
let collections = this.getCollections();
collections = collections.filter(c => c?.pathname !== collection.pathname);
collections.push({ ...collection });
this.saveCollections(collections);
return collection;
}
updateCollectionEnvironment({ collectionPath, environmentName }) {
const collection = this.getCollectionByPathname({ pathname: collectionPath });
collection.selectedEnvironment = environmentName;
this.setCollectionByPathname({ collection });
}
update({ type, data }) {
switch(type) {
case 'COLLECTION_ENVIRONMENT':
const { collectionPath, environmentName } = data;
this.updateCollectionEnvironment({ collectionPath, environmentName });
break;
default:
break;
}
}
}
module.exports = UiStateSnapshot;