removed custom ipc event

This commit is contained in:
Amr osama 2023-10-23 11:11:31 +03:00
parent cbfd7fa5f4
commit e658629482
3 changed files with 6 additions and 31 deletions

View File

@ -3,7 +3,8 @@ import { useFormik } from 'formik';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
import StyledWrapper from './StyledWrapper'; import StyledWrapper from './StyledWrapper';
import toast from 'react-hot-toast'; import toast from 'react-hot-toast';
import { updateCollectionPresets } from 'providers/ReduxStore/slices/collections/actions'; import { updateBrunoConfig } from 'providers/ReduxStore/slices/collections/actions';
import cloneDeep from 'lodash/cloneDeep';
const PresetsSettings = ({ collection }) => { const PresetsSettings = ({ collection }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -18,7 +19,9 @@ const PresetsSettings = ({ collection }) => {
defaultRequestUrl: defaultPresets.defaultRequestUrl || '' defaultRequestUrl: defaultPresets.defaultRequestUrl || ''
}, },
onSubmit: (newPresets) => { onSubmit: (newPresets) => {
dispatch(updateCollectionPresets(newPresets, collection.uid)); const brunoConfig = cloneDeep(collection.brunoConfig);
brunoConfig.presets = newPresets;
dispatch(updateBrunoConfig(brunoConfig, collection.uid));
toast.success('Collection presets updated'); toast.success('Collection presets updated');
} }
}); });

View File

@ -12,8 +12,7 @@ import {
collectionRenamedEvent, collectionRenamedEvent,
runRequestEvent, runRequestEvent,
runFolderEvent, runFolderEvent,
brunoConfigUpdateEvent, brunoConfigUpdateEvent
collectionPresetsUpdatedEvent
} from 'providers/ReduxStore/slices/collections'; } from 'providers/ReduxStore/slices/collections';
import { updatePreferences } from 'providers/ReduxStore/slices/app'; import { updatePreferences } from 'providers/ReduxStore/slices/app';
import toast from 'react-hot-toast'; import toast from 'react-hot-toast';
@ -108,10 +107,6 @@ const useIpcEvents = () => {
dispatch(collectionRenamedEvent(val)); dispatch(collectionRenamedEvent(val));
}); });
const removeCollectionPresetsUpdatedListener = ipcRenderer.on('main:collection-presets-updated', (val) => {
dispatch(collectionPresetsUpdatedEvent(val));
});
const removeRunFolderEventListener = ipcRenderer.on('main:run-folder-event', (val) => { const removeRunFolderEventListener = ipcRenderer.on('main:run-folder-event', (val) => {
dispatch(runFolderEvent(val)); dispatch(runFolderEvent(val));
}); });
@ -143,7 +138,6 @@ const useIpcEvents = () => {
removeDisplayErrorListener(); removeDisplayErrorListener();
removeScriptEnvUpdateListener(); removeScriptEnvUpdateListener();
removeCollectionRenamedListener(); removeCollectionRenamedListener();
removeCollectionPresetsUpdatedListener();
removeRunFolderEventListener(); removeRunFolderEventListener();
removeRunRequestEventListener(); removeRunRequestEventListener();
removeProcessEnvUpdatesListener(); removeProcessEnvUpdatesListener();

View File

@ -94,28 +94,6 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
} }
}); });
// update collection properties
ipcMain.handle('renderer:update-collection-presets', async (event, newPresets, collectionPathname) => {
try {
const brunoJsonFilePath = path.join(collectionPathname, 'bruno.json');
const content = fs.readFileSync(brunoJsonFilePath, 'utf8');
const json = JSON.parse(content);
json.presets = newPresets;
const newContent = await stringifyJson(json);
await writeFile(brunoJsonFilePath, newContent);
// fire an event in renderer to change the collection properties
mainWindow.webContents.send('main:collection-presets-updated', {
collectionPathname,
newPresets
});
} catch (error) {
return Promise.reject(error);
}
});
ipcMain.handle('renderer:save-collection-root', async (event, collectionPathname, collectionRoot) => { ipcMain.handle('renderer:save-collection-root', async (event, collectionPathname, collectionRoot) => {
try { try {
const collectionBruFilePath = path.join(collectionPathname, 'collection.bru'); const collectionBruFilePath = path.join(collectionPathname, 'collection.bru');