@@ -121,6 +121,7 @@ export interface ShellChromeHost extends HTMLElement {
121121
122122export class ShellChromeOwner {
123123 private pendingLazyAction = readLazyShellAction ( ) ;
124+ private listeners : AbortController | undefined ;
124125
125126 constructor ( private readonly host : ShellChromeHost ) { }
126127
@@ -133,56 +134,62 @@ export class ShellChromeOwner {
133134 }
134135
135136 connect ( ) : void {
137+ this . disconnect ( ) ;
138+ this . listeners = new AbortController ( ) ;
139+ // One connection owns all three targets; abort removes exactly its listeners.
140+ const options = { signal : this . listeners . signal } ;
136141 const host = this . host ;
137142 host . nativeHistoryState = readNativeHistoryState ( ) ;
138- host . addEventListener ( COMMAND_PALETTE_TARGET_EVENT , this . handleCommandPaletteTarget ) ;
139- window . addEventListener ( COMMAND_PALETTE_OPEN_EVENT , this . handleCommandPaletteOpen ) ;
140- window . addEventListener ( SHELL_NAV_DRAWER_TOGGLE_EVENT , this . handleShellNavDrawerToggle ) ;
141- window . addEventListener ( DEBUG_OVERLAY_REQUEST_EVENT , this . handleDebugOverlayRequest ) ;
142- window . addEventListener ( KEYBOARD_SHORTCUTS_REQUEST_EVENT , this . handleKeyboardShortcutsRequest ) ;
143- document . addEventListener ( "keydown" , this . handleDocumentKeydown ) ;
144- window . addEventListener ( "resize" , this . handleWindowResize ) ;
145- window . addEventListener ( "dragover" , this . handleUnhandledFileDrag ) ;
146- window . addEventListener ( "drop" , this . handleUnhandledFileDrag ) ;
147- window . addEventListener ( NATIVE_HISTORY_STATE_EVENT , this . handleNativeHistoryState ) ;
143+ host . addEventListener ( COMMAND_PALETTE_TARGET_EVENT , this . handleCommandPaletteTarget , options ) ;
144+ window . addEventListener ( COMMAND_PALETTE_OPEN_EVENT , this . handleCommandPaletteOpen , options ) ;
145+ window . addEventListener (
146+ SHELL_NAV_DRAWER_TOGGLE_EVENT ,
147+ this . handleShellNavDrawerToggle ,
148+ options ,
149+ ) ;
150+ window . addEventListener ( DEBUG_OVERLAY_REQUEST_EVENT , this . handleDebugOverlayRequest , options ) ;
151+ window . addEventListener (
152+ KEYBOARD_SHORTCUTS_REQUEST_EVENT ,
153+ this . handleKeyboardShortcutsRequest ,
154+ options ,
155+ ) ;
156+ document . addEventListener ( "keydown" , this . handleDocumentKeydown , options ) ;
157+ window . addEventListener ( "resize" , this . handleWindowResize , options ) ;
158+ window . addEventListener ( "dragover" , this . handleUnhandledFileDrag , options ) ;
159+ window . addEventListener ( "drop" , this . handleUnhandledFileDrag , options ) ;
160+ window . addEventListener ( NATIVE_HISTORY_STATE_EVENT , this . handleNativeHistoryState , options ) ;
148161 // Shipped Mac hosts use these same events even when native web chrome is absent.
149- window . addEventListener ( "openclaw:native-toggle-sidebar" , this . handleNativeToggleSidebar ) ;
150- window . addEventListener ( "openclaw:native-open-search" , this . handleNativeOpenSearch ) ;
151- window . addEventListener ( "openclaw:native-toggle-search" , this . handleNativeToggleSearch ) ;
152- window . addEventListener ( "openclaw:native-new-session" , this . handleNativeNewSession ) ;
153- window . addEventListener ( "openclaw:native-navigate" , this . handleNativeNavigate ) ;
154- window . addEventListener ( TERMINAL_PANEL_TOGGLE_EVENT , this . handleDeferredTerminalToggle ) ;
155- window . addEventListener ( BROWSER_PANEL_TOGGLE_EVENT , this . handleDeferredBrowserToggle ) ;
156- window . addEventListener ( DESKTOP_PANEL_TOGGLE_EVENT , this . handleDeferredDesktopToggle ) ;
157- window . addEventListener ( CUSTODIAN_PANEL_TOGGLE_EVENT , this . handleDeferredCustodianToggle ) ;
158- window . addEventListener ( SHELL_APPROVALS_OPEN_EVENT , this . handleApprovalsOpen ) ;
162+ window . addEventListener (
163+ "openclaw:native-toggle-sidebar" ,
164+ this . handleNativeToggleSidebar ,
165+ options ,
166+ ) ;
167+ window . addEventListener ( "openclaw:native-open-search" , this . handleNativeOpenSearch , options ) ;
168+ window . addEventListener (
169+ "openclaw:native-toggle-search" ,
170+ this . handleNativeToggleSearch ,
171+ options ,
172+ ) ;
173+ window . addEventListener ( "openclaw:native-new-session" , this . handleNativeNewSession , options ) ;
174+ window . addEventListener ( "openclaw:native-navigate" , this . handleNativeNavigate , options ) ;
175+ window . addEventListener (
176+ TERMINAL_PANEL_TOGGLE_EVENT ,
177+ this . handleDeferredTerminalToggle ,
178+ options ,
179+ ) ;
180+ window . addEventListener ( BROWSER_PANEL_TOGGLE_EVENT , this . handleDeferredBrowserToggle , options ) ;
181+ window . addEventListener ( DESKTOP_PANEL_TOGGLE_EVENT , this . handleDeferredDesktopToggle , options ) ;
182+ window . addEventListener (
183+ CUSTODIAN_PANEL_TOGGLE_EVENT ,
184+ this . handleDeferredCustodianToggle ,
185+ options ,
186+ ) ;
187+ window . addEventListener ( SHELL_APPROVALS_OPEN_EVENT , this . handleApprovalsOpen , options ) ;
159188 }
160189
161190 disconnect ( ) : void {
162- const host = this . host ;
163- host . removeEventListener ( COMMAND_PALETTE_TARGET_EVENT , this . handleCommandPaletteTarget ) ;
164- window . removeEventListener ( COMMAND_PALETTE_OPEN_EVENT , this . handleCommandPaletteOpen ) ;
165- window . removeEventListener ( SHELL_NAV_DRAWER_TOGGLE_EVENT , this . handleShellNavDrawerToggle ) ;
166- window . removeEventListener ( DEBUG_OVERLAY_REQUEST_EVENT , this . handleDebugOverlayRequest ) ;
167- window . removeEventListener (
168- KEYBOARD_SHORTCUTS_REQUEST_EVENT ,
169- this . handleKeyboardShortcutsRequest ,
170- ) ;
171- document . removeEventListener ( "keydown" , this . handleDocumentKeydown ) ;
172- window . removeEventListener ( "resize" , this . handleWindowResize ) ;
173- window . removeEventListener ( "dragover" , this . handleUnhandledFileDrag ) ;
174- window . removeEventListener ( "drop" , this . handleUnhandledFileDrag ) ;
175- window . removeEventListener ( NATIVE_HISTORY_STATE_EVENT , this . handleNativeHistoryState ) ;
176- window . removeEventListener ( "openclaw:native-toggle-sidebar" , this . handleNativeToggleSidebar ) ;
177- window . removeEventListener ( "openclaw:native-open-search" , this . handleNativeOpenSearch ) ;
178- window . removeEventListener ( "openclaw:native-toggle-search" , this . handleNativeToggleSearch ) ;
179- window . removeEventListener ( "openclaw:native-new-session" , this . handleNativeNewSession ) ;
180- window . removeEventListener ( "openclaw:native-navigate" , this . handleNativeNavigate ) ;
181- window . removeEventListener ( TERMINAL_PANEL_TOGGLE_EVENT , this . handleDeferredTerminalToggle ) ;
182- window . removeEventListener ( BROWSER_PANEL_TOGGLE_EVENT , this . handleDeferredBrowserToggle ) ;
183- window . removeEventListener ( DESKTOP_PANEL_TOGGLE_EVENT , this . handleDeferredDesktopToggle ) ;
184- window . removeEventListener ( CUSTODIAN_PANEL_TOGGLE_EVENT , this . handleDeferredCustodianToggle ) ;
185- window . removeEventListener ( SHELL_APPROVALS_OPEN_EVENT , this . handleApprovalsOpen ) ;
191+ this . listeners ?. abort ( ) ;
192+ this . listeners = undefined ;
186193 }
187194
188195 toggleNavigationSurface ( trigger ?: HTMLElement ) : void {
0 commit comments