<commit_before>import { ApplicationManagerBase } from "../../application-manager-base";
import * as path from "path";
import * as temp from "temp";
import { hook } from "../../../helpers";

export class IOSSimulatorApplicationManager extends ApplicationManagerBase {
	constructor(private iosSim: any,
		private identifier: string,
		private $options: ICommonOptions,
		private $fs: IFileSystem,
		private $bplistParser: IBinaryPlistParser,
		private $iOSSimulatorLogProvider: Mobile.IiOSSimulatorLogProvider,
		private $deviceLogProvider: Mobile.IDeviceLogProvider,
		$logger: ILogger,
		$hooksService: IHooksService) {
		super($logger, $hooksService);
	}

	public async getInstalledApplications(): Promise<string[]> {
		return this.iosSim.getInstalledApplications(this.identifier);
	}

	@hook('install')
	public async installApplication(packageFilePath: string): Promise<void> {
		if (this.$fs.exists(packageFilePath) && path.extname(packageFilePath) === ".zip") {
			temp.track();
			let dir = temp.mkdirSync("simulatorPackage");
			await this.$fs.unzip(packageFilePath, dir);
			let app = _.find(this.$fs.readDirectory(dir), directory => path.extname(directory) === ".app");
			if (app) {
				packageFilePath = path.join(dir, app);
			}
		}

		this.iosSim.installApplication(this.identifier, packageFilePath);
	}

	public async uninstallApplication(appIdentifier: string): Promise<void> {
		return this.iosSim.uninstallApplication(this.identifier, appIdentifier);
	}

	public async startApplication(appIdentifier: string): Promise<void> {
		let launchResult = this.iosSim.startApplication(this.identifier, appIdentifier);

		if (!this.$options.justlaunch) {
			let pid = launchResult.split(":")[1].trim();
			this.$deviceLogProvider.setApplicationPidForDevice(this.identifier, pid);
			this.$iOSSimulatorLogProvider.startLogProcess(this.identifier);
		}
	}

	public async stopApplication(appIdentifier: string, appName: string): Promise<void> {
		return this.iosSim.stopApplication(this.identifier, appIdentifier, appName);
	}

	public canStartApplication(): boolean {
		return true;
	}

	public async getApplicationInfo(applicationIdentifier: string): Promise<Mobile.IApplicationInfo> {
		let result: Mobile.IApplicationInfo = null,
			plistContent = await this.getParsedPlistContent(applicationIdentifier);

		if (plistContent) {
			result = {
				applicationIdentifier,
				deviceIdentifier: this.identifier,
				configuration: plistContent && plistContent.configuration
			};
		}

		return result;
	}

	public async isLiveSyncSupported(appIdentifier: string): Promise<boolean> {<commit_msg>Always set application pid.<commit_after>import { ApplicationManagerBase } from "../../application-manager-base";
import * as path from "path";
import * as temp from "temp";
import { hook } from "../../../helpers";

export class IOSSimulatorApplicationManager extends ApplicationManagerBase {
	constructor(private iosSim: any,
		private identifier: string,
		private $options: ICommonOptions,
		private $fs: IFileSystem,
		private $bplistParser: IBinaryPlistParser,
		private $iOSSimulatorLogProvider: Mobile.IiOSSimulatorLogProvider,
		private $deviceLogProvider: Mobile.IDeviceLogProvider,
		$logger: ILogger,
		$hooksService: IHooksService) {
		super($logger, $hooksService);
	}

	public async getInstalledApplications(): Promise<string[]> {
		return this.iosSim.getInstalledApplications(this.identifier);
	}

	@hook('install')
	public async installApplication(packageFilePath: string): Promise<void> {
		if (this.$fs.exists(packageFilePath) && path.extname(packageFilePath) === ".zip") {
			temp.track();
			let dir = temp.mkdirSync("simulatorPackage");
			await this.$fs.unzip(packageFilePath, dir);
			let app = _.find(this.$fs.readDirectory(dir), directory => path.extname(directory) === ".app");
			if (app) {
				packageFilePath = path.join(dir, app);
			}
		}

		this.iosSim.installApplication(this.identifier, packageFilePath);
	}

	public async uninstallApplication(appIdentifier: string): Promise<void> {
		return this.iosSim.uninstallApplication(this.identifier, appIdentifier);
	}

	public async startApplication(appIdentifier: string): Promise<void> {
		let launchResult = this.iosSim.startApplication(this.identifier, appIdentifier);
		let pid = launchResult.split(":")[1].trim();
		this.$deviceLogProvider.setApplicationPidForDevice(this.identifier, pid);

		if (!this.$options.justlaunch) {
			this.$iOSSimulatorLogProvider.startLogProcess(this.identifier);
		}
	}

	public async stopApplication(appIdentifier: string, appName: string): Promise<void> {
		return this.iosSim.stopApplication(this.identifier, appIdentifier, appName);
	}

	public canStartApplication(): boolean {
		return true;
	}

	public async getApplicationInfo(applicationIdentifier: string): Promise<Mobile.IApplicationInfo> {
		let result: Mobile.IApplicationInfo = null,
			plistContent = await this.getParsedPlistContent(applicationIdentifier);

		if (plistContent) {
			result = {
				applicationIdentifier,
				deviceIdentifier: this.identifier,
				configuration: plistContent && plistContent.configuration
			};
		}

		return result;
	}

	public async isLiveSyncSupported(appIdentifier: string): Promise<boolean> {
{'fraction_non_alphanumeric': 0.12043795620437957, 'fraction_numerical': 0.000384172109104879, 'mean_word_length': 5.599493029150824, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '253687', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1463, 'n_words': 313}