|
1 |
| -import { DeviceAndroidDebugBridge } from "../../common/mobile/android/device-android-debug-bridge"; |
2 |
| -import { AndroidDeviceHashService } from "../../common/mobile/android/android-device-hash-service"; |
3 |
| -import { DeviceLiveSyncServiceBase } from "./device-livesync-service-base"; |
| 1 | +import { AndroidDeviceLiveSyncServiceBase } from "./android-device-livesync-service-base"; |
4 | 2 | import { APP_FOLDER_NAME } from "../../constants";
|
5 | 3 | import { LiveSyncPaths } from "../../common/constants";
|
6 | 4 | import { AndroidLivesyncTool } from "./android-livesync-tool";
|
7 | 5 | import * as path from "path";
|
8 | 6 | import * as temp from "temp";
|
9 | 7 | import * as semver from "semver";
|
10 | 8 |
|
11 |
| -export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBase implements IAndroidNativeScriptDeviceLiveSyncService, INativeScriptDeviceLiveSyncService { |
| 9 | +export class AndroidDeviceSocketsLiveSyncService extends AndroidDeviceLiveSyncServiceBase implements IAndroidNativeScriptDeviceLiveSyncService, INativeScriptDeviceLiveSyncService { |
12 | 10 | private livesyncTool: IAndroidLivesyncTool;
|
13 | 11 | private static STATUS_UPDATE_INTERVAL = 10000;
|
14 | 12 | private static MINIMAL_VERSION_LONG_LIVING_CONNECTION = "0.2.0";
|
15 | 13 |
|
16 | 14 | constructor(
|
17 | 15 | private data: IProjectData,
|
18 |
| - private $injector: IInjector, |
| 16 | + $injector: IInjector, |
19 | 17 | protected $platformsData: IPlatformsData,
|
20 | 18 | protected $staticConfig: Config.IStaticConfig,
|
21 |
| - private $logger: ILogger, |
| 19 | + $logger: ILogger, |
22 | 20 | protected device: Mobile.IAndroidDevice,
|
23 | 21 | private $options: IOptions,
|
24 | 22 | private $processService: IProcessService,
|
25 | 23 | private $fs: IFileSystem,
|
26 |
| - private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants) { |
27 |
| - super($platformsData, device); |
28 |
| - this.livesyncTool = this.$injector.resolve(AndroidLivesyncTool); |
| 24 | + private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants, |
| 25 | + $filesHashService: IFilesHashService) { |
| 26 | + super($injector, $platformsData, $filesHashService, $logger, device); |
| 27 | + this.livesyncTool = this.$injector.resolve(AndroidLivesyncTool); |
29 | 28 | }
|
30 | 29 |
|
31 | 30 | public async beforeLiveSyncAction(deviceAppData: Mobile.IDeviceAppData): Promise<void> {
|
@@ -101,67 +100,17 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
|
101 | 100 |
|
102 | 101 | public async removeFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<void> {
|
103 | 102 | await this.livesyncTool.removeFiles(_.map(localToDevicePaths, (element: any) => element.filePath));
|
104 |
| - |
105 |
| - await this.getDeviceHashService(deviceAppData.appIdentifier).removeHashes(localToDevicePaths); |
106 |
| - } |
107 |
| - |
108 |
| - public async transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string, isFullSync: boolean): Promise<Mobile.ILocalToDevicePathData[]> { |
109 |
| - let transferredFiles; |
110 |
| - |
111 |
| - if (isFullSync) { |
112 |
| - transferredFiles = await this._transferDirectory(deviceAppData, localToDevicePaths, projectFilesPath); |
113 |
| - } else { |
114 |
| - transferredFiles = await this._transferFiles(deviceAppData, localToDevicePaths); |
115 |
| - } |
116 |
| - |
117 |
| - return transferredFiles; |
118 |
| - } |
119 |
| - |
120 |
| - public getDeviceHashService(appIdentifier: string): Mobile.IAndroidDeviceHashService { |
121 |
| - const adb = this.$injector.resolve(DeviceAndroidDebugBridge, { identifier: this.device.deviceInfo.identifier }); |
122 |
| - return this.$injector.resolve(AndroidDeviceHashService, { adb, appIdentifier }); |
123 |
| - } |
124 |
| - |
125 |
| - private async _transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise<Mobile.ILocalToDevicePathData[]> { |
126 |
| - await this.livesyncTool.sendFiles(localToDevicePaths.map(localToDevicePathData => localToDevicePathData.getLocalPath())); |
127 |
| - |
128 |
| - // Update hashes |
129 | 103 | const deviceHashService = this.getDeviceHashService(deviceAppData.appIdentifier);
|
130 |
| - if (! await deviceHashService.updateHashes(localToDevicePaths)) { |
131 |
| - this.$logger.trace("Unable to find hash file on device. The next livesync command will create it."); |
132 |
| - } |
133 |
| - |
134 |
| - return localToDevicePaths; |
| 104 | + await deviceHashService.removeHashes(localToDevicePaths); |
135 | 105 | }
|
136 | 106 |
|
137 |
| - private async _transferDirectory(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<Mobile.ILocalToDevicePathData[]> { |
138 |
| - let transferredLocalToDevicePaths: Mobile.ILocalToDevicePathData[]; |
139 |
| - const deviceHashService = this.getDeviceHashService(deviceAppData.appIdentifier); |
140 |
| - const currentHashes = await deviceHashService.generateHashesFromLocalToDevicePaths(localToDevicePaths); |
141 |
| - const oldHashes = await deviceHashService.getShasumsFromDevice(); |
142 |
| - console.log("!!!!! OLD HASHES!!!!!!"); |
143 |
| - console.log(oldHashes); |
144 |
| - |
145 |
| - if (this.$options.force || !oldHashes) { |
146 |
| - console.log("!!!!!!!!! NO OLD HASHES!!!!! THIS SHOULD NOT HAPPEN!!!!!!!"); |
147 |
| - await this.livesyncTool.sendDirectory(projectFilesPath); |
148 |
| - await deviceHashService.uploadHashFileToDevice(currentHashes); |
149 |
| - transferredLocalToDevicePaths = localToDevicePaths; |
150 |
| - } else { |
151 |
| - const changedShasums = deviceHashService.getChangedShasums(oldHashes, currentHashes); |
152 |
| - console.log("CHANGEDSHASUMS!!!!!!!!!!!!!!!"); |
153 |
| - console.log(changedShasums); |
154 |
| - const changedFiles = _.keys(changedShasums); |
155 |
| - if (changedFiles.length) { |
156 |
| - await this.livesyncTool.sendFiles(changedFiles); |
157 |
| - await deviceHashService.uploadHashFileToDevice(currentHashes); |
158 |
| - transferredLocalToDevicePaths = localToDevicePaths.filter(localToDevicePathData => changedFiles.indexOf(localToDevicePathData.getLocalPath()) >= 0); |
159 |
| - } else { |
160 |
| - transferredLocalToDevicePaths = []; |
161 |
| - } |
162 |
| - } |
| 107 | + public async transferFilesOnDevice(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise<void> { |
| 108 | + const files = _.map(localToDevicePaths, localToDevicePath => localToDevicePath.getLocalPath()); |
| 109 | + await this.livesyncTool.sendFiles(files); |
| 110 | + } |
163 | 111 |
|
164 |
| - return transferredLocalToDevicePaths; |
| 112 | + public async transferDirectoryOnDevice(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<void> { |
| 113 | + await this.livesyncTool.sendDirectory(projectFilesPath); |
165 | 114 | }
|
166 | 115 |
|
167 | 116 | private async connectLivesyncTool(appIdentifier: string) {
|
|
0 commit comments