Skip to content

Commit 1a234c8

Browse files
Peter XiePeter Xie
authored andcommitted
v0.8.46
1 parent 3bc7bd7 commit 1a234c8

File tree

7 files changed

+181
-124
lines changed

7 files changed

+181
-124
lines changed

app/proxyServer.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,17 @@ export class proxyServer {
481481

482482
}
483483

484+
public changeDocker ( data: IConnectCommand ) {
485+
if ( !data.gateWayIpAddress || !data.gateWayPort || !data.imapData.randomPassword ) {
486+
return saveLog (`ERROR: changeDocker data ERROR: gateWayIpAddress [${ data.gateWayIpAddress }] gateWayPort [${ data.gateWayPort }] data.imapData.randomPassword [${ data.imapData.randomPassword }]`)
487+
}
488+
this.serverIp = data.gateWayIpAddress
489+
this.serverPort = data.gateWayPort
490+
this.password = data.imapData.randomPassword
491+
this.gateway = new gateWay ( this.serverIp, this.serverPort, this.password )
492+
saveLog (`changeDocker gateWayIpAddress [${ data.gateWayIpAddress }] gateWayPort [${ data.gateWayPort }] data.imapData.randomPassword [${ data.imapData.randomPassword }]`)
493+
}
494+
484495
}
485496

486497
interface proxyServerInfo {
@@ -501,12 +512,17 @@ const saveLog = ( log: string ) => {
501512
})
502513
}
503514

504-
515+
let server: proxyServer = null
505516
remote.getCurrentWindow().once ( 'firstCallBack', ( data: IConnectCommand ) => {
506-
console.log ( data )
507-
const server = new proxyServer ([], new Map(), data.localServerIp, data.localServerPort, 'pac', data.gateWayIpAddress, data.gateWayPort, data.imapData.randomPassword,
517+
saveLog ( `************************** start proxyServer *****************************\r\n ${ JSON.stringify( data )}\r\n` )
518+
server = new proxyServer ([], new Map(), data.localServerIp, data.localServerPort, 'pac', data.gateWayIpAddress, data.gateWayPort, data.imapData.randomPassword,
508519
5000, 50000, data.AllDataToGateway, [] )
509520

510521
})
522+
remote.getCurrentWindow().on( 'changeDocker', ( data: IConnectCommand ) => {
523+
saveLog ( `got changeDocker event! data [${ JSON.stringify ( data )}]`)
524+
server.changeDocker ( data )
525+
})
526+
511527

512528
remote.getCurrentWindow().emit ( 'first' )

app/public/scripts/home.js

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3090,6 +3090,9 @@ var view_layout;
30903090
this.selectedQTGateRegionCancel();
30913091
}
30923092
});
3093+
socketIo.on('disconnectClickCallBack', () => {
3094+
this.desconnectCallBack();
3095+
});
30933096
socketIo.on('QTGateGatewayConnectRequest', data => {
30943097
this.QTGateGatewayConnectRequestCallBack(this, data);
30953098
});
@@ -3550,33 +3553,34 @@ var view_layout;
35503553
this.ConnectGatewayShow(true);
35513554
return data.showConnectedArea(true);
35523555
}
3553-
disconnectClick() {
3554-
this.disconnecting(true);
3555-
socketIo.emit('disconnectClick', () => {
3556-
this.selectedQTGateRegion().showConnectedArea(false);
3557-
this.ConnectGatewayShow(false);
3558-
this.selectedQTGateRegionCancel();
3559-
this.disconnecting(false);
3560-
socketIo.emit('getAvaliableRegion', (region) => {
3561-
this.QTGateRegions().forEach(n => {
3562-
const index = region.findIndex(nn => { return nn === n.qtRegion; });
3563-
if (index < 0)
3564-
return n.available(false);
3565-
return n.available(true);
3566-
});
3567-
this.QTGateRegions.sort((a, b) => {
3568-
if (a.available() === b.available())
3569-
return 0;
3570-
if (b.available() && !a.available()) {
3571-
return 1;
3572-
}
3573-
return -1;
3574-
});
3575-
const imapServer = this.emailPool()[0].iMapServerName();
3576-
this.canDoAtEmail(/imap\.mail\.me\.com$/.test(imapServer));
3556+
desconnectCallBack() {
3557+
this.selectedQTGateRegion().showConnectedArea(false);
3558+
this.ConnectGatewayShow(false);
3559+
this.selectedQTGateRegionCancel();
3560+
this.disconnecting(false);
3561+
socketIo.emit('getAvaliableRegion', (region) => {
3562+
this.QTGateRegions().forEach(n => {
3563+
const index = region.findIndex(nn => { return nn === n.qtRegion; });
3564+
if (index < 0)
3565+
return n.available(false);
3566+
return n.available(true);
3567+
});
3568+
this.QTGateRegions.sort((a, b) => {
3569+
if (a.available() === b.available())
3570+
return 0;
3571+
if (b.available() && !a.available()) {
3572+
return 1;
3573+
}
3574+
return -1;
35773575
});
3576+
const imapServer = this.emailPool()[0].iMapServerName();
3577+
this.canDoAtEmail(/imap\.mail\.me\.com$/.test(imapServer));
35783578
});
35793579
}
3580+
disconnectClick() {
3581+
this.disconnecting(true);
3582+
socketIo.emit('disconnectClick');
3583+
}
35803584
exit() {
35813585
socketIo.emit('exit');
35823586
}

app/public/scripts/home.ts

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3307,6 +3307,10 @@ module view_layout {
33073307

33083308
})
33093309

3310+
socketIo.on ( 'disconnectClickCallBack', () => {
3311+
this.desconnectCallBack ()
3312+
})
3313+
33103314
socketIo.on ( 'QTGateGatewayConnectRequest', data => {
33113315
this.QTGateGatewayConnectRequestCallBack ( this, data )
33123316
})
@@ -3897,36 +3901,36 @@ module view_layout {
38973901

38983902
public disconnecting = ko.observable ( false )
38993903

3900-
3901-
public disconnectClick () {
3902-
3903-
this.disconnecting ( true )
3904-
socketIo.emit ( 'disconnectClick', () => {
3905-
this.selectedQTGateRegion().showConnectedArea( false )
3906-
this.ConnectGatewayShow ( false )
3907-
this.selectedQTGateRegionCancel ()
3908-
this.disconnecting ( false )
3909-
socketIo.emit ( 'getAvaliableRegion', ( region: string [] ) => {
3910-
this.QTGateRegions().forEach( n => {
3911-
const index = region.findIndex ( nn => { return nn === n.qtRegion })
3912-
if ( index < 0 )
3913-
return n.available( false )
3914-
return n.available ( true )
3915-
})
3916-
this.QTGateRegions.sort (( a, b ) => {
3917-
if ( a.available() === b.available() )
3918-
return 0
3919-
if ( b.available() && !a.available() ) {
3920-
return 1
3921-
}
3922-
return -1
3923-
})
3924-
const imapServer = this.emailPool()[0].iMapServerName ()
3925-
3926-
this.canDoAtEmail ( /imap\.mail\.me\.com$/.test( imapServer ))
3904+
private desconnectCallBack () {
3905+
this.selectedQTGateRegion().showConnectedArea( false )
3906+
this.ConnectGatewayShow ( false )
3907+
this.selectedQTGateRegionCancel ()
3908+
this.disconnecting ( false )
3909+
socketIo.emit ( 'getAvaliableRegion', ( region: string [] ) => {
3910+
this.QTGateRegions().forEach( n => {
3911+
const index = region.findIndex ( nn => { return nn === n.qtRegion })
3912+
if ( index < 0 )
3913+
return n.available( false )
3914+
return n.available ( true )
3915+
})
3916+
this.QTGateRegions.sort (( a, b ) => {
3917+
if ( a.available() === b.available() )
3918+
return 0
3919+
if ( b.available() && !a.available() ) {
3920+
return 1
3921+
}
3922+
return -1
39273923
})
3924+
const imapServer = this.emailPool()[0].iMapServerName ()
3925+
3926+
this.canDoAtEmail ( /imap\.mail\.me\.com$/.test( imapServer ))
39283927
})
39293928
}
3929+
3930+
public disconnectClick () {
3931+
this.disconnecting ( true )
3932+
socketIo.emit ( 'disconnectClick')
3933+
}
39303934

39313935
public newVersionInstallLoading = ko.observable ( false )
39323936
public exit () {

app/server.js

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
361364
class 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

Comments
 (0)