2019-04-26 19:09:08 +00:00
|
|
|
/**
|
|
|
|
* Module for Tray functions.
|
|
|
|
*/
|
|
|
|
|
2020-05-12 16:55:56 +00:00
|
|
|
const { BrowserWindow, Tray } = require('electron')
|
2019-04-26 19:09:08 +00:00
|
|
|
|
2020-05-13 20:01:42 +00:00
|
|
|
const path = require('path')
|
2020-05-13 12:20:57 +00:00
|
|
|
|
2019-04-26 19:09:08 +00:00
|
|
|
let trayServiceWindow = null
|
|
|
|
let tray = null
|
|
|
|
|
|
|
|
let trayService = {}
|
|
|
|
|
2020-05-18 14:51:43 +00:00
|
|
|
let getTrayServiceIcon = (iconName = 'icon') => {
|
|
|
|
let iconImage = ''
|
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
iconImage = iconName
|
|
|
|
}
|
|
|
|
else if (process.platform === 'win32') {
|
|
|
|
iconImage = iconName+'-16x16'
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
iconImage = iconName+'-48x48'
|
|
|
|
}
|
|
|
|
return path.join(__dirname, '/../resources/images/' + iconImage + '.png')
|
|
|
|
}
|
|
|
|
|
2019-04-26 19:09:08 +00:00
|
|
|
trayService.initTray = (window) => {
|
|
|
|
trayServiceWindow = window
|
2020-05-18 14:51:43 +00:00
|
|
|
let iconPath = getTrayServiceIcon()
|
2019-04-26 19:09:08 +00:00
|
|
|
tray = new Tray(iconPath)
|
|
|
|
tray.setToolTip('Chimeverse')
|
|
|
|
tray.on('click', function() {
|
2020-05-12 16:55:56 +00:00
|
|
|
// Sent open-related-chat event only on click
|
|
|
|
let activeWindow = BrowserWindow.getAllWindows()[0]
|
|
|
|
activeWindow.webContents.send('open-unread-chat')
|
2019-04-26 19:09:08 +00:00
|
|
|
trayService.hideEnvelope()
|
|
|
|
trayServiceWindow.show()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
trayService.showEnvelope = () => {
|
2020-05-18 14:51:43 +00:00
|
|
|
let iconPath = getTrayServiceIcon('envelope')
|
|
|
|
tray.setImage(iconPath)
|
2019-04-26 19:09:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
trayService.hideEnvelope = () => {
|
2020-05-18 14:51:43 +00:00
|
|
|
let iconPath = getTrayServiceIcon()
|
|
|
|
tray.setImage(iconPath)
|
2019-04-26 19:09:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = trayService
|