if (process.type === 'browser') { try { require('source-map-support').install(); } catch(ignored) {} }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 _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');

var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);

var _entries = require('babel-runtime/core-js/object/entries');

var _entries2 = _interopRequireDefault(_entries);

var _getIterator2 = require('babel-runtime/core-js/get-iterator');

var _getIterator3 = _interopRequireDefault(_getIterator2);

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 _events = require('events');

var _events2 = _interopRequireDefault(_events);

var _electron = require('electron');

var _autoUpdater = require('browser/components/auto-updater');

var _autoUpdater2 = _interopRequireDefault(_autoUpdater);

var _utils = require('browser/menus/utils');

var _main = require('browser/menus/main');

var _main2 = _interopRequireDefault(_main);

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

var MainMenuManager = function (_EventEmitter) {
  (0, _inherits3.default)(MainMenuManager, _EventEmitter);

  function MainMenuManager() {
    (0, _classCallCheck3.default)(this, MainMenuManager);

    var _this = (0, _possibleConstructorReturn3.default)(this, (MainMenuManager.__proto__ || (0, _getPrototypeOf2.default)(MainMenuManager)).call(this));

    _this.cfuVisibleItem = null;
    return _this;
  }

  (0, _createClass3.default)(MainMenuManager, [{
    key: 'create',
    value: function create() {
      if (!this.menu) {
        this.menu = _electron.Menu.buildFromTemplate((0, _main2.default)());
        log('app menu created');
      } else {
        log('app menu already created');
      }
    }
  }, {
    key: 'setDefault',
    value: function setDefault() {
      if (this.menu) {
        _electron.Menu.setApplicationMenu(this.menu);
        log('app menu set');
      } else {
        logError(new Error('menu not created'));
      }
    }
  }, {
    key: 'setAutoUpdaterListeners',
    value: function setAutoUpdaterListeners() {
      var _arguments = arguments,
          _this2 = this;

      if (!this.cfuVisibleItem) {
        this.cfuVisibleItem = (0, _utils.findItemById)(this.menu.items, 'cfu-check-for-update');
      }

      var eventToIdMap = {
        'error': 'cfu-check-for-update',
        'checking-for-update': 'cfu-checking-for-update',
        'update-available': 'cfu-update-available',
        'update-not-available': 'cfu-check-for-update',
        'update-downloaded': 'cfu-update-downloaded'
      };

      var _iteratorNormalCompletion = true;
      var _didIteratorError = false;
      var _iteratorError = undefined;

      try {
        var _loop = function _loop() {
          var _step$value = (0, _slicedToArray3.default)(_step.value, 2),
              eventName = _step$value[0],
              itemId = _step$value[1];

          _autoUpdater2.default.on(eventName, function () {
            log.apply(undefined, ['auto updater on:', eventName, 'params:'].concat(Array.prototype.slice.call(_arguments)));
            _this2.cfuVisibleItem.visible = false;
            _this2.cfuVisibleItem = (0, _utils.findItemById)(_this2.menu.items, itemId);
            _this2.cfuVisibleItem.visible = true;
          });
        };

        for (var _iterator = (0, _getIterator3.default)((0, _entries2.default)(eventToIdMap)), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
          _loop();
        }
      } catch (err) {
        _didIteratorError = true;
        _iteratorError = err;
      } finally {
        try {
          if (!_iteratorNormalCompletion && _iterator.return) {
            _iterator.return();
          }
        } finally {
          if (_didIteratorError) {
            throw _iteratorError;
          }
        }
      }
    }
  }, {
    key: 'windowSpecificItemsEnabled',
    value: function windowSpecificItemsEnabled(enabled) {
      var items = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.menu.items;
      var _iteratorNormalCompletion2 = true;
      var _didIteratorError2 = false;
      var _iteratorError2 = undefined;

      try {
        for (var _iterator2 = (0, _getIterator3.default)(items), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
          var item = _step2.value;

          if (item.needsWindow) {
            item.enabled = enabled;
          } else if (item.submenu) {
            this.windowSpecificItemsEnabled(enabled, item.submenu.items);
          }
        }
      } catch (err) {
        _didIteratorError2 = true;
        _iteratorError2 = err;
      } finally {
        try {
          if (!_iteratorNormalCompletion2 && _iterator2.return) {
            _iterator2.return();
          }
        } finally {
          if (_didIteratorError2) {
            throw _iteratorError2;
          }
        }
      }
    }
  }]);
  return MainMenuManager;
}(_events2.default);

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