Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Electron app not launching

am working with angular version 6.1.0 and electron 2.0,on running the app in browser it but on running npm run electron-build was successful but the app could not launch. thus, no browser window is displayed.

Here is the package.json file:

{
    "name": "front",
    "version": "0.0.0",
    "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"
    }
    ...
}

Here is the main.js file:

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

let win;
function createWindow (){
    win = new BrowserWindow({
        height: 600,
        width:600,
        backgroundColor:'#ffffff'
    })
    win.loadURL(`file://${__dirname}/dist/index.html`)
    win.on('closed',function(){
        win=null;
    })
}

app.on('ready',createWindow())

app.on('windows-all-closed',()=>{
    if(process.platform!=='darwin'){
        app.quit();
    }
})
app.on('activate',function(){
    if(win==null){
        createWindow()
    }
})
like image 981
yaxx Avatar asked Sep 16 '25 07:09

yaxx


1 Answers

It's because you're calling the createWindow function when the app first loads since in the ready event it thinks it should call the createWindow function straight away since it has the two brackets at the end.

To fix it just take the brakets off so it becomes:

app.on('ready',createWindow)

Thanks to @KirkLarkin for spotting the bug.

like image 127
Joshua Avatar answered Sep 17 '25 21:09

Joshua