Skip to content

Commit 2c4d0c9

Browse files
author
Dimitar Kerezov
committed
Delete AndroidAppIdentifier
1 parent e293ef9 commit 2c4d0c9

File tree

8 files changed

+64
-86
lines changed

8 files changed

+64
-86
lines changed

lib/bootstrap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ $injector.require("androidToolsInfo", "./android-tools-info");
104104
$injector.requireCommand("platform|clean", "./commands/platform-clean");
105105

106106
$injector.require("liveSyncService", "./services/livesync/livesync-service"); // The name is used in https://github.com/NativeScript/nativescript-dev-typescript
107+
$injector.require("androidLiveSyncService", "./services/livesync/android-livesync-service");
108+
$injector.require("iOSLiveSyncService", "./services/livesync/ios-livesync-service");
107109
$injector.require("usbLiveSyncService", "./services/livesync/livesync-service"); // The name is used in https://github.com/NativeScript/nativescript-dev-typescript
108110
$injector.require("iosLiveSyncServiceLocator", "./services/livesync/ios-device-livesync-service");
109-
$injector.require("androidLiveSyncServiceLocator", "./services/livesync/android-device-livesync-service");
110-
111111
$injector.require("sysInfo", "./sys-info");
112112

113113
$injector.require("iOSNotificationService", "./services/ios-notification-service");

lib/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ class ItunesConnectApplicationTypesClass implements IiTunesConnectApplicationTyp
6666
}
6767

6868
export const ItunesConnectApplicationTypes = new ItunesConnectApplicationTypesClass();
69-
69+
export const SYNC_DIR_NAME = "sync";
70+
export const REMOVEDSYNC_DIR_NAME = "removedsync";
71+
export const FULLSYNC_DIR_NAME = "fullsync";
7072
export const ANGULAR_NAME = "angular";
7173
export const TYPESCRIPT_NAME = "typescript";
7274
export const BUILD_OUTPUT_EVENT_NAME = "buildOutput";

lib/definitions/livesync.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ interface ILiveSyncResultInfo {
163163
interface IFullSyncInfo {
164164
projectData: IProjectData;
165165
device: Mobile.IDevice;
166+
watch: boolean;
166167
syncAllFiles: boolean;
167168
useLiveEdit?: boolean;
168169
}
@@ -194,3 +195,12 @@ interface INativeScriptDeviceLiveSyncService extends IDeviceLiveSyncServiceBase
194195
*/
195196
removeFiles(appIdentifier: string, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectId: string): Promise<void>;
196197
}
198+
199+
interface IAndroidNativeScriptDeviceLiveSyncService {
200+
/**
201+
* Retrieves the android device's hash service.
202+
* @param {string} appIdentifier Application identifier.
203+
* @return {Promise<Mobile.IAndroidDeviceHashService>} The hash service
204+
*/
205+
getDeviceHashService(appIdentifier: string): Mobile.IAndroidDeviceHashService;
206+
}

lib/providers/device-app-data-provider.ts

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import * as deviceAppDataBaseLib from "../common/mobile/device-app-data/device-app-data-base";
22
import * as path from "path";
3-
import { AndroidDeviceHashService } from "../common/mobile/android/android-device-hash-service";
4-
import { DeviceAndroidDebugBridge } from "../common/mobile/android/device-android-debug-bridge";
5-
6-
const SYNC_DIR_NAME = "sync";
7-
const FULLSYNC_DIR_NAME = "fullsync";
83

94
export class IOSAppIdentifier extends deviceAppDataBaseLib.DeviceAppDataBase implements Mobile.IDeviceAppData {
105
private static DEVICE_PROJECT_ROOT_PATH = "Library/Application Support/LiveSync/app";
@@ -43,46 +38,11 @@ export class IOSAppIdentifier extends deviceAppDataBaseLib.DeviceAppDataBase imp
4338
}
4439
}
4540

46-
export class AndroidAppIdentifier extends deviceAppDataBaseLib.DeviceAppDataBase implements Mobile.IDeviceAppData {
47-
constructor(_appIdentifier: string,
48-
public device: Mobile.IDevice,
49-
public platform: string,
50-
private $options: IOptions,
51-
private $injector: IInjector) {
52-
super(_appIdentifier);
53-
}
54-
55-
private _deviceProjectRootPath: string;
56-
57-
public async getDeviceProjectRootPath(): Promise<string> {
58-
if (!this._deviceProjectRootPath) {
59-
let syncFolderName = await this.getSyncFolderName();
60-
this._deviceProjectRootPath = `/data/local/tmp/${this.appIdentifier}/${syncFolderName}`;
61-
}
62-
63-
return this._deviceProjectRootPath;
64-
}
65-
66-
public async isLiveSyncSupported(): Promise<boolean> {
67-
return true;
68-
}
69-
70-
private async getSyncFolderName(): Promise<string> {
71-
let adb = this.$injector.resolve(DeviceAndroidDebugBridge, { identifier: this.device.deviceInfo.identifier });
72-
let deviceHashService: AndroidDeviceHashService = this.$injector.resolve(AndroidDeviceHashService, { adb: adb, appIdentifier: this.appIdentifier });
73-
let hashFile = this.$options.force ? null : await deviceHashService.doesShasumFileExistsOnDevice();
74-
return this.$options.watch || hashFile ? SYNC_DIR_NAME : FULLSYNC_DIR_NAME;
75-
}
76-
}
77-
7841
export class DeviceAppDataProvider implements Mobile.IDeviceAppDataProvider {
7942
public createFactoryRules(): IDictionary<Mobile.IDeviceAppDataFactoryRule> {
8043
return {
8144
iOS: {
8245
vanilla: IOSAppIdentifier
83-
},
84-
Android: {
85-
vanilla: AndroidAppIdentifier
8646
}
8747
};
8848
}

lib/services/livesync/android-device-livesync-service.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { DeviceAndroidDebugBridge } from "../../common/mobile/android/device-android-debug-bridge";
22
import { AndroidDeviceHashService } from "../../common/mobile/android/android-device-hash-service";
33
import * as helpers from "../../common/helpers";
4+
import { SYNC_DIR_NAME, FULLSYNC_DIR_NAME, REMOVEDSYNC_DIR_NAME } from "../../constants";
45
import { cache } from "../../common/decorators";
56
import * as path from "path";
67
import * as net from "net";
78
import { EOL } from "os";
89

9-
export class AndroidLiveSyncService implements INativeScriptDeviceLiveSyncService {
10-
private static FAST_SYNC_FILE_EXTENSIONS = [".css", ".xml", ".html"];
10+
export class AndroidDeviceLiveSyncService implements IAndroidNativeScriptDeviceLiveSyncService {
11+
private static FAST_SYNC_FILE_EXTENSIONS = [".css", ".xml", ".html"];
1112

1213
private static BACKEND_PORT = 18182;
1314
private device: Mobile.IAndroidDevice;
@@ -37,7 +38,7 @@ export class AndroidLiveSyncService implements INativeScriptDeviceLiveSyncServic
3738
`/data/local/tmp/${deviceAppData.appIdentifier}/sync`]
3839
);
3940

40-
let canExecuteFastSync = ! liveSyncInfo.isFullSync && !_.some(localToDevicePaths,
41+
let canExecuteFastSync = !liveSyncInfo.isFullSync && !_.some(localToDevicePaths,
4142
(localToDevicePath: Mobile.ILocalToDevicePathData) => !this.canExecuteFastSync(localToDevicePath.getLocalPath(), projectData, this.device.deviceInfo.platform));
4243

4344
if (canExecuteFastSync) {
@@ -50,7 +51,7 @@ export class AndroidLiveSyncService implements INativeScriptDeviceLiveSyncServic
5051
@cache()
5152
private getFastLiveSyncFileExtensions(platform: string, projectData: IProjectData): string[] {
5253
const platformData = this.$platformsData.getPlatformData(platform, projectData);
53-
const fastSyncFileExtensions = AndroidLiveSyncService.FAST_SYNC_FILE_EXTENSIONS.concat(platformData.fastLivesyncFileExtensions);
54+
const fastSyncFileExtensions = AndroidDeviceLiveSyncService.FAST_SYNC_FILE_EXTENSIONS.concat(platformData.fastLivesyncFileExtensions);
5455
return fastSyncFileExtensions;
5556
}
5657

@@ -87,13 +88,13 @@ export class AndroidLiveSyncService implements INativeScriptDeviceLiveSyncServic
8788
await this.device.adb.executeShellCommand(["rm", "-f", deviceRootPath]);
8889
}
8990

90-
this.device.adb.executeShellCommand(["rm", "-rf", this.$mobileHelper.buildDevicePath(deviceRootPath, "fullsync"),
91-
this.$mobileHelper.buildDevicePath(deviceRootPath, "sync"),
92-
await this.$mobileHelper.buildDevicePath(deviceRootPath, "removedsync")]);
91+
this.device.adb.executeShellCommand(["rm", "-rf", this.$mobileHelper.buildDevicePath(deviceRootPath, FULLSYNC_DIR_NAME),
92+
this.$mobileHelper.buildDevicePath(deviceRootPath, SYNC_DIR_NAME),
93+
await this.$mobileHelper.buildDevicePath(deviceRootPath, REMOVEDSYNC_DIR_NAME)]);
9394
}
9495

9596
private async reloadPage(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise<void> {
96-
await this.device.adb.executeCommand(["forward", `tcp:${AndroidLiveSyncService.BACKEND_PORT.toString()}`, `localabstract:${deviceAppData.appIdentifier}-livesync`]);
97+
await this.device.adb.executeCommand(["forward", `tcp:${AndroidDeviceLiveSyncService.BACKEND_PORT.toString()}`, `localabstract:${deviceAppData.appIdentifier}-livesync`]);
9798
if (!await this.sendPageReloadMessage()) {
9899
await this.restartApplication(deviceAppData);
99100
}
@@ -104,13 +105,19 @@ export class AndroidLiveSyncService implements INativeScriptDeviceLiveSyncServic
104105

105106
for (let localToDevicePathData of localToDevicePaths) {
106107
let relativeUnixPath = _.trimStart(helpers.fromWindowsRelativePathToUnix(localToDevicePathData.getRelativeToProjectBasePath()), "/");
107-
let deviceFilePath = this.$mobileHelper.buildDevicePath(deviceRootPath, "removedsync", relativeUnixPath);
108+
let deviceFilePath = this.$mobileHelper.buildDevicePath(deviceRootPath, REMOVEDSYNC_DIR_NAME, relativeUnixPath);
108109
await this.device.adb.executeShellCommand(["mkdir", "-p", path.dirname(deviceFilePath), " && ", "touch", deviceFilePath]);
109110
}
110111

111112
await this.getDeviceHashService(projectId).removeHashes(localToDevicePaths);
112113
}
113114

115+
@cache()
116+
public getDeviceHashService(appIdentifier: string): Mobile.IAndroidDeviceHashService {
117+
let adb = this.$injector.resolve(DeviceAndroidDebugBridge, { identifier: this.device.deviceInfo.identifier });
118+
return this.$injector.resolve(AndroidDeviceHashService, { adb, appIdentifier });
119+
}
120+
114121
private getDeviceRootPath(appIdentifier: string): string {
115122
return `/data/local/tmp/${appIdentifier}`;
116123
}
@@ -120,7 +127,7 @@ export class AndroidLiveSyncService implements INativeScriptDeviceLiveSyncServic
120127
let isResolved = false;
121128
let socket = new net.Socket();
122129

123-
socket.connect(AndroidLiveSyncService.BACKEND_PORT, '127.0.0.1', () => {
130+
socket.connect(AndroidDeviceLiveSyncService.BACKEND_PORT, '127.0.0.1', () => {
124131
socket.write(new Buffer([0, 0, 0, 1, 1]));
125132
});
126133
socket.on("data", (data: any) => {
@@ -141,15 +148,4 @@ export class AndroidLiveSyncService implements INativeScriptDeviceLiveSyncServic
141148
});
142149
});
143150
}
144-
145-
private _deviceHashService: Mobile.IAndroidDeviceHashService;
146-
private getDeviceHashService(projectId: string): Mobile.IAndroidDeviceHashService {
147-
if (!this._deviceHashService) {
148-
let adb = this.$injector.resolve(DeviceAndroidDebugBridge, { identifier: this.device.deviceInfo.identifier });
149-
this._deviceHashService = this.$injector.resolve(AndroidDeviceHashService, { adb: adb, appIdentifier: projectId });
150-
}
151-
152-
return this._deviceHashService;
153-
}
154151
}
155-
$injector.register("androidLiveSyncServiceLocator", { factory: AndroidLiveSyncService });

lib/services/livesync/android-livesync-service.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as deviceAppDataIdentifiers from "../../providers/device-app-data-provider";
21
import * as path from "path";
3-
import * as adls from "./android-device-livesync-service";
2+
import { AndroidDeviceLiveSyncService } from "./android-device-livesync-service";
3+
import { APP_FOLDER_NAME, SYNC_DIR_NAME, FULLSYNC_DIR_NAME } from "../../constants";
44

55
export class AndroidLiveSyncService implements IPlatformLiveSyncService {
66
constructor(private $projectFilesManager: IProjectFilesManager,
@@ -14,14 +14,13 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
1414
public async fullSync(syncInfo: IFullSyncInfo): Promise<ILiveSyncResultInfo> {
1515
const projectData = syncInfo.projectData;
1616
const device = syncInfo.device;
17-
const deviceLiveSyncService = this.$injector.resolve<adls.AndroidLiveSyncService>(adls.AndroidLiveSyncService, { _device: device });
17+
const deviceLiveSyncService = this.$injector.resolve<AndroidDeviceLiveSyncService>(AndroidDeviceLiveSyncService, { _device: device });
1818
const platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform, projectData);
19-
const deviceAppData = this.$injector.resolve(deviceAppDataIdentifiers.AndroidAppIdentifier,
20-
{ _appIdentifier: projectData.projectId, device, platform: device.deviceInfo.platform });
2119

20+
const deviceAppData = await this.getAppData(syncInfo, deviceLiveSyncService);
2221
await deviceLiveSyncService.beforeLiveSyncAction(deviceAppData);
2322

24-
const projectFilesPath = path.join(platformData.appDestinationDirectoryPath, "app");
23+
const projectFilesPath = path.join(platformData.appDestinationDirectoryPath, APP_FOLDER_NAME);
2524
const localToDevicePaths = await this.$projectFilesManager.createLocalToDevicePaths(deviceAppData, projectFilesPath, null, []);
2625
await this.transferFiles(deviceAppData, localToDevicePaths, projectFilesPath, true);
2726

@@ -34,8 +33,9 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
3433

3534
public async liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<ILiveSyncResultInfo> {
3635
const projectData = liveSyncInfo.projectData;
37-
const deviceAppData = this.$injector.resolve(deviceAppDataIdentifiers.AndroidAppIdentifier,
38-
{ _appIdentifier: projectData.projectId, device, platform: device.deviceInfo.platform });
36+
const syncInfo = _.merge<IFullSyncInfo>({ device, watch: true }, liveSyncInfo);
37+
const deviceLiveSyncService = this.$injector.resolve<AndroidDeviceLiveSyncService>(AndroidDeviceLiveSyncService, { _device: device });
38+
const deviceAppData = await this.getAppData(syncInfo, deviceLiveSyncService);
3939

4040
let modifiedLocalToDevicePaths: Mobile.ILocalToDevicePathData[] = [];
4141
if (liveSyncInfo.filesToSync.length) {
@@ -52,7 +52,7 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
5252

5353
if (existingFiles.length) {
5454
let platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform, projectData);
55-
const projectFilesPath = path.join(platformData.appDestinationDirectoryPath, "app");
55+
const projectFilesPath = path.join(platformData.appDestinationDirectoryPath, APP_FOLDER_NAME);
5656
let localToDevicePaths = await this.$projectFilesManager.createLocalToDevicePaths(deviceAppData,
5757
projectFilesPath, mappedFiles, []);
5858
modifiedLocalToDevicePaths.push(...localToDevicePaths);
@@ -65,11 +65,11 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
6565
let platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform, projectData);
6666

6767
const mappedFiles = _.map(filePaths, filePath => this.$projectFilesProvider.mapFilePath(filePath, device.deviceInfo.platform, projectData));
68-
const projectFilesPath = path.join(platformData.appDestinationDirectoryPath, "app");
68+
const projectFilesPath = path.join(platformData.appDestinationDirectoryPath, APP_FOLDER_NAME);
6969
let localToDevicePaths = await this.$projectFilesManager.createLocalToDevicePaths(deviceAppData, projectFilesPath, mappedFiles, []);
7070
modifiedLocalToDevicePaths.push(...localToDevicePaths);
7171

72-
const deviceLiveSyncService = this.$injector.resolve<INativeScriptDeviceLiveSyncService>(adls.AndroidLiveSyncService, { _device: device });
72+
const deviceLiveSyncService = this.$injector.resolve<INativeScriptDeviceLiveSyncService>(AndroidDeviceLiveSyncService, { _device: device });
7373
deviceLiveSyncService.removeFiles(projectData.projectId, localToDevicePaths, projectData.projectId);
7474
}
7575

@@ -80,12 +80,9 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
8080
};
8181
}
8282

83-
public async refreshApplication(
84-
projectData: IProjectData,
85-
liveSyncInfo: ILiveSyncResultInfo
86-
): Promise<void> {
83+
public async refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise<void> {
8784
if (liveSyncInfo.isFullSync || liveSyncInfo.modifiedFilesData.length) {
88-
let deviceLiveSyncService = this.$injector.resolve<INativeScriptDeviceLiveSyncService>(adls.AndroidLiveSyncService, { _device: liveSyncInfo.deviceAppData.device });
85+
let deviceLiveSyncService = this.$injector.resolve<INativeScriptDeviceLiveSyncService>(AndroidDeviceLiveSyncService, { _device: liveSyncInfo.deviceAppData.device });
8986
this.$logger.info("Refreshing application...");
9087
await deviceLiveSyncService.refreshApplication(projectData, liveSyncInfo);
9188
}
@@ -97,7 +94,21 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
9794
} else {
9895
await deviceAppData.device.fileSystem.transferFiles(deviceAppData, localToDevicePaths);
9996
}
97+
}
10098

101-
console.log("TRANSFEREEDDDDDDD!!!!!!");
99+
private async getAppData(syncInfo: IFullSyncInfo, deviceLiveSyncService: IAndroidNativeScriptDeviceLiveSyncService): Promise<Mobile.IDeviceAppData> {
100+
return {
101+
appIdentifier: syncInfo.device.deviceInfo.identifier,
102+
device: syncInfo.device,
103+
platform: syncInfo.device.deviceInfo.platform,
104+
getDeviceProjectRootPath: async () => {
105+
const hashService = deviceLiveSyncService.getDeviceHashService(syncInfo.device.deviceInfo.identifier);
106+
const hashFile = syncInfo.syncAllFiles ? null : await hashService.doesShasumFileExistsOnDevice();
107+
const syncFolderName = syncInfo.watch || hashFile ? SYNC_DIR_NAME : FULLSYNC_DIR_NAME;
108+
return `/data/local/tmp/${syncInfo.device.deviceInfo.identifier}/${syncFolderName}`;
109+
},
110+
isLiveSyncSupported: async () => true
111+
};
102112
}
103113
}
114+
$injector.register("androidLiveSyncService", AndroidLiveSyncService);

lib/services/livesync/ios-livesync-service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class IOSLiveSyncService implements IPlatformLiveSyncService {
7676

7777
if (liveSyncInfo.isRebuilt) {
7878
// In this case we should execute fullsync:
79-
await this.fullSync({ projectData, device, syncAllFiles: liveSyncInfo.syncAllFiles });
79+
await this.fullSync({ projectData, device, syncAllFiles: liveSyncInfo.syncAllFiles, watch: true });
8080
} else {
8181
if (liveSyncInfo.filesToSync.length) {
8282
const filesToSync = liveSyncInfo.filesToSync;
@@ -138,3 +138,4 @@ export class IOSLiveSyncService implements IPlatformLiveSyncService {
138138
console.log("### ios TRANSFEREEDDDDDDD!!!!!!");
139139
}
140140
}
141+
$injector.register("iOSLiveSyncService", IOSLiveSyncService);

lib/services/livesync/livesync-service.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import * as path from "path";
22
import * as choki from "chokidar";
3-
import * as iOSLs from "./ios-livesync-service";
4-
import * as androidLs from "./android-livesync-service";
53
import { EventEmitter } from "events";
64
import { exported } from "../../common/decorators";
75
import { hook } from "../../common/helpers";
@@ -123,9 +121,9 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
123121
// TODO: Register both livesync services in injector
124122
private getLiveSyncService(platform: string): IPlatformLiveSyncService {
125123
if (this.$mobileHelper.isiOSPlatform(platform)) {
126-
return this.$injector.resolve(iOSLs.IOSLiveSyncService);
124+
return this.$injector.resolve("iOSLiveSyncService");
127125
} else if (this.$mobileHelper.isAndroidPlatform(platform)) {
128-
return this.$injector.resolve(androidLs.AndroidLiveSyncService);
126+
return this.$injector.resolve("androidLiveSyncService");
129127
}
130128

131129
throw new Error(`Invalid platform ${platform}. Supported platforms are: ${this.$mobileHelper.platformNames.join(", ")}`);

0 commit comments

Comments
 (0)