Add menubar to existing electron app
troncoso opened this issue · 1 comments
troncoso commented
How to add menubar
to an existing app
I created a boilerplate electron app with the default main.js
code like this:
const { app, BrowserWindow } = require('electron')
const path = require('path')
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(path.resolve(), 'preload.js')
}
})
win.loadFile('dist/index.html')
}
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
How do I add menubar
to this so my app shows when clicking a toolbar icon. I understand that you can pass some BrowserWindow
options directly to menubar
, but I don't understand the overlap here, I guess.
troncoso commented
I got this figured out. For my specific situation, I was loading the index.html
out of the dist folder. In order to make this work with menubar
, I just had to pass in the dir
parameter:
const mb = menubar({
dir: path.resolve(__dirname, './dist/')
})