Skip to content

Commit b720651

Browse files
fix: livesync should stop when all devices are disconnected
Whenever all devices/emulators/simulators that we are using for LiveSync operation are disconnected or we are unable to sync changes on them, the command (`tns debug`, `tns run`...) should exit. This is not happening currently due to the setIntervals and iOS device detection that happens and does not stop when the devices are disconnected. So workaround the problem by handling the liveSyncStopped event for the livesync related commands. In case we receive liveSyncStopped for all devices that we've been using for LiveSync action, call process.exit. Use non-zero exit code for this case, as if we receive liveSyncStopped event, we've either received error for particular device or it has been stopped. For both cases this is not a correct behavior for LiveSync.
1 parent d50b5d4 commit b720651

File tree

6 files changed

+668
-643
lines changed

6 files changed

+668
-643
lines changed

lib/common/declarations.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,8 @@ declare const enum ErrorCodes {
596596
KARMA_FAIL = 130,
597597
UNHANDLED_REJECTION_FAILURE = 131,
598598
DELETED_KILL_FILE = 132,
599-
TESTS_INIT_REQUIRED = 133
599+
TESTS_INIT_REQUIRED = 133,
600+
ALL_DEVICES_DISCONNECTED = 134
600601
}
601602

602603
interface IFutureDispatcher {

lib/constants.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require("colors");
2+
import { PreviewAppLiveSyncEvents } from "./services/livesync/playground/preview-app-constants";
23

34
export const APP_FOLDER_NAME = "app";
45
export const APP_RESOURCES_FOLDER_NAME = "App_Resources";
@@ -269,3 +270,13 @@ export class AndroidAppBundleMessages {
269270
public static ANDROID_APP_BUNDLE_DOCS_MESSAGE = "What is Android App Bundle: https://docs.nativescript.org/tooling/publishing/android-app-bundle";
270271
public static ANDROID_APP_BUNDLE_PUBLISH_DOCS_MESSAGE = "How to use Android App Bundle for publishing: https://docs.nativescript.org/tooling/publishing/publishing-android-apps#android-app-bundle";
271272
}
273+
274+
export const LiveSyncEvents = {
275+
liveSyncStopped: "liveSyncStopped",
276+
// In case we name it error, EventEmitter expects instance of Error to be raised and will also raise uncaught exception in case there's no handler
277+
liveSyncError: "liveSyncError",
278+
previewAppLiveSyncError: PreviewAppLiveSyncEvents.PREVIEW_APP_LIVE_SYNC_ERROR,
279+
liveSyncExecuted: "liveSyncExecuted",
280+
liveSyncStarted: "liveSyncStarted",
281+
liveSyncNotification: "notify"
282+
};

0 commit comments

Comments
 (0)