@@ -173,7 +173,8 @@ export class ProxyStore {
173173            http : any , 
174174            webrtc : any 
175175        } > ( { 
176-             adminServerUrl : 'http://127.0.0.1:45456' 
176+             adminServerUrl : 'http://127.0.0.1:45456' , 
177+             adminStreamReconnectAttempts : Infinity 
177178        } ) ; 
178179
179180        // These are persisted initially, so we know if the user updates them that we 
@@ -237,7 +238,29 @@ export class ProxyStore {
237238        } ) ; 
238239    } ) ; 
239240
240-     private  monitorRemoteClientConnection ( client : PluggableAdmin . AdminClient < { } > )  { 
241+     @observable 
242+     streamDisconnected : boolean  =  false ; 
243+ 
244+     private  async  monitorRemoteClientConnection ( client : PluggableAdmin . AdminClient < { } > )  { 
245+         // Track stream connect/disconnected state: 
246+         client . on ( 'stream-reconnecting' ,  action ( ( )  =>  { 
247+             console . log ( 'Admin client stream reconnecting...' ) ; 
248+             this . streamDisconnected  =  true ; 
249+         } ) ) ; 
250+ 
251+         client . on ( 'stream-reconnected' ,  action ( ( )  =>  { 
252+             console . log ( 'Admin client reconnected' ) ; 
253+             this . streamDisconnected  =  false ; 
254+         } ) ) ; 
255+ 
256+         // We show the below as disconnection, but we generally won't recover - this 
257+         // probably means the server has unexpectedly cleanly shut down. 
258+         client . on ( 'stopped' ,  action ( ( )  =>  { 
259+             console . log ( 'Server stopped' ) ; 
260+             this . streamDisconnected  =  true ; 
261+         } ) ) ; 
262+ 
263+         // Log various other related events for debugging: 
241264        client . on ( 'stream-error' ,  ( err )  =>  { 
242265            console . log ( 'Admin client stream error' ,  err ) ; 
243266        } ) ; 
@@ -246,19 +269,6 @@ export class ProxyStore {
246269        } ) ; 
247270        client . on ( 'stream-reconnect-failed' ,  ( err )  =>  { 
248271            logError ( err . message  ? err  : new  Error ( 'Client reconnect error' ) ,  {  cause : err  } ) ; 
249- 
250-             alert ( "Server disconnected unexpectedly, app restart required.\n\nPlease report this at github.com/httptoolkit/httptoolkit." ) ; 
251-             setTimeout ( ( )  =>  {  // Tiny wait for any other UI events to fire (error reporting/logging/other UI responsiveness) 
252-                 if  ( DesktopApi . restartApp )  { 
253-                     // Where possible (recent desktop release) we restart the whole app directly 
254-                     DesktopApi . restartApp ( ) ; 
255-                 }  else  if  ( ! navigator . platform ?. startsWith ( 'Mac' ) )  { 
256-                     // If not, on Windows & Linux we just close the window (which restarts) 
257-                     window . close ( ) ; 
258-                 } 
259-                 // On Mac, app exit is independent from window exit, so we can't force that here, 
260-                 // but hopefully this alert will lead the user to do so themselves. 
261-             } ,  10 ) ; 
262272        } ) ; 
263273    } 
264274
0 commit comments