Skip to content

Commit

Permalink
Merge pull request #127 from rolldone/working
Browse files Browse the repository at this point in the history
Improvement
  • Loading branch information
rolldone authored Jul 20, 2022
2 parents 86968e4 + a9b6aae commit bdef05f
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 31 deletions.
6 changes: 5 additions & 1 deletion src/app/devsync/compute/Watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,11 @@ export default class Watcher {
}

async close(): Promise<void> {
this.uploader.client.end();
try {
this.uploader.client.end();
} catch (ex) {
console.log("this.uploader.client.end - ex :: ", ex);
}
for (var a = 0; a < this._unwatch.length; a++) {
await this._unwatch[a].close();
}
Expand Down
56 changes: 41 additions & 15 deletions src/app/devsync/services/DevSyncService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export const COMMAND_TARGET = {


var cache_command: Array<string> = [];
var questions_command = null;
var _readLine: ReadLine = null;

const DevSyncService = BaseService.extend<DevSyncServiceInterface>({
returnConfig: function (cli) {
Expand Down Expand Up @@ -368,14 +370,14 @@ const DevSyncService = BaseService.extend<DevSyncServiceInterface>({
});

/* Define readline nodejs for listen CTRL + R */
this._readLine = rl.createInterface({
_readLine = rl.createInterface({
input: process.stdin,
output: process.stdout,
terminal: true
});


let questions_command = [
questions_command = [
{
type: "rawlist",
name: "remote",
Expand Down Expand Up @@ -408,6 +410,10 @@ const DevSyncService = BaseService.extend<DevSyncServiceInterface>({
}
]

masterData.setOnListener("listen_from_outside", async (val) => {
this.construct(this._cli);
})

let remoteFuncKeypress = async (key: any, data: any) => {
let total_tab = 9;
switch (data.sequence) {
Expand All @@ -432,7 +438,7 @@ const DevSyncService = BaseService.extend<DevSyncServiceInterface>({
this._actionMode = "devsync";
this.watcher.actionMode = this._actionMode;

this._readLine = rl.createInterface({
_readLine = rl.createInterface({
input: process.stdin,
output: process.stdout,
// terminal: true
Expand All @@ -442,7 +448,10 @@ const DevSyncService = BaseService.extend<DevSyncServiceInterface>({
break;
case '\u001b2':
console.clear();
this._readLine.close();
try {
_readLine.close();
_readLine = null;
} catch (ex) { }
process.stdin.removeListener('keypress', remoteFuncKeypress);
process.stdout.write(chalk.green('Console | ') + 'Start Console' + '\r');
for (var i = 0; i < total_tab; i++) {
Expand Down Expand Up @@ -473,7 +482,10 @@ const DevSyncService = BaseService.extend<DevSyncServiceInterface>({

for (var i = 0; i < total_tab; i++) {
if (data.sequence == '\u001b' + (i + 3)) {
this._readLine.close();
try {
_readLine.close();
_readLine = null;
} catch (ex) { }
process.stdin.removeListener('keypress', remoteFuncKeypress);
console.clear();
this.uploader.setConsoleAction("pending first");
Expand Down Expand Up @@ -614,28 +626,42 @@ const DevSyncService = BaseService.extend<DevSyncServiceInterface>({
case '\x12':
this._is_stop = true;
let stop = async () => {
this._readLine.close();
this._readLine.removeAllListeners();
try {
_readLine.close();
_readLine = null;
} catch (ex) { }
_startWatchingWithTimeOut(true);
syncPull.stopSubmitWatch();
syncPull = null;

try {
if (syncPull != null) {
syncPull.stopSubmitWatch();
}
syncPull = null;
} catch (ex) {
console.log("syncPull - ex :: ", ex);
}

await this.watcher.close();
this.watcher = null;

/* Restart the syncronize */
this.uploader.clientClose();
this.uploader.onListener('RESTART', {});
this.uploader = null;
try {
if (this.uploader != null) {
this.uploader.clientClose();
this.uploader.onListener('RESTART', {});
}
this.uploader = null;
} catch (ex) {
console.log("this.uploader - ex :: ", ex);
}

process.stdin.off('keypress', remoteFuncKeypress);
process.stdin.removeAllListeners('keypress');
this.task.done();
console.clear();
process.stdout.write(chalk.green('Remote | ') + 'Restarting...' + '\r');

setTimeout(() => {
this.construct(this._cli);
}, 2000);
masterData.saveData("listen_from_outside", {});
}
var closeRemote = () => {
if (this._currentConf.devsync.script.remote.on_stop != "" && this._currentConf.devsync.script.remote.on_stop != null) {
Expand Down
45 changes: 30 additions & 15 deletions src/app/devsync2/services/DevSync2Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export const COMMAND_TARGET = {
}

var cache_command: Array<string> = [];
var questions_command = null;
var _readLine: ReadLine = null;

const DevRsyncService = BaseService.extend<DevRsyncServiceInterface>({

Expand Down Expand Up @@ -467,17 +469,17 @@ const DevRsyncService = BaseService.extend<DevRsyncServiceInterface>({
}
});
/* Define readline nodejs for listen CTRL + R */
this._readLine = rl.createInterface({
_readLine = rl.createInterface({
input: process.stdin,
output: process.stdout,
// terminal: true
});

this._readLine.on('line', function (line) { }).on('close', function () {
_readLine.on('line', function (line) { }).on('close', function () {
console.log("Close The Main Readline");
});

let questions_command = [
questions_command = [
{
type: "rawlist",
name: "remote",
Expand Down Expand Up @@ -510,6 +512,10 @@ const DevRsyncService = BaseService.extend<DevRsyncServiceInterface>({
}
]

masterData.setOnListener("listen_from_outside", async (val) => {
this.construct(this._cli);
})

/* Register new keypress */
var remoteFuncKeypress = async (key: any, data: any) => {
let total_tab = 9;
Expand Down Expand Up @@ -537,19 +543,23 @@ const DevRsyncService = BaseService.extend<DevRsyncServiceInterface>({
this._actionMode = "devsync";
this.watcher.actionMode = this._actionMode;

this._readLine.close();
process.stdin.removeListener("keypress", remoteFuncKeypress);
// _readLine.close();

this._readLine = rl.createInterface({
process.stdin.removeListener("keypress", remoteFuncKeypress);
_readLine = rl.createInterface({
input: process.stdin,
output: process.stdout,
// terminal: true
});
process.stdin.on('keypress', remoteFuncKeypress);

process.stdin.on("keypress", remoteFuncKeypress)
break;
case '\u001b2':
console.clear();
this._readLine.close();
try{
_readLine.close();
_readLine = null;
}catch(ex){}
process.stdin.removeListener('keypress', remoteFuncKeypress);
process.stdout.write(chalk.green('Console | ') + 'Start Console' + '\r');
for (var i = 0; i < total_tab; i++) {
Expand All @@ -576,8 +586,12 @@ const DevRsyncService = BaseService.extend<DevRsyncServiceInterface>({
}
for (var i = 0; i < total_tab; i++) {
if (data.sequence == '\u001b' + (i + 3)) {
this._readLine.close();
process.stdin.removeListener('keypress', remoteFuncKeypress);
try{
_readLine.close();
_readLine = null;
}catch(ex){}
process.stdin.removeAllListeners('keypress');
// process.stdin.removeListener('keypress', remoteFuncKeypress);
console.clear();
this.uploader.setConsoleAction("pending first");
let inin = i;
Expand Down Expand Up @@ -714,8 +728,8 @@ const DevRsyncService = BaseService.extend<DevRsyncServiceInterface>({
case '\x12':
this._is_stop = true;
let stop = async () => {
this._readLine.close();
this._readLine.removeAllListeners();
_readLine.close();
_readLine.removeAllListeners();

/* Stop httpEvent */
if (this._httpEvent != null) {
Expand All @@ -731,6 +745,7 @@ const DevRsyncService = BaseService.extend<DevRsyncServiceInterface>({
}

process.stdin.off('keypress', remoteFuncKeypress);
process.stdin.removeAllListeners('keypress');
await this.watcher.close();
this.watcher = null;

Expand All @@ -745,9 +760,9 @@ const DevRsyncService = BaseService.extend<DevRsyncServiceInterface>({
this.task.done();
console.clear();
process.stdout.write(chalk.green('Remote | ') + 'Restarting...' + '\r');
setTimeout(() => {
this.construct(this._cli);
}, 2000);
masterData.saveData("listen_from_outside", {});
// setTimeout(() => {
// }, 2000);
}
var closeRemote = () => {
if (this._currentConf.devsync.script.remote.on_stop != "" && this._currentConf.devsync.script.remote.on_stop != null) {
Expand Down

0 comments on commit bdef05f

Please sign in to comment.