Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit f07714f

Browse files
author
Nedyalko Nikolov
authored
Merge pull request #839 from telerik/nnikolov/InstallHook
Added install hook.
2 parents 6f46668 + 259100a commit f07714f

File tree

6 files changed

+42
-19
lines changed

6 files changed

+42
-19
lines changed

mobile/android/android-application-manager.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import {EOL} from "os";
2-
import {ApplicationManagerBase} from "../application-manager-base";
1+
import { EOL } from "os";
2+
import { ApplicationManagerBase } from "../application-manager-base";
33
import { LiveSyncConstants, TARGET_FRAMEWORK_IDENTIFIERS } from "../../constants";
44
import Future = require("fibers/future");
5+
import { hook } from "../../helpers";
56

67
export class AndroidApplicationManager extends ApplicationManagerBase {
78

@@ -12,8 +13,9 @@ export class AndroidApplicationManager extends ApplicationManagerBase {
1213
private $logcatHelper: Mobile.ILogcatHelper,
1314
private $androidProcessService: Mobile.IAndroidProcessService,
1415
private $httpClient: Server.IHttpClient,
15-
$logger: ILogger) {
16-
super($logger);
16+
$logger: ILogger,
17+
$hooksService: IHooksService) {
18+
super($logger, $hooksService);
1719
}
1820

1921
public getInstalledApplications(): IFuture<string[]> {
@@ -30,6 +32,7 @@ export class AndroidApplicationManager extends ApplicationManagerBase {
3032
}).future<string[]>()();
3133
}
3234

35+
@hook('install')
3336
public installApplication(packageFilePath: string): IFuture<void> {
3437
return this.adb.executeCommand(["install", "-r", `${packageFilePath}`]);
3538
}

mobile/application-manager-base.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { EventEmitter } from "events";
2-
import {TARGET_FRAMEWORK_IDENTIFIERS} from "../constants";
2+
import { TARGET_FRAMEWORK_IDENTIFIERS } from "../constants";
33

44
export abstract class ApplicationManagerBase extends EventEmitter implements Mobile.IDeviceApplicationManager {
55
private lastInstalledAppIdentifiers: string[];
66
private lastAvailableDebuggableApps: Mobile.IDeviceApplicationInformation[];
77
private lastAvailableDebuggableAppViews: IDictionary<Mobile.IDebugWebViewInfo[]> = {};
88

9-
constructor(protected $logger: ILogger) {
9+
constructor(protected $logger: ILogger,
10+
protected $hooksService: IHooksService) {
1011
super();
1112
}
1213

mobile/ios/device/ios-application-manager.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import * as net from "net";
22
import * as ref from "ref";
33
import * as os from "os";
44
import * as iOSProxyServices from "./ios-proxy-services";
5-
import {ApplicationManagerBase} from "../../application-manager-base";
6-
import {CoreTypes, GDBServer} from "./ios-core";
5+
import { hook } from "../../../helpers";
6+
import { ApplicationManagerBase } from "../../application-manager-base";
7+
import { CoreTypes, GDBServer } from "./ios-core";
78
import Future = require("fibers/future");
89

910
export class IOSApplicationManager extends ApplicationManagerBase {
@@ -12,6 +13,7 @@ export class IOSApplicationManager extends ApplicationManagerBase {
1213
private applicationsLiveSyncInfos: Mobile.ILiveSyncApplicationInfo[];
1314

1415
constructor(protected $logger: ILogger,
16+
protected $hooksService: IHooksService,
1517
private device: Mobile.IiOSDevice,
1618
private devicePointer: NodeBuffer,
1719
private $childProcess: IChildProcess,
@@ -24,7 +26,7 @@ export class IOSApplicationManager extends ApplicationManagerBase {
2426
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
2527
private $processService: IProcessService,
2628
private $options: ICommonOptions) {
27-
super($logger);
29+
super($logger, $hooksService);
2830
this.uninstallApplicationCallbackPtr = CoreTypes.am_device_mount_image_callback.toPointer(IOSApplicationManager.uninstallCallback);
2931
}
3032

@@ -43,6 +45,7 @@ export class IOSApplicationManager extends ApplicationManagerBase {
4345
}).future<string[]>()();
4446
}
4547

48+
@hook('install')
4649
public installApplication(packageFilePath: string): IFuture<void> {
4750
return (() => {
4851
let installationProxy = this.getInstallationProxy();
@@ -74,8 +77,8 @@ export class IOSApplicationManager extends ApplicationManagerBase {
7477
"ApplicationType": "User",
7578
"ReturnAttributes": [
7679
"CFBundleIdentifier",
77-
"IceniumLiveSyncEnabled",
78-
"configuration"
80+
"IceniumLiveSyncEnabled",
81+
"configuration"
7982
]
8083
}
8184
}).wait();
@@ -158,7 +161,7 @@ export class IOSApplicationManager extends ApplicationManagerBase {
158161
isLiveSyncSupported: app.IceniumLiveSyncEnabled,
159162
configuration: app.configuration,
160163
deviceIdentifier: this.device.deviceInfo.identifier
161-
}));
164+
}));
162165
this.applicationsLiveSyncInfos = this.applicationsLiveSyncInfos.concat(currentList);
163166
});
164167

mobile/ios/simulator/ios-simulator-application-manager.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {ApplicationManagerBase} from "../../application-manager-base";
22
import Future = require("fibers/future");
33
import * as path from "path";
44
import * as temp from "temp";
5+
import { hook } from "../../../helpers";
56

67
export class IOSSimulatorApplicationManager extends ApplicationManagerBase {
78
constructor(private iosSim: any,
@@ -11,14 +12,16 @@ export class IOSSimulatorApplicationManager extends ApplicationManagerBase {
1112
private $bplistParser: IBinaryPlistParser,
1213
private $iOSSimulatorLogProvider: Mobile.IiOSSimulatorLogProvider,
1314
private $deviceLogProvider: Mobile.IDeviceLogProvider,
14-
$logger: ILogger) {
15-
super($logger);
15+
$logger: ILogger,
16+
$hooksService: IHooksService) {
17+
super($logger, $hooksService);
1618
}
1719

1820
public getInstalledApplications(): IFuture<string[]> {
1921
return Future.fromResult(this.iosSim.getInstalledApplications(this.identifier));
2022
}
2123

24+
@hook('install')
2225
public installApplication(packageFilePath: string): IFuture<void> {
2326
return (() => {
2427
if (this.$fs.exists(packageFilePath).wait() && path.extname(packageFilePath) === ".zip") {

test/unit-tests/mobile/application-manager-base.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {Yok} from "../../../yok";
2-
import {assert} from "chai";
3-
import { CommonLoggerStub } from "../stubs";
1+
import { Yok } from "../../../yok";
2+
import { assert } from "chai";
3+
import { CommonLoggerStub, HooksServiceStub } from "../stubs";
44
import { ApplicationManagerBase } from "../../../mobile/application-manager-base";
55
import Future = require("fibers/future");
66

@@ -9,8 +9,8 @@ let currentlyAvailableAppsForDebugging: Mobile.IDeviceApplicationInformation[],
99
currentlyAvailableAppWebViewsForDebugging: IDictionary<Mobile.IDebugWebViewInfo[]>;
1010

1111
class ApplicationManager extends ApplicationManagerBase {
12-
constructor($logger: ILogger) {
13-
super($logger);
12+
constructor($logger: ILogger, $hooksService: IHooksService) {
13+
super($logger, $hooksService);
1414
}
1515

1616
public isLiveSyncSupported(appIdentifier: string): IFuture<boolean> {
@@ -57,6 +57,7 @@ class ApplicationManager extends ApplicationManagerBase {
5757
function createTestInjector(): IInjector {
5858
let testInjector = new Yok();
5959
testInjector.register("logger", CommonLoggerStub);
60+
testInjector.register("hooksService", HooksServiceStub);
6061
testInjector.register("applicationManager", ApplicationManager);
6162
return testInjector;
6263
}

test/unit-tests/stubs.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* tslint:disable:no-empty */
22

33
import * as util from "util";
4+
import Future = require("fibers/future");
45

56
export class CommonLoggerStub implements ILogger {
67
setLevel(level: string): void { }
@@ -64,3 +65,14 @@ export class ErrorsStub implements IErrors {
6465

6566
verifyHeap(message: string): void { }
6667
}
68+
69+
export class HooksServiceStub implements IHooksService {
70+
executeBeforeHooks(commandName: string): IFuture<void> {
71+
return Future.fromResult();
72+
}
73+
executeAfterHooks(commandName: string): IFuture<void> {
74+
return Future.fromResult();
75+
}
76+
77+
hookArgsName = "hookArgs";
78+
}

0 commit comments

Comments
 (0)