Reputation: 5192
I'm developing a Node.js app on Electron so it can be distributed and run by people who won't be using the command line. The app doesn't need an interface, it just needs to be executed. Is there a way to hide the electron window, so the app can just sit in the tray and can be opened/quit?
Upvotes: 3
Views: 1971
Reputation: 15403
Why do you need to create a BrowserWindow at all? The Tray API runs from the Main process. I just created a small proof of concept app and it seems to work just fine running with no BrowserWindow. You'd just need to make sure to quit the app when the user chooses that option in the tray.
Upvotes: 1
Reputation: 131
Besides the show option the BrowserWindow object has methods for hide/show/focus.
If you want to prevent the users from closing the application when the window is closed you can always intercept the window 'close' event like this:
this.mainWindow.on('close', (event) => {
event.preventDefault()
this.mainWindow.hide()
})
Upvotes: 1
Reputation: 113335
There a show
option in the BrowserWindow options. By default it's true
, but by turning it off (show: false
) you will hide the window, so the app runs, but there's no visible Window.
From Docs:
show
Boolean (optional) - Whether window should be shown when created. Default istrue
.
Upvotes: 4