I have a simple Electron tray app with the following source:
const { app, Tray, Notification, Menu, nativeImage } = require('electron');
const path = require('path');
const iconPath = path.join(__dirname, 'assets/icons/iconTemplate.png');
let tray = null;
app.whenReady().then(() => {
try {
console.log(iconPath);
tray = new Tray(nativeImage.createFromPath(iconPath));
tray.setToolTip('Electron app');
} catch (e) {
console.log(e);
}
})
Here's the package.json:
{
"name": "Electron app",
"version": "0.0.1",
"description": "",
"main": "app.js",
"scripts": {
"electron": "electron app.js",
"test": "echo \"Error: no test specified\" && exit 1",
"package-linux": "electron-packager . --overwrite --icon=assets/icons/256x256.png --out=release-builds",
"deb64": "electron-installer-debian --config config/build-config.json"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
...
},
"devDependencies": {
...
}
}
When I run the app with electron app.js, nothing happens. But when I run npm run electron (which runs the script from package.json) the app works. What's the difference?
