@@ -6,10 +6,12 @@ import { LiveSyncPaths } from "../../common/constants";
6
6
import { AndroidLivesyncTool } from "./android-livesync-tool" ;
7
7
import * as path from "path" ;
8
8
import * as temp from "temp" ;
9
+ import * as semver from "semver" ;
9
10
10
11
export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBase implements IAndroidNativeScriptDeviceLiveSyncService , INativeScriptDeviceLiveSyncService {
11
12
private livesyncTool : IAndroidLivesyncTool ;
12
13
private static STATUS_UPDATE_INTERVAL = 10000 ;
14
+ private static MINIMAL_VERSION_LONG_LIVING_CONNECTION = "0.2.0" ;
13
15
14
16
constructor (
15
17
private data : IProjectData ,
@@ -20,19 +22,18 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
20
22
protected device : Mobile . IAndroidDevice ,
21
23
private $options : ICommonOptions ,
22
24
private $processService : IProcessService ,
23
- private $fs : IFileSystem ) {
25
+ private $fs : IFileSystem ,
26
+ private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ) {
24
27
super ( $platformsData , device ) ;
25
28
this . livesyncTool = this . $injector . resolve ( AndroidLivesyncTool ) ;
26
29
}
27
30
28
31
public async beforeLiveSyncAction ( deviceAppData : Mobile . IDeviceAppData ) : Promise < void > {
29
- const platformData = this . $platformsData . getPlatformData ( deviceAppData . platform , this . data ) ;
30
- const projectFilesPath = path . join ( platformData . appDestinationDirectoryPath , APP_FOLDER_NAME ) ;
31
32
const pathToLiveSyncFile = temp . path ( { prefix : "livesync" } ) ;
32
33
this . $fs . writeFile ( pathToLiveSyncFile , "" ) ;
33
34
await this . device . fileSystem . putFile ( pathToLiveSyncFile , this . getPathToLiveSyncFileOnDevice ( deviceAppData . appIdentifier ) , deviceAppData . appIdentifier ) ;
34
35
await this . device . applicationManager . startApplication ( { appId : deviceAppData . appIdentifier , projectName : this . data . projectName , justLaunch : true } ) ;
35
- await this . connectLivesyncTool ( projectFilesPath , this . data . projectId ) ;
36
+ await this . connectLivesyncTool ( this . data . projectId ) ;
36
37
}
37
38
38
39
private getPathToLiveSyncFileOnDevice ( appIdentifier : string ) : string {
@@ -42,8 +43,11 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
42
43
public async finalizeSync ( liveSyncInfo : ILiveSyncResultInfo , projectData : IProjectData ) : Promise < IAndroidLivesyncSyncOperationResult > {
43
44
try {
44
45
const result = await this . doSync ( liveSyncInfo , projectData ) ;
46
+ if ( ! semver . gte ( this . livesyncTool . protocolVersion , AndroidDeviceSocketsLiveSyncService . MINIMAL_VERSION_LONG_LIVING_CONNECTION ) ) {
47
+ this . livesyncTool . end ( ) ;
48
+ }
45
49
return result ;
46
- } finally {
50
+ } catch ( e ) {
47
51
this . livesyncTool . end ( ) ;
48
52
}
49
53
}
@@ -85,6 +89,13 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
85
89
const canExecuteFastSync = ! liveSyncInfo . isFullSync && this . canExecuteFastSyncForPaths ( liveSyncInfo . modifiedFilesData , projectData , this . device . deviceInfo . platform ) ;
86
90
if ( ! canExecuteFastSync || ! liveSyncInfo . didRefresh ) {
87
91
await this . device . applicationManager . restartApplication ( { appId : liveSyncInfo . deviceAppData . appIdentifier , projectName : projectData . projectName } ) ;
92
+ if ( this . livesyncTool . protocolVersion && semver . gte ( this . livesyncTool . protocolVersion , AndroidDeviceSocketsLiveSyncService . MINIMAL_VERSION_LONG_LIVING_CONNECTION ) ) {
93
+ try {
94
+ await this . connectLivesyncTool ( liveSyncInfo . deviceAppData . appIdentifier ) ;
95
+ } catch ( e ) {
96
+ this . $logger . trace ( "Failed to connect after app restart." ) ;
97
+ }
98
+ }
88
99
}
89
100
}
90
101
@@ -143,12 +154,16 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
143
154
return transferredLocalToDevicePaths ;
144
155
}
145
156
146
- private async connectLivesyncTool ( projectFilesPath : string , appIdentifier : string ) {
147
- await this . livesyncTool . connect ( {
148
- appIdentifier,
149
- deviceIdentifier : this . device . deviceInfo . identifier ,
150
- appPlatformsPath : projectFilesPath
151
- } ) ;
157
+ private async connectLivesyncTool ( appIdentifier : string ) {
158
+ const platformData = this . $platformsData . getPlatformData ( this . $devicePlatformsConstants . Android , this . data ) ;
159
+ const projectFilesPath = path . join ( platformData . appDestinationDirectoryPath , APP_FOLDER_NAME ) ;
160
+ if ( ! this . livesyncTool . hasConnection ( ) ) {
161
+ await this . livesyncTool . connect ( {
162
+ appIdentifier,
163
+ deviceIdentifier : this . device . deviceInfo . identifier ,
164
+ appPlatformsPath : projectFilesPath
165
+ } ) ;
166
+ }
152
167
}
153
168
154
169
public getDeviceHashService ( appIdentifier : string ) : Mobile . IAndroidDeviceHashService {
0 commit comments