Here's a step-by-step guide to create a toolbar with an icon for an Electron app on Windows:
- Create the App Icon
- Design your icon in .ico format (recommended size: 256x256 pixels)
- Save the icon file in your project's assets or resources folder
- Configure Electron Main Process
const { app, BrowserWindow } = require('electron')
const path = require('path')
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
icon: path.join(__dirname, 'assets/icon.ico'), // Set Windows app icon
webPreferences: {
nodeIntegration: true
}
})
win.loadFile('index.html')
}
app.whenReady().then(createWindow)
- Add Toolbar in Main Window
const { Menu } = require('electron')
const template = [
{
label: 'File',
submenu: [
{ label: 'New', click: () => { /* New file action */ } },
{ label: 'Open', click: () => { /* Open file action */ } },
{ type: 'separator' },
{ label: 'Exit', click: () => app.quit() }
]
},
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' }
]
}
]
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
- Package.json Configuration
{
"build": {
"appId": "com.yourapp.name",
"win": {
"icon": "assets/icon.ico"
}
}
}
- Use electron-builder for Packaging
npm install electron-builder --save-dev
Add to package.json scripts:
"scripts": {
"build": "electron-builder build --win"
}
Key Considerations:
- Use high-quality .ico file for best results
- Customize menu template to match your app's functionality
- Test thoroughly on Windows environment
- Consider platform-specific design guidelines
Recommended Libraries:
- electron-builder for packaging
- electron-windows-installer for Windows-specific installation
Remember to handle cross-platform compatibility if targeting multiple operating systems.