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


// 将以下内容挂载在windows下，渲染进程可直接访问！
contextBridge.exposeInMainWorld('versions', {
    node: () => process.versions.node,
    chrome: () => process.versions.chrome,
    electron: () => process.versions.electron,
    ping: () => ipcRenderer.invoke('ping'),
    // 能暴露的不仅仅是函数，我们还可以暴露变量
})
// 直接挂载ipcRenderer.invoke给windows
contextBridge.exposeInMainWorld('ipcRenderer_invoke', ipcRenderer.invoke)

window.addEventListener('DOMContentLoaded', () => {
    const replaceText = (selector, text) => {
        const element = document.getElementById(selector)
        if (element) element.innerText = text
    }

    for (const dependency of ['chrome', 'node', 'electron']) {
        replaceText(`${dependency}-version`, process.versions[dependency])
    }
})
