forked from NativeScript/nativescript-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathandroid-livesync-service.ts
More file actions
112 lines (105 loc) · 3.03 KB
/
android-livesync-service.ts
File metadata and controls
112 lines (105 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { AndroidDeviceLiveSyncService } from "./android-device-livesync-service";
import { AndroidDeviceSocketsLiveSyncService } from "./android-device-livesync-sockets-service";
import { PlatformLiveSyncServiceBase } from "./platform-livesync-service-base";
import { performanceLog } from "../../common/decorators";
import * as semver from "semver";
import * as _ from "lodash";
import { IPlatformsDataService } from "../../definitions/platform";
import { IProjectData } from "../../definitions/project";
import {
IProjectFilesManager,
IFileSystem,
IProjectDir,
} from "../../common/declarations";
import { IInjector } from "../../common/definitions/yok";
import { injector } from "../../common/yok";
import { IOptions } from "../../declarations";
export class AndroidLiveSyncService
extends PlatformLiveSyncServiceBase
implements IPlatformLiveSyncService
{
private static MIN_SOCKETS_LIVESYNC_RUNTIME_VERSION = "4.2.0-2018-07-20-02";
constructor(
protected $platformsDataService: IPlatformsDataService,
protected $projectFilesManager: IProjectFilesManager,
private $injector: IInjector,
$devicePathProvider: IDevicePathProvider,
$fs: IFileSystem,
$logger: ILogger,
$options: IOptions
) {
super(
$fs,
$logger,
$platformsDataService,
$projectFilesManager,
$devicePathProvider,
$options
);
}
protected _getDeviceLiveSyncService(
device: Mobile.IDevice,
data: IProjectDir,
frameworkVersion: string
): INativeScriptDeviceLiveSyncService {
if (
semver.gt(
frameworkVersion,
AndroidLiveSyncService.MIN_SOCKETS_LIVESYNC_RUNTIME_VERSION
)
) {
return this.$injector.resolve<INativeScriptDeviceLiveSyncService>(
AndroidDeviceSocketsLiveSyncService,
{ device, data }
);
}
return this.$injector.resolve<INativeScriptDeviceLiveSyncService>(
AndroidDeviceLiveSyncService,
{ device, data }
);
}
@performanceLog()
public async liveSyncWatchAction(
device: Mobile.IDevice,
liveSyncInfo: ILiveSyncWatchInfo
): Promise<IAndroidLiveSyncResultInfo> {
const liveSyncResult = await super.liveSyncWatchAction(
device,
liveSyncInfo
);
const result = await this.finalizeSync(
device,
liveSyncInfo.projectData,
liveSyncResult
);
return result;
}
@performanceLog()
public async fullSync(
syncInfo: IFullSyncInfo
): Promise<IAndroidLiveSyncResultInfo> {
const liveSyncResult = await super.fullSync(syncInfo);
const result = await this.finalizeSync(
syncInfo.device,
syncInfo.projectData,
liveSyncResult
);
return result;
}
private async finalizeSync(
device: Mobile.IDevice,
projectData: IProjectData,
liveSyncResult: ILiveSyncResultInfo
): Promise<IAndroidLiveSyncResultInfo> {
const liveSyncService = <IAndroidNativeScriptDeviceLiveSyncService>(
this.getDeviceLiveSyncService(device, projectData)
);
const finalizeResult = await liveSyncService.finalizeSync(
liveSyncResult,
projectData
);
const result = _.extend(liveSyncResult, finalizeResult);
return result;
}
}
injector.register("androidLiveSyncService", AndroidLiveSyncService);