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

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

contextBridge.exposeInMainWorld("ipcRenderer", {
  send: (channel, data) => {
    //    whitelist channels
    // let validChannels = ["toMain"];
    // if (validChannels.includes(channel)) {
    console.log("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)
    );
    // }
  },
  removeAllListeners: (...channels) => {
    // let validChannels = ["fromMain"];
    // if (validChannels.includes(channel)) {
    // Deliberately strip event as it includes `sender`
    ipcRenderer.removeAllListeners(...channels);
    // }
  },
});
