@@ -357,6 +357,9 @@ class RendererProcess {
357357 return this . win . destroy ( ) ;
358358 }
359359 }
360+ sendCommand ( command , data ) {
361+ return this . win . emit ( command , data ) ;
362+ }
360363}
361364class localServer {
362365 constructor ( version , port ) {
@@ -569,6 +572,7 @@ class localServer {
569572 return CallBack ( ) ;
570573 } ) ;
571574 }
575+ // After password
572576 listenAfterPassword ( socket ) {
573577 socket . on ( 'startCheckImap' , ( id , imapData , CallBack ) => {
574578 if ( ! id || ! id . length || ! imapData || ! Object . keys ( imapData ) . length ) {
@@ -618,17 +622,8 @@ class localServer {
618622 // Have gateway connect!
619623 if ( res . Args [ 1 ] ) {
620624 const uu = res . Args [ 1 ] ;
621- if ( ! this . connectCommand ) {
622- this . connectCommand = uu ;
623- }
624- if ( ! this . proxyServer ) {
625- const runCom = uu . connectType === 1 ? '@Opn' : 'iOpn' ;
626- uu . localServerIp = exports . getLocalInterface ( ) [ 0 ] ;
627- this . proxyServer = new RendererProcess ( runCom , uu , DEBUG , ( ) => {
628- saveLog ( `proxyServerWindow on exit!` ) ;
629- this . proxyServer = null ;
630- this . connectCommand = null ;
631- } ) ;
625+ if ( ! this . proxyServer || ! this . connectCommand ) {
626+ this . makeOpnConnect ( uu ) ;
632627 }
633628 return socket . emit ( 'QTGateGatewayConnectRequest' , this . connectCommand ) ;
634629 }
@@ -733,22 +728,27 @@ class localServer {
733728 // no error
734729 CallBack ( res ) ;
735730 if ( res . error < 0 ) {
736- this . connectCommand = arg ;
737- const runCom = arg . connectType === 1 ? '@Opn' : 'iOpn' ;
738- return this . proxyServer = new RendererProcess ( runCom , arg , DEBUG , ( ) => {
739- saveLog ( `proxyServerWindow on exit!` ) ;
740- this . proxyServer = null ;
741- this . connectCommand = null ;
742- } ) ;
731+ return this . makeOpnConnect ( arg ) ;
743732 }
744733 saveLog ( `res.error [${ res . error } ]` ) ;
745734 } ) ;
746735 } ) ;
747736 } ) ;
748- socket . on ( 'disconnectClick' , CallBack => {
749- this . disConnectGateway ( ) ;
737+ socket . on ( 'disconnectClick' , ( ) => {
750738 this . stopGetwayConnect ( ) ;
751- CallBack ( ) ;
739+ this . disConnectGateway ( ) ;
740+ } ) ;
741+ }
742+ makeOpnConnect ( arg ) {
743+ this . connectCommand = arg ;
744+ const runCom = arg . connectType === 1 ? '@Opn' : 'iOpn' ;
745+ saveLog ( `makeOpnConnect arg [${ JSON . stringify ( arg ) } ]` ) ;
746+ console . trace ( arg ) ;
747+ return this . proxyServer = new RendererProcess ( runCom , arg , DEBUG , ( ) => {
748+ saveLog ( `proxyServerWindow on exit!` ) ;
749+ this . proxyServer = null ;
750+ this . connectCommand = null ;
751+ this . socketServer . emit ( 'disconnectClickCallBack' ) ;
752752 } ) ;
753753 }
754754 disConnectGateway ( ) {
@@ -1367,6 +1367,17 @@ class ImapConnect extends Imap.imapPeer {
13671367 saveLog ( `QTGateAPIRequestCommand on containerStop! doing disConnectGateway()` ) ;
13681368 localServer . disConnectGateway ( ) ;
13691369 }
1370+ case 'changeDocker' : {
1371+ const container = ret . Args [ 0 ] ;
1372+ if ( ! container ) {
1373+ return saveLog ( `got Command from server "changeDocker" but have no data ret = [${ JSON . stringify ( ret ) } ]` ) ;
1374+ }
1375+ if ( ! this . localServer . proxyServer || ! this . localServer . connectCommand ) {
1376+ saveLog ( `got Command from server "changeDocker" localServer.proxyServer or localServer.connectCommand is null!!` ) ;
1377+ return this . localServer . makeOpnConnect ( container ) ;
1378+ }
1379+ this . localServer . proxyServer . sendCommand ( 'changeDocker' , container ) ;
1380+ }
13701381 default : {
13711382 return saveLog ( `QTGateAPIRequestCommand have not requestSerial!, 【${ JSON . stringify ( ret ) } 】` ) ;
13721383 }
@@ -1442,7 +1453,7 @@ class ImapConnect extends Imap.imapPeer {
14421453 return CallBack ( err1 ) ;
14431454 }
14441455 this . append ( data ) ;
1445- saveLog ( `do request command [${ command . command } ] finished and wait server responsr !` ) ;
1456+ saveLog ( `do request command [${ command . command } ] finished and wait server response !` ) ;
14461457 } ) ;
14471458 }
14481459 doingDisconnect ( ) {
0 commit comments