当egg业务中需要调用electron相关api时,可在app/service模块,调用this.ipcCall()方法。如:

    1. # 打开文件夹
    2. // app/service/example.js
    3. # egg服务调用electron功能
    4. async openLocalDir(dir) {
    5. await this.ipcCall('example.openDir', dir);
    6. return true;
    7. }
    8. // electron/apis/example.js
    9. exports.openDir = function (dir = '') {
    10. if (!dir) {
    11. return false;
    12. }
    13. dir = getElectronPath(dir);
    14. shell.openPath(dir);
    15. return true;
    16. }