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

// const p = (Math.random() * 1e6) | 0;
// contextBridge.exposeInMainWorld(`alert_${p}`, (msg) => ipcRenderer.send('ipc-alert', msg));
//
// let script = document.createElement('script');
// script.text = `window.alert=s=>alert_${p}(s); window.confirm=s=>!1; window.prompt=s=>null;`;
// document.append(script);

contextBridge.exposeInMainWorld('electronAPI', {
    openWindow: (url) => ipcRenderer.send('openWindow', url),
    openWindowSelf: (url) => ipcRenderer.send('openWindowSelf', url),
    focusWindow: () => ipcRenderer.send('focusWindow'),
    getWinId: () => {
        const id = ipcRenderer.sendSync('getWinId');
        return id;
    },
});
