当egg业务中需要调用electron相关api时,可在app/service模块,调用this.ipcCall()方法。如:
# 打开文件夹
// app/service/example.js
# egg服务调用electron功能
async openLocalDir(dir) {
await this.ipcCall('example.openDir', dir);
return true;
}
// electron/apis/example.js
exports.openDir = function (dir = '') {
if (!dir) {
return false;
}
dir = getElectronPath(dir);
shell.openPath(dir);
return true;
}