"use strict";

exports.__esModule = true;
exports.log = log;
exports.warn = warn;
exports.error = error;
exports.setBounds = setBounds;
exports.getBounds = getBounds;
exports.stopFileNavigate = stopFileNavigate;
exports.stopNavigateAndNewWindow = stopNavigateAndNewWindow;
exports.remoteStringify = void 0;

var _chalk = _interopRequireDefault(require("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 = JSON.stringify;
exports.remoteStringify = remoteStringify;

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(_chalk.default.yellow("[WARN] " + str));
}

function error(str) {
  str = stringify(str);
  return console.error(_chalk.default.red.bold("[ERROR] " + str));
}

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();
  });
}