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 _promisifyEs = require('promisify-es6');

var _promisifyEs2 = _interopRequireDefault(_promisifyEs);

var _winreg = require('winreg');

var _winreg2 = _interopRequireDefault(_winreg);

var _filePaths = require('common/utils/file-paths');

var _filePaths2 = _interopRequireDefault(_filePaths);

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

var _base2 = _interopRequireDefault(_base);

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

var REG_KEY = new _winreg2.default({
  hive: _winreg2.default.HKCU,
  key: '\\Software\\Microsoft\\Windows\\CurrentVersion\\Run'
});

var setAsync = (0, _promisifyEs2.default)(REG_KEY.set, { context: REG_KEY });
var removeAsync = (0, _promisifyEs2.default)(REG_KEY.remove, { context: REG_KEY });
var keyExistsAsync = (0, _promisifyEs2.default)(REG_KEY.keyExists, { context: REG_KEY });

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

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

  (0, _createClass3.default)(Win32AutoLauncher, [{
    key: 'enable',
    value: function () {
      var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() {
        var updateExePath, cmd;
        return _regenerator2.default.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                updateExePath = _filePaths2.default.getSquirrelUpdateExePath();
                cmd = ['"' + updateExePath + '"', '--processStart', '"' + global.manifest.productName + '.exe"', '--process-start-args', '"--os-startup"'].join(' ');


                log('setting registry key for', global.manifest.productName, 'value', cmd);
                _context.next = 5;
                return setAsync(global.manifest.productName, _winreg2.default.REG_SZ, cmd);

              case 5:
              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() {
        var notFoundMsg, notFoundErr, knownError;
        return _regenerator2.default.wrap(function _callee2$(_context2) {
          while (1) {
            switch (_context2.prev = _context2.next) {
              case 0:
                log('removing registry key for', global.manifest.productName);
                _context2.prev = 1;
                _context2.next = 4;
                return removeAsync(global.manifest.productName);

              case 4:
                _context2.next = 13;
                break;

              case 6:
                _context2.prev = 6;
                _context2.t0 = _context2['catch'](1);
                notFoundMsg = 'The system was unable to find the specified registry key or value.';
                notFoundErr = _context2.t0.message && _context2.t0.message.includes(notFoundMsg);
                knownError = notFoundErr;

                if (knownError) {
                  _context2.next = 13;
                  break;
                }

                throw _context2.t0;

              case 13:
              case 'end':
                return _context2.stop();
            }
          }
        }, _callee2, this, [[1, 6]]);
      }));

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

      return disable;
    }()
  }, {
    key: 'isEnabled',
    value: function () {
      var _ref3 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3() {
        var exists;
        return _regenerator2.default.wrap(function _callee3$(_context3) {
          while (1) {
            switch (_context3.prev = _context3.next) {
              case 0:
                log('querying registry key for', global.manifest.productName);
                _context3.next = 3;
                return keyExistsAsync(global.manifest.productName);

              case 3:
                exists = _context3.sent;

                log('registry value for', global.manifest.productName, 'is', exists ? 'enabled' : 'disabled');
                return _context3.abrupt('return', exists);

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

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

      return isEnabled;
    }()
  }]);
  return Win32AutoLauncher;
}(_base2.default);

exports.default = Win32AutoLauncher;
//# sourceMappingURL=data:application/json;charset=utf8;base64, 
