'use strict';

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

var _electron = require('electron');

var _config = require('./config');

var _config2 = _interopRequireDefault(_config);

var _window = require('./window');

var _window2 = _interopRequireDefault(_window);

var _debug = require('./debug');

var _debug2 = _interopRequireDefault(_debug);

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

const registerShortcut = (acc, desc, func) => {
  _debug2.default.log(`Registering shortcut: ${acc}\t=> ${desc}`);
  try {
    _electron.globalShortcut.register(acc, func);
    return true;
  } catch (err) {
    console.error(`Failed to register shortcut[${acc}]: ${err}`);
    return false;
  }
};

const registerBossKey = () => {
  const accelerator = _config2.default.get('poi.shortcut.bosskey', '');
  if (accelerator) if (!registerShortcut(accelerator, 'Boss Key', _window2.default.toggleAllWindowsVisibility)) _config2.default.set('poi.shortcut.bosskey', '');
};
const registerDevToolShortcut = () => {
  const accelerator = 'Ctrl+Shift+I';
  registerShortcut(accelerator, 'Open Focused Window Dev Tools', _window2.default.openFocusedWindowDevTools);
};

exports.default = {
  register: () => {
    if (process.platform !== 'darwin') {
      registerBossKey();
    }
    registerDevToolShortcut();
  },
  unregister: () => {
    _electron.globalShortcut.unregisterAll();
  }
};
module.exports = exports['default'];