"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var application_manager_base_1 = require("../../application-manager-base");
var Future = require("fibers/future");
var IOSSimulatorApplicationManager = (function (_super) {
    __extends(IOSSimulatorApplicationManager, _super);
    function IOSSimulatorApplicationManager(iosSim, identifier, $options) {
        _super.call(this);
        this.iosSim = iosSim;
        this.identifier = identifier;
        this.$options = $options;
        this.deviceLoggingStarted = false;
    }
    IOSSimulatorApplicationManager.prototype.getInstalledApplications = function () {
        return Future.fromResult(this.iosSim.getInstalledApplications(this.identifier));
    };
    IOSSimulatorApplicationManager.prototype.installApplication = function (packageFilePath) {
        return this.iosSim.installApplication(this.identifier, packageFilePath);
    };
    IOSSimulatorApplicationManager.prototype.uninstallApplication = function (appIdentifier) {
        return this.iosSim.uninstallApplication(this.identifier, appIdentifier);
    };
    IOSSimulatorApplicationManager.prototype.startApplication = function (appIdentifier) {
        var _this = this;
        return (function () {
            var launchResult = _this.iosSim.startApplication(_this.identifier, appIdentifier).wait();
            if (!_this.$options.justlaunch && !_this.deviceLoggingStarted) {
                _this.deviceLoggingStarted = true;
                _this.iosSim.printDeviceLog(_this.identifier, launchResult);
            }
        }).future()();
    };
    IOSSimulatorApplicationManager.prototype.stopApplication = function (cfBundleExecutable) {
        return this.iosSim.stopApplication(this.identifier, cfBundleExecutable);
    };
    IOSSimulatorApplicationManager.prototype.canStartApplication = function () {
        return true;
    };
    return IOSSimulatorApplicationManager;
})(application_manager_base_1.ApplicationManagerBase);
exports.IOSSimulatorApplicationManager = IOSSimulatorApplicationManager;
