converse-desktop/modules/tray-service.js
JC Brand 1d19fba89f Refactor converse-desktop and bump to Converse 9
This removes all AngularJS code

Angular version 1 is unmaintained and largely obsolete since years.

Additionally, I'd rather re-use the conventions and libraries from
Converse instead of having different ones in converse-desktop.

This means we're losing some functionality, such as the app settings
and the about modal.

This is unfortunate, but ideally (non-Electron) app settings should
be implemented in Converse itself and not in this repo.
2021-12-17 21:24:45 +01:00

51 lines
1.3 KiB
JavaScript

/**
* Module for Tray functions.
*/
const { BrowserWindow, Tray } = require('electron')
const path = require('path')
let trayServiceWindow = null
let tray = null
const trayService = {}
const getTrayServiceIcon = (iconName = 'icon') => {
let iconImage = ''
if (process.platform === 'darwin') {
iconImage = iconName+'Template'
} else if (process.platform === 'win32') {
iconImage = iconName+'-16x16'
} else {
iconImage = iconName+'-48x48'
}
return path.join(__dirname, '/../resources/images/' + iconImage + '.png')
}
trayService.initTray = (window) => {
trayServiceWindow = window
const iconPath = getTrayServiceIcon()
tray = new Tray(iconPath)
tray.setToolTip('Converse Desktop')
tray.on('click', function() {
// Sent open-related-chat event only on click
const activeWindow = BrowserWindow.getAllWindows()[0]
activeWindow.webContents.send('open-unread-chat')
trayService.hideEnvelope()
trayServiceWindow.show()
})
}
trayService.showEnvelope = () => {
const iconPath = getTrayServiceIcon('envelope')
tray.setImage(iconPath)
}
trayService.hideEnvelope = () => {
const iconPath = getTrayServiceIcon()
tray.setImage(iconPath)
}
module.exports = trayService