Skip to content

Commit

Permalink
Merge pull request #5 from nkolba/fix-doubles-after-reactivate
Browse files Browse the repository at this point in the history
better cleanup runtime objects and listeners so that we don't get dou…
  • Loading branch information
nkolba authored Mar 30, 2022
2 parents 0fcff33 + 681dad7 commit b8222c5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ app.disableHardwareAcceleration();
*/
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
if (runtime) {
runtime.clean();
runtime = null;
}
app.quit();
}
});
Expand All @@ -85,6 +89,11 @@ app.on('window-all-closed', () => {
* @see https://www.electronjs.org/docs/v14-x-y/api/app#event-activate-macos Event: 'activate'
*/
app.on('activate', () => {
console.log('activated');
if (runtime) {
runtime.clean();
runtime = null;
}
runtime = new Runtime();
createWindow();
});
Expand Down
2 changes: 2 additions & 0 deletions packages/main/src/listeners/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export class RuntimeListener {

constructor(runtime: Runtime) {
this.runtime = runtime;
//start with clean IPC
ipcMain.removeAllListeners();

ipcMain.on(TOPICS.SELECT_TAB, (event, args) => {
//bring selected browserview to front
Expand Down
8 changes: 8 additions & 0 deletions packages/main/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,12 @@ export class Runtime {
dropResolver() {
resolver = undefined;
}

//cleanup state of the runtime
clean() {
contexts.clear();
views.clear();
workspaces.clear();
resolver = undefined;
}
}

0 comments on commit b8222c5

Please sign in to comment.