const { contextBridge, ipcRenderer } = require("electron");

contextBridge.exposeInMainWorld("deployMaster", {
  listTargets: () => ipcRenderer.invoke("targets:list"),
  chooseZip: options => ipcRenderer.invoke("dialog:zip", options),
  startDeploy: payload => ipcRenderer.invoke("deploy:start", payload),
  stopDeploy: () => ipcRenderer.invoke("deploy:stop"),
  onDeployEvent: callback => {
    const listener = (_, payload) => callback(payload);
    ipcRenderer.on("deploy:event", listener);
    return () => ipcRenderer.removeListener("deploy:event", listener);
  }
});
