Skip to content

Commit 811a830

Browse files
committed
fix: prevent tray click event listener from being added multiple times
- Remove existing listener before adding to ensure only one instance - Prevents memory leak from repeated state transitions - Ensures click handler is called exactly once per click This fixes a potential memory leak where tray click listeners could accumulate on repeated RUNNING state transitions. Each state change to RUNNING would add a new listener without removing the old one, leading to multiple stopRun() calls per click and gradual memory growth. The fix uses defensive programming: always remove the listener before adding it, ensuring exactly one listener is active regardless of how many times the state transitions. Severity: Medium-High (6-7/10) Impact: Prevents memory leak and duplicate event handling
1 parent de90499 commit 811a830

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

apps/ui-tars/src/main/tray.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export async function createTray() {
4242
// 根据状态添加或移除点击事件监听
4343
if (state.status === StatusEnum.RUNNING) {
4444
tray?.setImage(pauseIcon);
45+
tray?.removeListener('click', handleTrayClick);
4546
tray?.on('click', handleTrayClick);
4647
} else {
4748
tray?.setImage(normalIcon);

0 commit comments

Comments
 (0)