File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -48,11 +48,8 @@ class CapacitorSerialProtocol extends EventTarget {
4848 }
4949
5050 cleanup ( ) {
51- UsbSerial . removeAllListeners ( "data" ) ;
52- UsbSerial . removeAllListeners ( "connected" ) ;
53- UsbSerial . removeAllListeners ( "attached" ) ;
54- UsbSerial . removeAllListeners ( "detached" ) ;
55- UsbSerial . removeAllListeners ( "error" ) ;
51+ // Don't remove listeners - they need to persist for reconnection and device attach/detach events
52+ // Only cleanup is handled in disconnect() by resetting state
5653 }
5754
5855 handleDataEvent ( event ) {
@@ -68,8 +65,14 @@ class CapacitorSerialProtocol extends EventTarget {
6865 this . connected = true ;
6966 }
7067
71- handleAttachedEvent ( event ) {
72- this . handleNewDevice ( event ) ;
68+ async handleAttachedEvent ( event ) {
69+ // Reload device list to ensure we have the latest device info with proper permissions
70+ await this . loadDevices ( ) ;
71+
72+ const added = this . handleNewDevice ( event ) ;
73+ if ( added ) {
74+ this . dispatchEvent ( new CustomEvent ( "addedDevice" , { detail : added } ) ) ;
75+ }
7376 }
7477
7578 handleDetachedEvent ( event ) {
@@ -265,7 +268,7 @@ class CapacitorSerialProtocol extends EventTarget {
265268 console . error ( `${ logHead } Error closing serial connection:` , error ) ;
266269 closeError = error ;
267270 } finally {
268- this . cleanup ( ) ;
271+ // Reset state but keep listeners active for reconnection
269272 this . isOpen = false ;
270273 this . connected = false ;
271274 this . port = null ;
You can’t perform that action at this time.
0 commit comments