Skip to content

Commit

Permalink
Merge pull request #4459 from NativeScript/vladimirov/fix-debug-sidekick
Browse files Browse the repository at this point in the history
fix: raise debuggerAttached only if app is restarted
  • Loading branch information
rosen-vladimirov authored Mar 21, 2019
2 parents a2c64f9 + 464cf5c commit 871b343
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/definitions/livesync.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ interface IPlatformLiveSyncService {
shouldRestart(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise<boolean>;
getDeviceLiveSyncService(device: Mobile.IDevice, projectData: IProjectData): INativeScriptDeviceLiveSyncService;
}
interface IRefreshApplicationInfo {
didRefresh: boolean;
interface IRestartApplicationInfo {
didRestart: boolean;
}

interface INativeScriptDeviceLiveSyncService {
Expand Down
12 changes: 6 additions & 6 deletions lib/services/livesync/livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,30 +145,30 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
}

@performanceLog()
private async refreshApplication(projectData: IProjectData, liveSyncResultInfo: ILiveSyncResultInfo, debugOpts?: IDebugOptions, outputPath?: string): Promise<IRefreshApplicationInfo | IDebugInformation> {
private async refreshApplication(projectData: IProjectData, liveSyncResultInfo: ILiveSyncResultInfo, debugOpts?: IDebugOptions, outputPath?: string): Promise<IRestartApplicationInfo | IDebugInformation> {
const deviceDescriptor = this.getDeviceDescriptor(liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier, projectData.projectDir);

return deviceDescriptor && deviceDescriptor.debugggingEnabled ?
this.refreshApplicationWithDebug(projectData, liveSyncResultInfo, debugOpts, outputPath) :
this.refreshApplicationWithoutDebug(projectData, liveSyncResultInfo, debugOpts, outputPath);
}

private async refreshApplicationWithoutDebug(projectData: IProjectData, liveSyncResultInfo: ILiveSyncResultInfo, debugOpts?: IDebugOptions, outputPath?: string, settings?: IRefreshApplicationSettings): Promise<IRefreshApplicationInfo> {
const result = { didRefresh: false };
private async refreshApplicationWithoutDebug(projectData: IProjectData, liveSyncResultInfo: ILiveSyncResultInfo, debugOpts?: IDebugOptions, outputPath?: string, settings?: IRefreshApplicationSettings): Promise<IRestartApplicationInfo> {
const result = { didRestart: false };
const platform = liveSyncResultInfo.deviceAppData.platform;
const platformLiveSyncService = this.getLiveSyncService(platform);
const applicationIdentifier = projectData.projectIdentifiers[platform.toLowerCase()];
try {
let shouldRestart = await platformLiveSyncService.shouldRestart(projectData, liveSyncResultInfo);
if (!shouldRestart) {
result.didRefresh = await platformLiveSyncService.tryRefreshApplication(projectData, liveSyncResultInfo);
shouldRestart = !result.didRefresh;
shouldRestart = !await platformLiveSyncService.tryRefreshApplication(projectData, liveSyncResultInfo);
}

if (shouldRestart) {
const deviceIdentifier = liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier;
this.emit(DEBUGGER_DETACHED_EVENT_NAME, { deviceIdentifier });
await platformLiveSyncService.restartApplication(projectData, liveSyncResultInfo);
result.didRestart = true;
}
} catch (err) {
this.$logger.info(`Error while trying to start application ${applicationIdentifier} on device ${liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier}. Error is: ${err.message || err}`);
Expand Down Expand Up @@ -212,7 +212,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
// if we try to send the launch request, the debugger port will not be printed and the command will timeout
debugOptions.start = !debugOptions.debugBrk;

debugOptions.forceDebuggerAttachedEvent = !refreshInfo.didRefresh;
debugOptions.forceDebuggerAttachedEvent = refreshInfo.didRestart;
const deviceOption = {
deviceIdentifier: liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier,
debugOptions: debugOptions,
Expand Down

0 comments on commit 871b343

Please sign in to comment.