|
1 | 1 | import { IOSDeviceLib as IOSDeviceLibModule } from "ios-device-lib"; |
2 | 2 | import { cache } from "../../../decorators"; |
| 3 | +import { DEVICE_LOG_EVENT_NAME } from "../../../constants"; |
3 | 4 | import assert = require("assert"); |
| 5 | +import { EventEmitter } from "events"; |
4 | 6 |
|
5 | | -export class IOSDeviceOperations implements IIOSDeviceOperations, IDisposable { |
| 7 | +export class IOSDeviceOperations extends EventEmitter implements IIOSDeviceOperations, IDisposable { |
6 | 8 | public isInitialized: boolean; |
7 | 9 | public shouldDispose: boolean; |
8 | 10 | private deviceLib: IOSDeviceLib.IOSDeviceLib; |
9 | 11 |
|
10 | 12 | constructor(private $logger: ILogger, |
11 | 13 | private $processService: IProcessService) { |
| 14 | + super(); |
| 15 | + |
12 | 16 | this.isInitialized = false; |
13 | 17 | this.shouldDispose = true; |
14 | 18 | this.$processService.attachToProcessExitSignals(this, () => { |
@@ -67,15 +71,13 @@ export class IOSDeviceOperations implements IIOSDeviceOperations, IDisposable { |
67 | 71 | } |
68 | 72 | } |
69 | 73 |
|
70 | | - public startDeviceLog(deviceIdentifier: string, printLogFunction: (response: IOSDeviceLib.IDeviceLogData) => void): void { |
| 74 | + public startDeviceLog(deviceIdentifier: string): void { |
71 | 75 | this.assertIsInitialized(); |
72 | 76 | this.setShouldDispose(false); |
73 | 77 |
|
74 | 78 | this.$logger.trace(`Printing device log for device with identifier: ${deviceIdentifier}.`); |
75 | 79 |
|
76 | | - this.deviceLib.on("deviceLogData", (response: IOSDeviceLib.IDeviceLogData) => { |
77 | | - printLogFunction(response); |
78 | | - }); |
| 80 | + this.attacheDeviceLogDataHandler(); |
79 | 81 |
|
80 | 82 | this.deviceLib.startDeviceLog([deviceIdentifier]); |
81 | 83 | } |
@@ -230,6 +232,13 @@ export class IOSDeviceOperations implements IIOSDeviceOperations, IDisposable { |
230 | 232 | private assertIsInitialized(): void { |
231 | 233 | assert.ok(this.isInitialized, "iOS device operations not initialized."); |
232 | 234 | } |
| 235 | + |
| 236 | + @cache() |
| 237 | + private attacheDeviceLogDataHandler(): void { |
| 238 | + this.deviceLib.on(DEVICE_LOG_EVENT_NAME, (response: IOSDeviceLib.IDeviceLogData) => { |
| 239 | + this.emit(DEVICE_LOG_EVENT_NAME, response); |
| 240 | + }); |
| 241 | + } |
233 | 242 | } |
234 | 243 |
|
235 | 244 | $injector.register("iosDeviceOperations", IOSDeviceOperations); |
0 commit comments