Форк Rambox
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.5 KiB

const path = require('path');
const electron = require('electron');
const app = electron.app;
// Module to create tray icon
const Tray = electron.Tray;
const MenuItem = electron.MenuItem;
9 years ago
var appIcon = null;
exports.create = function(win, config) {
if (process.platform === 'darwin' || appIcon || config.get('window_display_behavior') === 'show_taskbar' ) return;
const icon = process.platform === 'linux' || process.platform === 'darwin' ? 'IconTray.png' : 'Icon.ico';
const iconPath = path.join(__dirname, `../resources/${icon}`);
const contextMenu = electron.Menu.buildFromTemplate([
9 years ago
{
label: 'Show/Hide Window'
,click() {
win.webContents.executeJavaScript('ipc.send("toggleWin", false);');
}
9 years ago
},
{
type: 'separator'
},
{
label: 'Quit'
,click() {
app.quit();
}
}
]);
9 years ago
appIcon = new Tray(iconPath);
appIcon.setToolTip('Rambox');
appIcon.setContextMenu(contextMenu);
appIcon.on('double-click', function() {
win.webContents.executeJavaScript('ipc.send("toggleWin", true);');
});
};
exports.destroy = function() {
8 years ago
if (appIcon) appIcon.destroy();
appIcon = null;
};
exports.setBadge = function(messageCount, showUnreadTray) {
if (process.platform === 'darwin' || !appIcon) return;
let icon;
if (process.platform === 'linux') {
icon = messageCount && showUnreadTray ? 'IconTrayUnread.png' : 'IconTray.png';
} else {
icon = messageCount && showUnreadTray ? 'IconTrayUnread.ico' : 'Icon.ico';
}
const iconPath = path.join(__dirname, `../resources/${icon}`);
9 years ago
appIcon.setImage(iconPath);
};