Skip to content

Commit a103f18

Browse files
refactor: streamline preferences IPC handling and filter invalid directories from last opened collections
1 parent 0d99457 commit a103f18

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

packages/bruno-electron/src/ipc/preferences.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ const { getPreferences, savePreferences, preferencesUtil } = require('../store/p
33
const { isDirectory } = require('../utils/filesystem');
44
const { openCollection } = require('../app/collections');
55
const { globalEnvironmentsStore } = require('../store/global-environments');
6-
``;
6+
77
const registerPreferencesIpc = (mainWindow, watcher, lastOpenedCollections) => {
8-
ipcMain.handle('renderer:ready', async (event) => {
8+
ipcMain.handle('renderer:ready', async () => {
99
// load preferences
1010
const preferences = getPreferences();
1111
mainWindow.webContents.send('main:load-preferences', preferences);
1212

1313
// load system proxy vars
14-
const systemProxyVars = preferencesUtil.getSystemProxyEnvVariables();
15-
const { http_proxy, https_proxy, no_proxy } = systemProxyVars || {};
14+
const { http_proxy, https_proxy, no_proxy } = preferencesUtil.getSystemProxyEnvVariables() || {};
1615
mainWindow.webContents.send('main:load-system-proxy-env', { http_proxy, https_proxy, no_proxy });
1716

1817
// load global environments
@@ -23,16 +22,20 @@ const registerPreferencesIpc = (mainWindow, watcher, lastOpenedCollections) => {
2322

2423
// reload last opened collections
2524
const lastOpened = lastOpenedCollections.getAll();
25+
const invalidDirectories = [];
2626

2727
if (lastOpened && lastOpened.length) {
28-
for (let collectionPath of lastOpened) {
28+
for (const collectionPath of lastOpened) {
2929
if (isDirectory(collectionPath)) {
30-
await openCollection(mainWindow, watcher, collectionPath, {
31-
dontSendDisplayErrors: true
32-
});
30+
await openCollection(mainWindow, watcher, collectionPath, { dontSendDisplayErrors: true });
31+
} else {
32+
invalidDirectories.push(collectionPath);
3333
}
3434
}
3535
}
36+
37+
const updatedLastOpenedCollections = lastOpened.filter(coll => !invalidDirectories.includes(coll));
38+
lastOpenedCollections.update(updatedLastOpenedCollections);
3639
});
3740

3841
ipcMain.on('main:open-preferences', () => {
@@ -48,4 +51,4 @@ const registerPreferencesIpc = (mainWindow, watcher, lastOpenedCollections) => {
4851
});
4952
};
5053

51-
module.exports = registerPreferencesIpc;
54+
module.exports = registerPreferencesIpc;

0 commit comments

Comments
 (0)