Skip to content

Commit 5d79aeb

Browse files
fix: hmr for iOS does not work on Windows
With `tns cloud run ...` command (or with NativeScript Sidekick), you can use LiveSync on iOS device from Windows machine (with application built in the cloud). However, this approach does not work when the iOS device does not have developer disk image mounted (i.e. it has not been used on macOS). The problem is that during establishment of socket connection, CLI tries to start the application. This is a precautions for cases when the application had crashed. In most of the cases when we reach to this code, the application is already up and running. However, calling `startApplication` fails on Windows and we never setup the socket connection. So the HMR does not work at all. Fix this by adding a try-catch block around starting of application when trying to setup the socket connection.
1 parent c7a762e commit 5d79aeb

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

lib/common/mobile/ios/device/ios-device.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class IOSDevice extends IOSDeviceBase {
1818
private $injector: IInjector,
1919
protected $iOSDebuggerPortService: IIOSDebuggerPortService,
2020
protected $deviceLogProvider: Mobile.IDeviceLogProvider,
21+
protected $logger: ILogger,
2122
protected $lockService: ILockService,
2223
private $iOSSocketRequestExecutor: IiOSSocketRequestExecutor,
2324
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,

lib/common/mobile/ios/ios-device-base.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export abstract class IOSDeviceBase implements Mobile.IiOSDevice {
77
protected abstract $deviceLogProvider: Mobile.IDeviceLogProvider;
88
protected abstract $iOSDebuggerPortService: IIOSDebuggerPortService;
99
protected abstract $lockService: ILockService;
10+
protected abstract $logger: ILogger;
1011
abstract deviceInfo: Mobile.IDeviceInfo;
1112
abstract applicationManager: Mobile.IDeviceApplicationManager;
1213
abstract fileSystem: Mobile.IDeviceFileSystem;
@@ -22,8 +23,12 @@ export abstract class IOSDeviceBase implements Mobile.IiOSDevice {
2223
}
2324

2425
await this.attachToDebuggerFoundEvent(appId, projectName);
25-
if (ensureAppStarted) {
26-
await this.applicationManager.startApplication({ appId, projectName });
26+
try {
27+
if (ensureAppStarted) {
28+
await this.applicationManager.startApplication({ appId, projectName });
29+
}
30+
} catch (err) {
31+
this.$logger.trace(`Unable to start application ${appId} on device ${this.deviceInfo.identifier} in getDebugSocket method. Error is: ${err}`);
2732
}
2833

2934
this.cachedSockets[appId] = await this.getDebugSocketCore(appId);

lib/common/mobile/ios/simulator/ios-simulator-device.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class IOSSimulator extends IOSDeviceBase implements Mobile.IiOSDevice {
2222
private $iOSEmulatorServices: Mobile.IiOSSimulatorService,
2323
private $iOSNotification: IiOSNotification,
2424
private $iOSSimulatorLogProvider: Mobile.IiOSSimulatorLogProvider,
25-
private $logger: ILogger) {
25+
protected $logger: ILogger) {
2626
super();
2727
this.applicationManager = this.$injector.resolve(applicationManagerPath.IOSSimulatorApplicationManager, { iosSim: this.$iOSSimResolver.iOSSim, device: this });
2828
this.fileSystem = this.$injector.resolve(fileSystemPath.IOSSimulatorFileSystem, { iosSim: this.$iOSSimResolver.iOSSim });

0 commit comments

Comments
 (0)