Skip to content

Commit 667cd65

Browse files
committed
fix: app crash on clicking close button \n Added collection, workspace, and api spec watcher cleanup on app close method
1 parent 4f5c738 commit 667cd65

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

packages/bruno-electron/src/app/apiSpecsWatcher.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ class ApiSpecWatcher {
141141
delete this.watcherWorkspaces[watchPath];
142142
}
143143
}
144+
145+
closeAllWatchers() {
146+
for (const [watchPath, watcher] of Object.entries(this.watchers)) {
147+
if (watcher) {
148+
try {
149+
watcher.close();
150+
} catch (err) {}
151+
}
152+
}
153+
this.watchers = {};
154+
this.watcherWorkspaces = {};
155+
}
144156
}
145157

146158
module.exports = ApiSpecWatcher;

packages/bruno-electron/src/app/collection-watcher.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,17 @@ class CollectionWatcher {
958958
.filter(([path, watcher]) => !!watcher)
959959
.map(([path, _watcher]) => path);
960960
}
961+
962+
closeAllWatchers() {
963+
for (const [watchPath, watcher] of Object.entries(this.watchers)) {
964+
if (watcher) {
965+
try {
966+
watcher.close();
967+
} catch (err) {}
968+
}
969+
}
970+
this.watchers = {};
971+
}
961972
}
962973

963974
const collectionWatcher = new CollectionWatcher();

packages/bruno-electron/src/app/workspace-watcher.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,28 @@ class WorkspaceWatcher {
224224
hasWatcher(workspacePath) {
225225
return Boolean(this.watchers[workspacePath]);
226226
}
227+
228+
closeAllWatchers() {
229+
for (const [watchPath, watcher] of Object.entries(this.watchers)) {
230+
if (watcher) {
231+
try {
232+
watcher.close();
233+
} catch (err) {}
234+
}
235+
}
236+
this.watchers = {};
237+
238+
for (const [watchPath, watcher] of Object.entries(this.environmentWatchers)) {
239+
if (watcher) {
240+
try {
241+
watcher.close();
242+
} catch (err) {}
243+
}
244+
}
245+
this.environmentWatchers = {};
246+
247+
dotEnvWatcher.closeAll();
248+
}
227249
}
228250

229251
module.exports = WorkspaceWatcher;

packages/bruno-electron/src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ app.on('ready', async () => {
387387

388388
mainWindow.on('close', (e) => {
389389
e.preventDefault();
390+
collectionWatcher.closeAllWatchers();
391+
workspaceWatcher.closeAllWatchers();
392+
apiSpecWatcher.closeAllWatchers();
390393
terminalManager.cleanup(mainWindow.webContents);
391394
ipcMain.emit('main:start-quit-flow');
392395
});
@@ -459,6 +462,9 @@ app.on('ready', async () => {
459462

460463
// Quit the app once all windows are closed
461464
app.on('before-quit', () => {
465+
collectionWatcher.closeAllWatchers();
466+
workspaceWatcher.closeAllWatchers();
467+
apiSpecWatcher.closeAllWatchers();
462468
// Release single instance lock to allow other instances to take over
463469
if (useSingleInstance && gotTheLock) {
464470
app.releaseSingleInstanceLock();

0 commit comments

Comments
 (0)