Skip to content

fix: wait for '# NativeScript Debugger started #' only on debug-brkas now we don't restart the app in the other cases #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/project/androidProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class AndroidProject extends Project {
const debugProcess: ChildProcess = super.executeDebugCommand(args);
const tnsOutputEventEmitter = new EventEmitter();

this.configureReadyEvent(debugProcess.stdout, tnsOutputEventEmitter, true);
this.configureReadyEvent(debugProcess.stdout, tnsOutputEventEmitter, false);

return { tnsProcess: debugProcess, tnsOutputEventEmitter };
}
Expand All @@ -38,25 +38,23 @@ export class AndroidProject extends Project {
const debugProcess: ChildProcess = super.executeDebugCommand(args);
const tnsOutputEventEmitter: EventEmitter = new EventEmitter();

this.configureReadyEvent(debugProcess.stdout, tnsOutputEventEmitter, false);
this.configureReadyEvent(debugProcess.stdout, tnsOutputEventEmitter, args.indexOf('--debug-brk') > -1);

return { tnsProcess: debugProcess, tnsOutputEventEmitter };
}

protected configureReadyEvent(readableStream: stream.Readable, eventEmitter: EventEmitter, attach?: boolean): void {
protected configureReadyEvent(readableStream: stream.Readable, eventEmitter: EventEmitter, debugBrk?: boolean): void {
super.configureReadyEvent(readableStream, eventEmitter);

let debugPort = null;

new scanner.StringMatchingScanner(readableStream).onEveryMatch(new RegExp('device: .* debug port: [0-9]+'), (match: scanner.IMatchFound) => {
// device: {device-name} debug port: {debug-port}
debugPort = parseInt((match.matches[0] as string).match('(?:debug port: )([\\d]{5})')[1], 10);
if (attach) {
// wait a little before trying to connect, this gives a chance for adb to be able to connect to the debug socket
if (!debugBrk) {
setTimeout(() => { eventEmitter.emit('readyForConnection', debugPort); }, 1000);
}
});
if (!attach) {
if (debugBrk) {
new scanner.StringMatchingScanner(readableStream).onEveryMatch('# NativeScript Debugger started #', (match: scanner.IMatchFound) => {
// wait a little before trying to connect, this gives a chance for adb to be able to connect to the debug socket
setTimeout(() => { eventEmitter.emit('readyForConnection', debugPort); }, 1000);
Expand Down