lbry-desktop/electron/createTray.js

45 lines
894 B
JavaScript
Raw Normal View History

2018-02-26 23:03:01 -05:00
import { app, Menu, Tray } from 'electron';
2018-02-23 18:20:12 -05:00
import path from 'path';
2019-03-15 18:16:11 -05:00
let tray;
2018-02-23 18:20:12 -05:00
export default window => {
let iconPath;
2019-03-15 17:09:14 -05:00
2018-02-23 18:20:12 -05:00
switch (process.platform) {
case 'darwin': {
2019-03-04 23:46:57 -05:00
iconPath = 'static/img/tray/mac/trayTemplate.png';
2018-02-23 18:20:12 -05:00
break;
}
case 'win32': {
2019-03-04 23:46:57 -05:00
iconPath = 'static/img/tray/windows/tray.ico';
2018-02-23 18:20:12 -05:00
break;
}
default: {
2019-03-04 23:46:57 -05:00
iconPath = 'static/img/tray/default/tray.png';
2018-02-23 18:20:12 -05:00
}
}
2019-05-07 17:38:29 -04:00
tray = new Tray(process.env.NODE_ENV === 'development' ? iconPath : path.join(process.resourcesPath, iconPath));
2018-02-23 18:20:12 -05:00
tray.on('double-click', () => {
window.show();
});
tray.setToolTip('LBRY App');
const template = [
{
label: `Open ${app.getName()}`,
click: () => {
window.show();
},
},
{ role: 'quit' },
];
const contextMenu = Menu.buildFromTemplate(template);
tray.setContextMenu(contextMenu);
return tray;
};