Skip to content

Commit b7a32da

Browse files
fix(run): remove prepareReadyEvent handler correctly on run
`tns run` (and using SK) should remove its handler for prepareControllers' `prepareReadyEvent` handler. However, this does not happend due to two reasons: - we try to remove the handler from runControllers' event, but this handler is attached to `preparController`, so it actually remains and causes multiple issues in long living processes, when CLI is used as a library - the event handler is not cached correctly as we attach its bound version, but cache it without the binding. So you cannot remove it. This causes issues when running on device in Sidekick, closing the current app, open it again and try to livesync a change - we have many handlers for prepareReadyEvent and this causes multiple livesync operations.
1 parent 62aecdd commit b7a32da

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/controllers/run-controller.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class RunController extends EventEmitter implements IRunController {
5151
}
5252

5353
if (!this.prepareReadyEventHandler) {
54-
this.prepareReadyEventHandler = async (data: IFilesChangeEventData) => {
54+
const handler = async (data: IFilesChangeEventData) => {
5555
if (data.hasNativeChanges) {
5656
const platformData = this.$platformsDataService.getPlatformData(data.platform, projectData);
5757
const prepareData = this.$prepareDataService.getPrepareData(liveSyncInfo.projectDir, data.platform, { ...liveSyncInfo, watch: !liveSyncInfo.skipWatcher });
@@ -63,7 +63,9 @@ export class RunController extends EventEmitter implements IRunController {
6363
await this.syncChangedDataOnDevices(data, projectData, liveSyncInfo);
6464
}
6565
};
66-
this.$prepareController.on(PREPARE_READY_EVENT_NAME, this.prepareReadyEventHandler.bind(this));
66+
67+
this.prepareReadyEventHandler = handler.bind(this);
68+
this.$prepareController.on(PREPARE_READY_EVENT_NAME, this.prepareReadyEventHandler);
6769
}
6870

6971
await this.syncInitialDataOnDevices(projectData, liveSyncInfo, deviceDescriptorsForInitialSync);
@@ -113,7 +115,7 @@ export class RunController extends EventEmitter implements IRunController {
113115
liveSyncProcessInfo.deviceDescriptors = [];
114116

115117
if (this.prepareReadyEventHandler) {
116-
this.removeListener(PREPARE_READY_EVENT_NAME, this.prepareReadyEventHandler);
118+
this.$prepareController.removeListener(PREPARE_READY_EVENT_NAME, this.prepareReadyEventHandler);
117119
this.prepareReadyEventHandler = null;
118120
}
119121

@@ -199,7 +201,7 @@ export class RunController extends EventEmitter implements IRunController {
199201
result.didRestart = true;
200202
}
201203
} catch (err) {
202-
this.$logger.trace(`Error while trying to start application ${applicationIdentifier} on device ${liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier}. Error is: ${err.message || err}`);
204+
this.$logger.info(`Error while trying to start application ${applicationIdentifier} on device ${liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier}. Error is: ${err.message || err}`);
203205
const msg = `Unable to start application ${applicationIdentifier} on device ${liveSyncResultInfo.deviceAppData.device.deviceInfo.identifier}. Try starting it manually.`;
204206
this.$logger.warn(msg);
205207

0 commit comments

Comments
 (0)