converse-desktop/modules/tray-service.js

45 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

/**
* Module for Tray functions.
*/
2022-03-29 21:19:49 +00:00
const { Tray } = require('electron')
2020-05-13 20:01:42 +00:00
const path = require('path')
2020-05-13 12:20:57 +00:00
let tray = null
const trayService = {}
const getTrayServiceIcon = (iconName = 'icon') => {
let iconImage;
if (process.platform === 'darwin' || process.platform === 'win32') {
2022-03-29 21:19:49 +00:00
iconImage = iconName + '-16x16'
} else {
2022-03-29 21:19:49 +00:00
iconImage = iconName + '-48x48'
2020-05-18 14:51:43 +00:00
}
2022-03-29 21:19:49 +00:00
return path.join(__dirname, '..', 'resources', 'images', iconImage + '.png')
2020-05-18 14:51:43 +00:00
}
trayService.initTray = (window) => {
const iconPath = getTrayServiceIcon()
tray = new Tray(iconPath)
2020-08-07 11:53:57 +00:00
tray.setToolTip('Converse Desktop')
2022-03-29 21:19:49 +00:00
tray.on('click', function () {
window.webContents.send('open-unread-chat')
trayService.hideEnvelope()
window.show()
})
}
trayService.showEnvelope = () => {
const iconPath = getTrayServiceIcon('envelope')
2020-05-18 14:51:43 +00:00
tray.setImage(iconPath)
}
trayService.hideEnvelope = () => {
const iconPath = getTrayServiceIcon()
2020-05-18 14:51:43 +00:00
tray.setImage(iconPath)
}
module.exports = trayService