'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.remoteStringify = undefined;
exports.log = log;
exports.warn = warn;
exports.error = error;
exports.setBounds = setBounds;
exports.getBounds = getBounds;
exports.stopFileNavigate = stopFileNavigate;
exports.stopNavigateAndNewWindow = stopNavigateAndNewWindow;

var _chalk = require('chalk');

var _chalk2 = _interopRequireDefault(_chalk);

var _electron = require('electron');

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

const stringify = str => {
  if (typeof str === 'string') {
    return str;
  }
  if (str.toString().startsWith('[object ')) {
    str = JSON.stringify(str);
  } else {
    str = str.toString();
  }
  return str;
};

const remoteStringify = exports.remoteStringify = JSON.stringify;

function log(str) {
  str = stringify(str);
  // eslint-disable-next-line no-console
  return console.log("[INFO] " + str);
}

function warn(str) {
  str = stringify(str);
  return console.warn(_chalk2.default.yellow("[WARN] " + str));
}

function error(str) {
  str = stringify(str);
  return console.error(_chalk2.default.red.bold("[ERROR] " + str));
}
function setBounds(options) {
  return global.mainWindow.setBounds(options);
}
function getBounds() {
  return global.mainWindow.getBounds();
}

function _ref(e, url) {
  if (url.startsWith('file')) {
    e.preventDefault();
  }
}

function stopFileNavigate(id) {
  _electron.webContents.fromId(id).addListener('will-navigate', _ref);
}

function _ref2(e, url) {
  e.preventDefault();
}

function _ref3(e, url) {
  e.preventDefault();
}

function stopNavigateAndNewWindow(id) {
  _electron.webContents.fromId(id).addListener('will-navigate', _ref2);
  _electron.webContents.fromId(id).addListener('new-window', _ref3);
}