console.log("Running preloader!");
const { contextBridge, ipcRenderer } = require("electron");
//const log = require("electron-log");

//ipcRenderer.removeAllListeners();

contextBridge.exposeInMainWorld("logger", {
  info: (...msg) => {
    console.log(...msg);
  },
  debug: (...msg) => {
    console.log(...msg);
  },
  warn: (...msg) => {
    console.log(...msg);
  },
  error: (...msg) => {
    console.log(...msg);
  },
  silly: (...msg) => {
    console.log(...msg);
  }
});

contextBridge.exposeInMainWorld("ipcRenderer", {
  send: (channel, data) => {
    //    whitelist channels
    // let validChannels = ["toMain"];
    // if (validChannels.includes(channel)) {
    //  log.info("[Main] ipcRenderer Send", channel);
    ipcRenderer.send(channel, data);
    //}
  },
  on: (channel, func) => {
    // let validChannels = ["fromMain"];
    // if (validChannels.includes(channel)) {
    //  Deliberately strip event as it includes `sender`
    ipcRenderer.on(
      channel,
      func
      ///(event, ...args) => func(...args)
    );
    // }
  },
  invoke: (channel, data) => {
    return ipcRenderer.invoke(channel, data);
  },
  removeAllListeners: (...channels) => {
    // let validChannels = ["fromMain"];
    // if (validChannels.includes(channel)) {
    // Deliberately strip event as it includes `sender`
    ipcRenderer.removeAllListeners(...channels);
    // }
  }
});
