36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
const { Tray, Menu, nativeImage } = require('electron');
|
|
const path = require('path');
|
|
|
|
let tray = null;
|
|
|
|
function createTray({ onToggle, onHide, onQuit }) {
|
|
const iconPath = path.join(__dirname, '../assets/fox-tray.png');
|
|
let icon = nativeImage.createFromPath(iconPath);
|
|
|
|
if (icon.isEmpty()) {
|
|
console.warn('[Tray] Icon nicht gefunden:', iconPath, '— Fallback auf leeres Icon');
|
|
// Minimales 1x1 schwarzes Template-PNG als Fallback
|
|
icon = nativeImage.createFromDataURL(
|
|
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=='
|
|
);
|
|
}
|
|
|
|
icon.setTemplateImage(true);
|
|
|
|
tray = new Tray(icon);
|
|
tray.setToolTip('Fox');
|
|
|
|
tray.setContextMenu(Menu.buildFromTemplate([
|
|
{ label: 'Fox öffnen/schließen', accelerator: 'Cmd+Shift+F', click: onToggle },
|
|
{ label: 'Fox verstecken', click: onHide },
|
|
{ type: 'separator' },
|
|
{ label: 'Beenden', click: onQuit },
|
|
]));
|
|
|
|
tray.on('click', onToggle);
|
|
|
|
return tray;
|
|
}
|
|
|
|
module.exports = { createTray };
|