import { Application } from '@webviewjs/webview';
const app = new Application();
const win = app.createBrowserWindow({
title: 'Tray Example',
});
win.createWebview({
html: '<h1>Hello!</h1>',
});
const size = 16;
const rgba = Buffer.alloc(size * size * 4);
for (let i = 0; i < rgba.length; i += 4) {
rgba[i] = 70;
rgba[i + 1] = 150;
rgba[i + 2] = 240;
rgba[i + 3] = 255;
}
let tray;
app.whenReady().then(() => {
tray = app.createTrayIcon({
icon: {
data: rgba,
width: size,
height: size,
},
tooltip: 'My Application',
menu: {
items: [
{
id: 'show',
label: 'Show window',
},
{
role: 'separator',
},
{
id: 'quit',
label: 'Quit',
},
],
},
});
});
app.on('custom-menu-click', ({ customMenuEvent }) => {
switch (customMenuEvent.id) {
case 'show':
win.show();
break;
case 'quit':
app.exit();
break;
}
});
app.run();