Files
bruno/packages/bruno-electron/src/ipc/preferences.js
lohit c1ec95dc29 fix: option to toggle on/off system proxy env variables (#2724)
fix: option to toggle on/off system proxy env variables
2024-08-30 11:44:29 +05:30

44 lines
1.5 KiB
JavaScript

const { ipcMain } = require('electron');
const { getPreferences, savePreferences, preferencesUtil } = require('../store/preferences');
const { isDirectory } = require('../utils/filesystem');
const { openCollection } = require('../app/collections');
``;
const registerPreferencesIpc = (mainWindow, watcher, lastOpenedCollections) => {
ipcMain.handle('renderer:ready', async (event) => {
// load preferences
const preferences = getPreferences();
mainWindow.webContents.send('main:load-preferences', preferences);
const systemProxyVars = preferencesUtil.getSystemProxyEnvVariables();
const { http_proxy, https_proxy, no_proxy } = systemProxyVars || {};
mainWindow.webContents.send('main:load-system-proxy-env', { http_proxy, https_proxy, no_proxy });
// reload last opened collections
const lastOpened = lastOpenedCollections.getAll();
if (lastOpened && lastOpened.length) {
for (let collectionPath of lastOpened) {
if (isDirectory(collectionPath)) {
await openCollection(mainWindow, watcher, collectionPath, {
dontSendDisplayErrors: true
});
}
}
}
});
ipcMain.on('main:open-preferences', () => {
mainWindow.webContents.send('main:open-preferences');
});
ipcMain.handle('renderer:save-preferences', async (event, preferences) => {
try {
await savePreferences(preferences);
} catch (error) {
return Promise.reject(error);
}
});
};
module.exports = registerPreferencesIpc;