【杂记】Electron

91 阅读1分钟

环境判断

import { ipcRenderer as ipcRendererFn } from 'electron'//浏览器环境执行到这会报一次错-不功能功能

/**
 * 判断是什么环境 e 还是 w
 * 判断是否是e环境
 * 慎用:e环境子窗口会被识别为w环境
 * @returns 
 */
export const tfE = () => {
    let tfElectron: any
    try {
        //环境判断
        tfElectron = window && window.process && window.process.versions && window.process.versions['electron'];
    } catch (error) { }
    if (tfElectron) {
        return true
    } else {
        return false
    }
}

export const ipcRenderer = ipcRendererFn