Skip to content

Commit 45ea8ba

Browse files
DimitarTachevDimitarTachev
authored andcommitted
fix: stop forcing app restart on debug
1 parent cdd6b0b commit 45ea8ba

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

lib/services/livesync/livesync-service.ts

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
170170
notification: msg
171171
});
172172
}
173+
174+
this.handleDeveloperDiskImageError(err, liveSyncResultInfo, projectData, debugOpts, outputPath);
173175
}
174176

175177
this.emitLivesyncEvent(LiveSyncEvents.liveSyncExecuted, {
@@ -183,41 +185,26 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
183185

184186
private async refreshApplicationWithDebug(projectData: IProjectData, liveSyncResultInfo: ILiveSyncResultInfo, debugOptions: IDebugOptions, outputPath?: string): Promise<IDebugInformation> {
185187
const deviceAppData = liveSyncResultInfo.deviceAppData;
188+
debugOptions = debugOptions || {};
186189

187190
const deviceIdentifier = liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier;
188191
await this.$debugService.debugStop(deviceIdentifier);
189192
this.emit(DEBUGGER_DETACHED_EVENT_NAME, { deviceIdentifier });
190193

191-
const applicationId = deviceAppData.appIdentifier;
192-
const attachDebuggerOptions: IAttachDebuggerOptions = {
193-
platform: liveSyncResultInfo.deviceAppData.device.deviceInfo.platform,
194-
isEmulator: liveSyncResultInfo.deviceAppData.device.isEmulator,
195-
projectDir: projectData.projectDir,
196-
deviceIdentifier,
197-
debugOptions,
198-
outputPath
199-
};
200194

201-
try {
202-
await deviceAppData.device.applicationManager.stopApplication({ appId: applicationId, projectName: projectData.projectName });
203-
// Now that we've stopped the application we know it isn't started, so set debugOptions.start to false
204-
// so that it doesn't default to true in attachDebugger method
205-
debugOptions = debugOptions || {};
206-
debugOptions.start = false;
207-
} catch (err) {
208-
this.$logger.trace("Could not stop application during debug livesync. Will try to restart app instead.", err);
209-
if ((err.message || err) === "Could not find developer disk image") {
210-
// Set isFullSync here to true because we are refreshing with debugger
211-
// We want to force a restart instead of accidentally performing LiveEdit or FastSync
212-
liveSyncResultInfo.isFullSync = true;
213-
await this.refreshApplicationWithoutDebug(projectData, liveSyncResultInfo, debugOptions, outputPath, { shouldSkipEmitLiveSyncNotification: true });
214-
this.emit(USER_INTERACTION_NEEDED_EVENT_NAME, attachDebuggerOptions);
215-
return;
216-
} else {
217-
throw err;
195+
if (debugOptions.debugBrk) {
196+
const applicationId = deviceAppData.appIdentifier;
197+
try {
198+
await deviceAppData.device.applicationManager.stopApplication({ appId: applicationId, projectName: projectData.projectName });
199+
} catch (err) {
200+
this.$logger.trace("Could not stop application during debug livesync. Will try to restart app instead.", err);
201+
this.handleDeveloperDiskImageError(err, liveSyncResultInfo, projectData, debugOptions, outputPath);
218202
}
203+
} else {
204+
await this.refreshApplicationWithoutDebug(projectData, liveSyncResultInfo, debugOptions, outputPath, { shouldSkipEmitLiveSyncNotification: true });
219205
}
220206

207+
debugOptions.start = !debugOptions.debugBrk;
221208
const deviceOption = {
222209
deviceIdentifier: liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier,
223210
debugOptions: debugOptions,
@@ -226,6 +213,21 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
226213
return this.enableDebuggingCoreWithoutWaitingCurrentAction(deviceOption, { projectDir: projectData.projectDir });
227214
}
228215

216+
private handleDeveloperDiskImageError(err: any, liveSyncResultInfo: ILiveSyncResultInfo, projectData: IProjectData, debugOpts: IDebugOptions, outputPath: string) {
217+
if ((err.message || err) === "Could not find developer disk image") {
218+
const deviceIdentifier = liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier;
219+
const attachDebuggerOptions: IAttachDebuggerOptions = {
220+
platform: liveSyncResultInfo.deviceAppData.device.deviceInfo.platform,
221+
isEmulator: liveSyncResultInfo.deviceAppData.device.isEmulator,
222+
projectDir: projectData.projectDir,
223+
deviceIdentifier,
224+
debugOptions: debugOpts,
225+
outputPath
226+
};
227+
this.emit(USER_INTERACTION_NEEDED_EVENT_NAME, attachDebuggerOptions);
228+
}
229+
}
230+
229231
public async attachDebugger(settings: IAttachDebuggerOptions): Promise<IDebugInformation> {
230232
// Default values
231233
if (settings.debugOptions) {

0 commit comments

Comments
 (0)