'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;

require('colors');

var _electron = require('electron');

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);
  return console.log("[INFO] " + str);
}

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

function error(str) {
  str = stringify(str);
  return console.error(("[ERROR] " + str).bold.red);
}
function setBounds(options) {
  return global.mainWindow.setBounds(options);
}
function getBounds() {
  return global.mainWindow.getBounds();
}
function stopFileNavigate(id) {
  _electron.webContents.fromId(id).addListener('will-navigate', (e, url) => {
    if (url.startsWith('file')) {
      e.preventDefault();
    }
  });
}
function stopNavigateAndNewWindow(id) {
  _electron.webContents.fromId(id).addListener('will-navigate', (e, url) => {
    e.preventDefault();
  });
  _electron.webContents.fromId(id).addListener('new-window', (e, url) => {
    e.preventDefault();
  });
}