Skip to content

Commit 605df4a

Browse files
refactor: Use single object as arg for some of application manager methods
In order to make future refactorings easier, introduce a single object as an argument to some of the methods in devices' ApplicationManagers.
1 parent aa4ecfe commit 605df4a

8 files changed

+34
-25
lines changed

lib/definitions/platform.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ interface IPlatformService extends IBuildPlatformAction, NodeJS.EventEmitter {
125125
* @param {IProjectData} projectData DTO with information about the project.
126126
* @returns {void}
127127
*/
128-
startApplication(platform: string, runOptions: IRunPlatformOptions, projectId: string, projectName: string): Promise<void>;
128+
startApplication(platform: string, runOptions: IRunPlatformOptions, appData: Mobile.IApplicationData): Promise<void>;
129129

130130
cleanDestinationApp(platformInfo: IPreparePlatformInfo): Promise<void>;
131131
validatePlatformInstalled(platform: string, projectData: IProjectData): void;

lib/helpers/livesync-command-helper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
151151
};
152152

153153
await this.$platformService.deployPlatform(deployPlatformInfo);
154-
await this.$platformService.startApplication(currentPlatform, runPlatformOptions, this.$projectData.projectId, this.$projectData.projectName);
154+
await this.$platformService.startApplication(currentPlatform, runPlatformOptions, { appId: this.$projectData.projectId, projectName: this.$projectData.projectName });
155155
this.$platformService.trackProjectType(this.$projectData);
156156
}
157157
}

lib/services/android-debug-service.ts

+25-16
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ export class AndroidDebugService extends DebugServiceBase implements IPlatformDe
2626
}
2727

2828
public async debugStart(debugData: IDebugData, debugOptions: IDebugOptions): Promise<void> {
29-
const projectData = this.$projectDataService.getProjectData(debugData.projectDir);
3029
await this.$devicesService.initialize({ platform: this.platform, deviceId: debugData.deviceIdentifier });
31-
const action = (device: Mobile.IAndroidDevice): Promise<void> => this.debugStartCore(debugData.applicationIdentifier, debugOptions, projectData.projectName);
30+
const projectData = this.$projectDataService.getProjectData(debugData.projectDir);
31+
const appData: Mobile.IApplicationData = {
32+
appId: debugData.applicationIdentifier,
33+
projectName: projectData.projectName
34+
};
35+
36+
const action = (device: Mobile.IAndroidDevice): Promise<void> => this.debugStartCore(appData, debugOptions);
3237

3338
await this.$devicesService.execute(action, this.getCanExecuteAction(debugData.deviceIdentifier));
3439
}
@@ -93,24 +98,29 @@ export class AndroidDebugService extends DebugServiceBase implements IPlatformDe
9398

9499
await this.$devicesService.initialize({ platform: this.platform, deviceId: debugData.deviceIdentifier });
95100

96-
const packageName = this.$projectDataService.getProjectData(debugData.projectDir).projectName;
97-
const action = (device: Mobile.IAndroidDevice): Promise<string> => this.debugCore(device, packageFile, debugData.applicationIdentifier, packageName, debugOptions);
101+
const projectName = this.$projectDataService.getProjectData(debugData.projectDir).projectName;
102+
const appData: Mobile.IApplicationData = {
103+
appId: debugData.applicationIdentifier,
104+
projectName
105+
};
106+
107+
const action = (device: Mobile.IAndroidDevice): Promise<string> => this.debugCore(device, packageFile, appData, debugOptions);
98108

99109
const deviceActionResult = await this.$devicesService.execute(action, this.getCanExecuteAction(debugData.deviceIdentifier));
100110
return deviceActionResult[0].result;
101111
}
102112

103-
private async debugCore(device: Mobile.IAndroidDevice, packageFile: string, appId: string, packageName: string, debugOptions: IDebugOptions): Promise<string> {
104-
await this.printDebugPort(device.deviceInfo.identifier, appId);
113+
private async debugCore(device: Mobile.IAndroidDevice, packageFile: string, appData: Mobile.IApplicationData, debugOptions: IDebugOptions): Promise<string> {
114+
await this.printDebugPort(device.deviceInfo.identifier, appData.appId);
105115

106116
if (debugOptions.start) {
107-
return await this.attachDebugger(device.deviceInfo.identifier, appId, debugOptions);
117+
return await this.attachDebugger(device.deviceInfo.identifier, appData.appId, debugOptions);
108118
} else if (debugOptions.stop) {
109119
await this.removePortForwarding();
110120
return null;
111121
} else {
112-
await this.debugStartCore(appId, debugOptions, packageName);
113-
return await this.attachDebugger(device.deviceInfo.identifier, appId, debugOptions);
122+
await this.debugStartCore(appData, debugOptions);
123+
return await this.attachDebugger(device.deviceInfo.identifier, appData.appId, debugOptions);
114124
}
115125
}
116126

@@ -129,22 +139,21 @@ export class AndroidDebugService extends DebugServiceBase implements IPlatformDe
129139
return this.getChromeDebugUrl(debugOptions, port);
130140
}
131141

132-
private async debugStartCore(appId: string, debugOptions: IDebugOptions, projectName: string): Promise<void> {
142+
private async debugStartCore(appData: Mobile.IApplicationData, debugOptions: IDebugOptions): Promise<void> {
133143
// Arguments passed to executeShellCommand must be in array ([]), but it turned out adb shell "arg with intervals" still works correctly.
134144
// As we need to redirect output of a command on the device, keep using only one argument.
135145
// We could rewrite this with two calls - touch and rm -f , but -f flag is not available on old Android, so rm call will fail when file does not exist.
136-
137-
await this.device.applicationManager.stopApplication(appId);
146+
await this.device.applicationManager.stopApplication(appData);
138147

139148
if (debugOptions.debugBrk) {
140-
await this.device.adb.executeShellCommand([`cat /dev/null > /data/local/tmp/${appId}-debugbreak`]);
149+
await this.device.adb.executeShellCommand([`cat /dev/null > /data/local/tmp/${appData.appId}-debugbreak`]);
141150
}
142151

143-
await this.device.adb.executeShellCommand([`cat /dev/null > /data/local/tmp/${appId}-debugger-started`]);
152+
await this.device.adb.executeShellCommand([`cat /dev/null > /data/local/tmp/${appData.appId}-debugger-started`]);
144153

145-
await this.device.applicationManager.startApplication(appId, projectName);
154+
await this.device.applicationManager.startApplication(appData);
146155

147-
await this.waitForDebugger(appId);
156+
await this.waitForDebugger(appData.appId);
148157
}
149158

150159
private async waitForDebugger(packageName: String): Promise<void> {

lib/services/ios-debug-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
187187
};
188188

189189
const promisesResults = await Promise.all<any>([
190-
this.$platformService.startApplication(this.platform, runOptions, debugData.applicationIdentifier, projectData.projectName),
190+
this.$platformService.startApplication(this.platform, runOptions, { appId: debugData.applicationIdentifier, projectName: projectData.projectName }),
191191
this.debugBrkCore(device, debugData, debugOptions)
192192
]);
193193

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class AndroidDeviceLiveSyncService extends DeviceLiveSyncServiceBase impl
6262
const devicePath = this.$mobileHelper.buildDevicePath(devicePathRoot, "code_cache", "secondary_dexes", "proxyThumb");
6363
await this.device.adb.executeShellCommand(["rm", "-rf", devicePath]);
6464

65-
await this.device.applicationManager.restartApplication(deviceAppData.appIdentifier, projectName);
65+
await this.device.applicationManager.restartApplication({ appId: deviceAppData.appIdentifier, projectName });
6666
}
6767

6868
public async beforeLiveSyncAction(deviceAppData: Mobile.IDeviceAppData): Promise<void> {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ export class IOSDeviceLiveSyncService extends DeviceLiveSyncServiceBase implemen
7575
}
7676
}
7777

78-
private async restartApplication(deviceAppData: Mobile.IDeviceAppData, appName: string): Promise<void> {
79-
return this.device.applicationManager.restartApplication(deviceAppData.appIdentifier, appName);
78+
private async restartApplication(deviceAppData: Mobile.IDeviceAppData, projectName: string): Promise<void> {
79+
return this.device.applicationManager.restartApplication({ appId: deviceAppData.appIdentifier, projectName });
8080
}
8181

8282
private async reloadPage(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise<void> {

lib/services/livesync/livesync-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
165165
};
166166

167167
try {
168-
await deviceAppData.device.applicationManager.stopApplication(applicationId, projectData.projectName);
168+
await deviceAppData.device.applicationManager.stopApplication({ appId: applicationId, projectName: projectData.projectName });
169169
// Now that we've stopped the application we know it isn't started, so set debugOptions.start to false
170170
// so that it doesn't default to true in attachDebugger method
171171
debugOptions = debugOptions || {};

lib/services/platform-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -543,11 +543,11 @@ export class PlatformService extends EventEmitter implements IPlatformService {
543543
await this.$devicesService.execute(action, this.getCanExecuteAction(deployInfo.platform, deployInfo.deployOptions));
544544
}
545545

546-
public async startApplication(platform: string, runOptions: IRunPlatformOptions, projectId: string, projectName: string): Promise<void> {
546+
public async startApplication(platform: string, runOptions: IRunPlatformOptions, appData: Mobile.IApplicationData): Promise<void> {
547547
this.$logger.out("Starting...");
548548

549549
const action = async (device: Mobile.IDevice) => {
550-
await device.applicationManager.startApplication(projectId, projectName);
550+
await device.applicationManager.startApplication(appData);
551551
this.$logger.out(`Successfully started on device with identifier '${device.deviceInfo.identifier}'.`);
552552
};
553553

0 commit comments

Comments
 (0)