电子窗口不会打开,但不会显示任何错误

时间:2019-05-08 03:25:43

标签: javascript angularjs electron

上下文: :我 见过 this question,但不能解决我的问题。< / p>

当我尝试运行我的电子应用程序时,我没有收到任何错误,并且似乎可以编译,但是电子窗口没有弹出。

响应:

Date: 2019-05-08T03:02:22.036Z
Hash: 3303fd48d099a538493f
Time: 13840ms
chunk {0} runtime.26209474bfa8dc87a77c.js (runtime) 1.41 kB [entry] 
[rendered]
chunk {1} es2015-polyfills.c5dd28b362270c767b34.js (es2015-polyfills) 
56.4 kB [initial] [rendered]
chunk {2} main.8b6835f39caf5eafd09d.js (main) 276 kB [initial] 
[rendered]
chunk {3} polyfills.8bbb231b43165d65d357.js (polyfills) 41 kB [initial] 
[rendered]
chunk {4} styles.3ff695c00d717f2d2a11.css (styles) 0 bytes [initial] 
[rendered]

^似乎是完全正常的反应

此后不久,它退出而不显示任何错误代码。

主文件:

const { app, BrowserWindow } = require ('electron')

let win;

function createWindow() {
    //Create the browser window
    win = new BrowserWindow({
        width: 600,
        height: 600,
        backgroundColor: '#ffffff',
        //icon: 'file:///' + __dirname + '/dist/assets/favicon.ico'
    })

    win.loadURL('file:///' + __dirname + '/index.html')
    win.on('close', function() {
        win = null
    })
}

// Create window on electron intialization
app.on('ready', createWindow)

//Quit when all windows are closed
app.on('window-all-closed', function(){

    // On macOS specific close process
    if(process.platform !== 'darwin'){
        app.quit()
    }
})

app.on('activate', function(){
    //macOS specific close process
    if(win === null){
        createWindow()
    }
}) 

HTML文件:

    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>Bot</title>
      <base href="./">
    
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="icon" type="image/x-icon" href="favicon.ico">
    </head>
    <body>
      <app-root></app-root>
    </body>
    </html>
     

Package.json文件:

{
  "name": "shopify-bot",
  "version": "0.0.0",
  "license": "MIT",
  "main": "main.js",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "electron": "electron .",
    "electron-build": "ng build --prod"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~7.2.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "core-js": "^2.5.4",
    "node-html-parser": "^1.1.15",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.13.9",
    "@angular/cli": "~7.3.8",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.5.0",
    "electron": "^5.0.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2"
  }
}

我对棱角还很陌生,所以任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:0)

尝试将您的win.loadURL替换为:

win.loadURL(url.format({
            pathname: path.join(__dirname, 'dist/index.html'),
            protocol: 'file:'
}));

两个要点:

  • 使用protocol: 'file:';
  • dist 文件夹中加载索引

答案 1 :(得分:0)

我发现了我的错误。实际上,我遵循的是this中过时的YouTube视频中的指南,该指南在Angular 4之后失去了支持。我阅读并遵循了this文章中的说明,终于能够打开一个窗口。