const { contextBridge, ipcRenderer } = require('electron');
const rust = require('rust_native_module');

contextBridge.exposeInMainWorld('electron', {
  ipcRenderer: {
    send(channel, data) {
      const validChannels = ['beat-tracking'];
      if (validChannels.includes(channel)) {
        ipcRenderer.send(channel, data);
      }
    },
    on(channel, func) {
      const validChannels = ['tick', 'beat-tracking'];
      if (validChannels.includes(channel)) {
        // Deliberately strip event as it includes `sender`
        ipcRenderer.on(channel, (event, ...args) => func(...args));
      }
    },
  },
  rustding: rust
});
