简体   繁体   English

如何调试带有电子封装的节点中运行的代码

[英]How to debug code running in node with electron package

I have an application using Angular 5, node-adodb and Electron (see package.json below) 我有一个使用Angular 5,node-adodb和Electron的应用程序(请参阅下面的package.json)

When running Angular and Electron in development mode, everything is working fine. 在开发模式下运行Angular和Electron时,一切正常。 When I cal the Electron 'ipcMain.on('select'...) (see below), the SQL 'select' is done to the database, then returns to my Angular application. 当我校准Electron'ipcMain.on('select'...)(见下文)时,对数据库执行SQL'select',然后返回到我的Angular应用程序。

When I package everything withing an Electron package, the same SQL 'select' does not return at all. 当我用Electron软件包打包所有内容时,相同的SQL'select'根本不会返回。 Does not got to 'then' and not to 'catch'. 不必“那么”而不是“抓住”。

How can I debug that situation? 我该如何调试这种情况? You have a solution to suggest to fix that? 您有解决方案建议解决该问题?

Thanks in advance. 提前致谢。

main.js main.js

ipcMain.on('select', (event, type, sql) => {

    const reply = 'reply-select-' + type;

    // Code run until here

    connection = ADODB.open(databasePath);

    // Code run until here

    connection
      .query(sql)
      .then((data) => {

        // Code does not go here

        event.sender.send(reply, { status: 0, message: '', data: data });
      })
      .catch((error) => {

        // Code does not go here

        event.sender.send(reply, { status: 1, message: error.message, data: {} });
      });
  });

package.json package.json

"scripts": {
    "ng": "ng",
    "build-electron": "ng build --base-href . && cp src/main.js dist",
    "package-win": "npm run build-electron && electron-packager . --overwrite --asar=true --platform=win32 --arch=ia32 --prune=true --version-string.ProductName=\"MyApp\" --out=release-builds"
}
"dependencies": {
    "@angular/animations": "~5.0.0",
    "@angular/common": "~5.0.0",
    "@angular/compiler": "~5.0.0",
    "@angular/core": "~5.0.0",
    "@angular/forms": "~5.0.0",
    "@angular/http": "~5.0.0",
    "@angular/platform-browser": "~5.0.0",
    "@angular/platform-browser-dynamic": "~5.0.0",
    "@angular/router": "~5.0.0",
    "@clr/angular": "^0.11.0",
    "@clr/icons": "^0.11.0",
    "@clr/ui": "^0.11.0",
    "@ngforage/ngforage-ng5": "^1.0.4",
    "@ngx-translate/core": "^8.0.0",
    "@ngx-translate/http-loader": "^2.0.1",
    "@webcomponents/custom-elements": "^1.0.6",
    "core-js": "^2.5.3",
    "mutationobserver-shim": "^0.3.2",
    "ngx-electron": "^1.0.4",
    "node-adodb": "^4.0.6",
    "rxjs": "^5.5.6",
    "zone.js": "^0.8.17"
  },
  "devDependencies": {
    "@angular/cli": "^1.6.4",
    "@angular/compiler-cli": "~5.0.0",
    "@types/jasmine": "2.8.3",
    "@types/node": "^8.5.8",
    "bootstrap": "4.0.0-alpha.5",
    "codelyzer": "~4.0.2",
    "concurrently": "^3.5.1",
    "cpx": "^1.5.0",
    "electron": "^1.7.10",
    "electron-packager": "^10.1.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.3.0",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.3.0",
    "tslint": "~5.7.0",
    "typescript": "~2.5.2"
  }

Why are you using IPC and the main process to do this? 您为什么要使用IPC及其主要过程? The full features of node are accessible in the renderer process which can be debugged though the dev tools. 节点的全部功能都可以在渲染器过程中访问,可以通过开发工具进行调试。

The main process should only be used for creating BrowserWindows and for accessing electron APIs which are marked in the docs as only accessible via the main process. 主要过程仅应用于创建BrowserWindows和访问在文档中标记为只能通过主要过程访问的电子API。

Check out this article for more details of the differences between the main/renderer and what they are used for. 请查看本文,以获取有关主/渲染器及其用途之间差异的更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM