Skip to content

Commit 703f46b

Browse files
committed
Fix webContents event leak
1 parent f84b526 commit 703f46b

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"type": "node",
77
"request": "launch",
88
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
9-
"args": ["${workspaceFolder}/test/sample.js"],
9+
"args": ["--trace-warnings", "${workspaceFolder}/test/sample.js"],
1010
"preLaunchTask": "build:dev",
1111
"env": {
1212
"NODE_ENV": "development"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"build": "npm run clean && webpack",
2323
"build:dev": "npm run clean && NODE_ENV=development webpack",
2424
"dev": "webpack --mode development --watch",
25-
"sample": "electron test/sample.js"
25+
"sample": "electron --trace-warnings test/sample.js"
2626
},
2727
"repository": {
2828
"type": "git",

src/main.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ class Findbar {
6868
if (!this.findableContents) { throw new Error('There are no searchable web contents.'); }
6969

7070
this.findableContents._findbar = this;
71-
72-
this.findableContents.once('destroyed', () => { this.detach(); });
71+
this.findableContents.prependOnceListener('destroyed', () => { this.detach(); });
72+
this.findableContents.prependListener('found-in-page', (_e, result: FindInPageResult) => {
73+
this.sendMatchesCount(result.activeMatchOrdinal, result.matches);
74+
});
7375
this.updateParentWindow(parent);
7476
}
7577

@@ -369,12 +371,6 @@ class Findbar {
369371
this.window!.webContents.prependListener('before-input-event', (event, input) => {
370372
this.registerKeyboardShortcuts(event, input);
371373
});
372-
this.findableContents.prependOnceListener('destroyed', () => {
373-
this.close();
374-
});
375-
this.findableContents.prependListener('found-in-page', (_e, result: FindInPageResult) => {
376-
this.sendMatchesCount(result.activeMatchOrdinal, result.matches);
377-
});
378374
}
379375

380376
private sendMatchesCount(active: number, total: number): void {

0 commit comments

Comments
 (0)