electron使用nodejs组件

electron yekong 600℃

electron 开发时,使用nodejs的命令和组件要更方便一些,但是在html无法使用nodejs,需要通过通信的方式进行调用,记录一下大概流程,以便查阅。

nodeJs 创建down.js文件

const loudness = require("loudness");
exports.getSound = async (channel, args) => {
    let val = await loudness.getVolume();
    channel.returnValue = {
        status: true,
        data: val,
    };
};

mainjs

import osObj from '../../model/down'
ipcMain.on("getSound", osObj.getSound);

html调用

let soundObj = ipcRenderer.sendSync("getSound", {});
console.log(soundObj)
喜欢 (0)