Search code examples
javascriptnode.jselectronelectron-packager

Electron auto launch packaged application starts welcome window


I am working on an electron test application for windows.

The goal is an auto launching application which displays a popup message everytime the windows user logs in.

Scenario:

  1. I'm executing npm start to package my code. (index.js + package.json)
  2. I execute the generated .exe which will popup my message. (so far so good, right?)
  3. I sign out from windows (CTRL + L ALT + DEL if this is important) and sign in again to test the application.
  4. The popup opens but the default electron welcome page, too.

package.json

{
    "name": "test",
    "description": "",
    "version": "0.0.1",
    "main": "index.js",

    "scripts": {
        "test": "electron .",
        "start": "electron-packager . Test --platform=win32 --arch=x64 --overwrite"
    },

    "author": "",
    "license": "MIT",

    "build": {
        "appId": "com.test.test",
        "win": {
          "target": "NSIS"
        }
    },

    "dependencies": {
        "auto-launch": "^5.0.5"
    },

    "devDependencies": {
        "electron": "latest",
        "electron-packager": "^12.1.1"
    }
}

index.js

const {app, dialog} = require("electron");
const AutoLaunch = require("auto-launch");

app.on("ready", function(){
  dialog.showMessageBox({ message: "We are ready to take off! :-)", buttons: ["OK"] });

  let autoLaunch = new AutoLaunch({
    name: "test"
    // path: app.getPath("exe")
  }).isEnabled().then((isEnabled) => {
    if (!isEnabled){
            autoLaunch.enable();
            dialog.showMessageBox({ message: "AutoLaunch enabled.", buttons: ["OK"] });
    }
    else dialog.showMessageBox({ message: "AutoLaunch already enabled.", buttons: ["OK"] });
  });

  app.quit();
});

Edit: Found a problem that prevents the package.json being updated. A simple npm info resulted in a completely unexpected output.


Solution

  • Wow, totally forgot about this question. The solution was following:

    Update all dependencies. Make sure, that the path to the .html / .js file is absolute and correct.

    An absolute path start with a / For example /files/index.html

    That's how it works!