if (process.type === 'browser') { require('source-map-support').install(); }var log = require('common/utils/logger').debugLogger(__filename); var logError = require('common/utils/logger').errorLogger(__filename, false); var logFatal = require('common/utils/logger').errorLogger(__filename, true);'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _regenerator = require('babel-runtime/regenerator');

var _regenerator2 = _interopRequireDefault(_regenerator);

var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');

var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');

var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _launchd = require('launchd.plist');

var _launchd2 = _interopRequireDefault(_launchd);

var _fsExtraPromise = require('fs-extra-promise');

var _fsExtraPromise2 = _interopRequireDefault(_fsExtraPromise);

var _electron = require('electron');

var _path = require('path');

var _path2 = _interopRequireDefault(_path);

var _base = require('browser/components/auto-launcher/base');

var _base2 = _interopRequireDefault(_base);

var _files = require('common/utils/files');

var _files2 = _interopRequireDefault(_files);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var plistName = global.manifest.darwin.bundleId + '.plist';
var plistPath = _path2.default.join(_electron.app.getPath('home'), 'Library', 'LaunchAgents', plistName);

var DarwinAutoLauncher = function (_BaseAutoLauncher) {
  (0, _inherits3.default)(DarwinAutoLauncher, _BaseAutoLauncher);

  function DarwinAutoLauncher() {
    (0, _classCallCheck3.default)(this, DarwinAutoLauncher);
    return (0, _possibleConstructorReturn3.default)(this, (DarwinAutoLauncher.__proto__ || (0, _getPrototypeOf2.default)(DarwinAutoLauncher)).apply(this, arguments));
  }

  (0, _createClass3.default)(DarwinAutoLauncher, [{
    key: 'enable',
    value: function () {
      var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() {
        var _this2 = this;

        return _regenerator2.default.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                log('enabling darwin auto-launch');
                log('creating login plist');
                _context.next = 4;
                return _files2.default.replaceFile(plistPath, function () {
                  return _fsExtraPromise2.default.writeFileAsync(plistPath, _this2.buildPlist(), 'utf8');
                });

              case 4:
              case 'end':
                return _context.stop();
            }
          }
        }, _callee, this);
      }));

      function enable() {
        return _ref.apply(this, arguments);
      }

      return enable;
    }()
  }, {
    key: 'disable',
    value: function () {
      var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2() {
        return _regenerator2.default.wrap(function _callee2$(_context2) {
          while (1) {
            switch (_context2.prev = _context2.next) {
              case 0:
                log('disabling linux auto-launch');
                log('removing login plist');
                _context2.next = 4;
                return _fsExtraPromise2.default.removeAsync(plistPath);

              case 4:
              case 'end':
                return _context2.stop();
            }
          }
        }, _callee2, this);
      }));

      function disable() {
        return _ref2.apply(this, arguments);
      }

      return disable;
    }()
  }, {
    key: 'isEnabled',
    value: function () {
      var _ref3 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3() {
        return _regenerator2.default.wrap(function _callee3$(_context3) {
          while (1) {
            switch (_context3.prev = _context3.next) {
              case 0:
                log('checking darwin auto-launch');
                _context3.next = 3;
                return _files2.default.isFileExists(plistPath);

              case 3:
              case 'end':
                return _context3.stop();
            }
          }
        }, _callee3, this);
      }));

      function isEnabled() {
        return _ref3.apply(this, arguments);
      }

      return isEnabled;
    }()
  }, {
    key: 'buildPlist',
    value: function buildPlist() {
      var plist = new _launchd2.default();
      plist.setLabel(global.manifest.darwin.bundleId);
      plist.setProgram(_electron.app.getPath('exe'));
      plist.setProgramArgs(['--os-startup']);
      plist.setRunAtLoad(true);
      return plist.build();
    }
  }]);
  return DarwinAutoLauncher;
}(_base2.default);

exports.default = DarwinAutoLauncher;
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImJyb3dzZXIvY29tcG9uZW50cy9hdXRvLWxhdW5jaGVyL2ltcGwtZGFyd2luLmpzIl0sIm5hbWVzIjpbInBsaXN0TmFtZSIsImdsb2JhbCIsIm1hbmlmZXN0IiwiZGFyd2luIiwiYnVuZGxlSWQiLCJwbGlzdFBhdGgiLCJqb2luIiwiZ2V0UGF0aCIsIkRhcndpbkF1dG9MYXVuY2hlciIsImxvZyIsInJlcGxhY2VGaWxlIiwid3JpdGVGaWxlQXN5bmMiLCJidWlsZFBsaXN0IiwicmVtb3ZlQXN5bmMiLCJpc0ZpbGVFeGlzdHMiLCJwbGlzdCIsInNldExhYmVsIiwic2V0UHJvZ3JhbSIsInNldFByb2dyYW1BcmdzIiwic2V0UnVuQXRMb2FkIiwiYnVpbGQiXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFBQTs7OztBQUNBOzs7O0FBQ0E7O0FBQ0E7Ozs7QUFFQTs7OztBQUNBOzs7Ozs7QUFFQSxJQUFNQSxZQUFZQyxPQUFPQyxRQUFQLENBQWdCQyxNQUFoQixDQUF1QkMsUUFBdkIsR0FBa0MsUUFBcEQ7QUFDQSxJQUFNQyxZQUFZLGVBQUtDLElBQUwsQ0FBVSxjQUFJQyxPQUFKLENBQVksTUFBWixDQUFWLEVBQStCLFNBQS9CLEVBQTBDLGNBQTFDLEVBQTBEUCxTQUExRCxDQUFsQjs7SUFFTVEsa0I7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUdGQyxvQkFBSSw2QkFBSjtBQUNBQSxvQkFBSSxzQkFBSjs7dUJBQ00sZ0JBQU1DLFd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