Skip to content

Commit 7c4c417

Browse files
committed
iOS implementation refactoring
1 parent 76094c1 commit 7c4c417

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed

package.json

+8-10
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
"runtime": "node",
106106
"initialConfigurations": [
107107
{
108-
"name": "Launch on iOS",
108+
"name": "Sync on iOS",
109109
"type": "nativescript",
110110
"platform": "ios",
111111
"request": "launch",
@@ -116,7 +116,7 @@
116116
"rebuild": false
117117
},
118118
{
119-
"name": "Rebuild and launch on iOS",
119+
"name": "Launch on iOS",
120120
"type": "nativescript",
121121
"platform": "ios",
122122
"request": "launch",
@@ -127,18 +127,17 @@
127127
"rebuild": true
128128
},
129129
{
130-
"name": "Rebuild and attach on iOS",
130+
"name": "Attach on iOS",
131131
"type": "nativescript",
132132
"platform": "ios",
133133
"request": "attach",
134134
"appRoot": "${workspaceRoot}",
135135
"sourceMaps": true,
136136
"diagnosticLogging": false,
137-
"emulator": false,
138-
"rebuild": true
137+
"emulator": false
139138
},
140139
{
141-
"name": "Launch on Android",
140+
"name": "Sync on Android",
142141
"type": "nativescript",
143142
"platform": "android",
144143
"request": "launch",
@@ -149,7 +148,7 @@
149148
"rebuild": false
150149
},
151150
{
152-
"name": "Rebuild and launch on Android",
151+
"name": "Launch on Android",
153152
"type": "nativescript",
154153
"platform": "android",
155154
"request": "launch",
@@ -160,15 +159,14 @@
160159
"rebuild": true
161160
},
162161
{
163-
"name": "Rebuild and attach on Android",
162+
"name": "Attach on Android",
164163
"type": "nativescript",
165164
"platform": "android",
166165
"request": "attach",
167166
"appRoot": "${workspaceRoot}",
168167
"sourceMaps": true,
169168
"diagnosticLogging": false,
170-
"emulator": false,
171-
"rebuild": true
169+
"emulator": false
172170
}
173171
],
174172
"configurationAttributes": {

src/debug-adapter/webKitAdapterInterfaces.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export interface IAttachRequestArgs extends DebugProtocol.AttachRequestArguments
2424
request: string;
2525
tnsArgs?: string[];
2626
tnsOutput?: string;
27-
rebuild?: boolean;
2827
}
2928

3029
export interface ISetBreakpointsArgs extends DebugProtocol.SetBreakpointsArguments {

src/services/NsCliService.ts

+31-28
Original file line numberDiff line numberDiff line change
@@ -137,43 +137,51 @@ export class IosProject extends NSProject {
137137
return Promise.reject('iOS platform is supported only on OS X.');
138138
}
139139

140+
let rebuild = (args.request == "launch") ? (args as ILaunchRequestArgs).rebuild : true;
140141
// build command to execute
141142
let command = new CommandBuilder()
142143
.appendParam("debug")
143144
.appendParam(this.platform())
144145
.appendParamIf("--emulator", args.emulator)
145146
.appendParamIf("--start", args.request === "attach")
146147
.appendParamIf("--debug-brk", args.request === "launch")
147-
.appendParamIf("--no-rebuild", !args.rebuild)
148+
.appendParamIf("--no-rebuild", !rebuild)
148149
.appendParam("--no-client")
149150
.appendParams(args.tnsArgs)
150151
.build();
151152

152153
let socketPathPrefix = 'socket-file-location: ';
153154
let socketPathPattern: RegExp = new RegExp(socketPathPrefix + '.*\.sock');
154-
let readyToConnect: boolean = false;
155+
156+
let isSocketOpened = (cliOutput: string): string => {
157+
let matches: RegExpMatchArray = cliOutput.match(socketPathPattern);
158+
if(matches && matches.length > 0) {
159+
return matches[0].substr(socketPathPrefix.length);
160+
}
161+
return null;
162+
};
163+
164+
let isAppSynced = (cliOutput: string) => {
165+
return cliOutput.indexOf('Successfully synced application') > -1;
166+
};
155167

156168
return new Promise<string>((resolve, reject) => {
157169
// run NativeScript CLI command
158170
let child: ChildProcess = this.spawnProcess(command.path, command.args, args.tnsOutput);
159-
let synced = false;
171+
172+
let appSynced = false;
173+
let socketPath: string = null;
160174

161175
child.stdout.on('data', (data) => {
162-
let strData: string = data.toString();
163-
this.emit('TNS.outputMessage', strData, 'log');
164-
this.writeToTnsOutputFile(strData);
165-
if (!synced && !args.rebuild && strData.indexOf('Successfully synced application') > -1) {
166-
synced = true;
167-
//wait a little before trying to connect, this gives a changes for adb to be able to connect to the debug socket
168-
setTimeout(() => {
169-
resolve();
170-
}, 500);
171-
} else if(!readyToConnect) {
172-
let matches: RegExpMatchArray = strData.match(socketPathPattern);
173-
if(matches && matches.length > 0) {
174-
readyToConnect = true;
175-
resolve(matches[0].substr(socketPathPrefix.length));
176-
}
176+
let cliOutput: string = data.toString();
177+
this.emit('TNS.outputMessage', cliOutput, 'log');
178+
this.writeToTnsOutputFile(cliOutput);
179+
180+
socketPath = socketPath || isSocketOpened(cliOutput);
181+
appSynced = rebuild ? false : (appSynced || isAppSynced(cliOutput));
182+
183+
if ((rebuild && socketPath) || (!rebuild && socketPath && appSynced)) {
184+
resolve(socketPath);
177185
}
178186
});
179187

@@ -183,13 +191,7 @@ export class IosProject extends NSProject {
183191
});
184192

185193
child.on('close', (code, signal) => {
186-
if (!args.rebuild) {
187-
setTimeout(() => {
188-
reject("The debug process exited unexpectedly code:" + code);
189-
}, 3000);
190-
} else {
191-
reject("The debug process exited unexpectedly code:" + code);
192-
}
194+
reject("The debug process exited unexpectedly code:" + code);
193195
});
194196
});
195197
}
@@ -221,11 +223,12 @@ export class AndroidProject extends NSProject {
221223
return Promise.resolve(child);
222224
}
223225

224-
public debug(args: IAttachRequestArgs | ILaunchRequestArgs): Promise<void> {
225-
if (args.request === "attach") {
226+
public debug(params: IAttachRequestArgs | ILaunchRequestArgs): Promise<void> {
227+
if (params.request === "attach") {
226228
return Promise.resolve<void>();
227229
}
228-
else if (args.request === "launch") {
230+
else if (params.request === "launch") {
231+
let args: ILaunchRequestArgs = params as ILaunchRequestArgs;
229232
let that = this;
230233
let launched = false;
231234

0 commit comments

Comments
 (0)