converse-desktop/modules/tray-service.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

/**
* Module for Tray functions.
*/
2020-05-12 16:55:56 +00:00
const { BrowserWindow, Tray } = require('electron')
2020-05-13 20:01:42 +00:00
const path = require('path')
2020-05-13 12:20:57 +00:00
let trayServiceWindow = null
let tray = null
const trayService = {}
const getTrayServiceIcon = (iconName = 'icon') => {
2020-05-18 14:51:43 +00:00
let iconImage = ''
if (process.platform === 'darwin') {
2020-05-28 14:12:53 +00:00
iconImage = iconName+'Template'
} else if (process.platform === 'win32') {
2020-05-18 14:51:43 +00:00
iconImage = iconName+'-16x16'
} else {
2020-05-18 14:51:43 +00:00
iconImage = iconName+'-48x48'
}
return path.join(__dirname, '/../resources/images/' + iconImage + '.png')
}
trayService.initTray = (window) => {
trayServiceWindow = window
const iconPath = getTrayServiceIcon()
tray = new Tray(iconPath)
2020-08-07 11:53:57 +00:00
tray.setToolTip('Converse Desktop')
tray.on('click', function() {
2020-05-12 16:55:56 +00:00
// Sent open-related-chat event only on click
const activeWindow = BrowserWindow.getAllWindows()[0]
2020-05-12 16:55:56 +00:00
activeWindow.webContents.send('open-unread-chat')
trayService.hideEnvelope()
trayServiceWindow.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