Commit 83def413 authored by Tasso Evangelista's avatar Tasso Evangelista

Add menu option to toggle user status in tray icon

parent 670a27d7
......@@ -8,6 +8,7 @@ const createTemplate = ({
servers = [],
currentServerUrl = null,
showTrayIcon = true,
showUserStatusInTray = true,
showFullScreen = false,
showMenuBar = true,
showServerList = true,
......@@ -151,6 +152,13 @@ const createTemplate = ({
click: () => events.emit('toggle', 'showTrayIcon'),
},
...(process.platform === 'darwin' ? [
{
label: i18n.__('User status in tray'),
type: 'checkbox',
enabled: showTrayIcon,
checked: showTrayIcon && showUserStatusInTray,
click: () => events.emit('toggle', 'showUserStatusInTray'),
},
{
label: i18n.__('Full screen'),
type: 'checkbox',
......
......@@ -74,6 +74,7 @@ export default () => {
menus.setState({
showTrayIcon: localStorage.getItem('hideTray') !== 'true',
showUserStatusInTray: (localStorage.getItem('showUserStatusInTray') || 'true') === 'true',
showFullScreen: mainWindow.isFullScreen(),
showWindowOnUnreadChanged: localStorage.getItem('showWindowOnUnreadChanged') === 'true',
showMenuBar: localStorage.getItem('autohideMenu') !== 'true',
......@@ -88,6 +89,11 @@ export default () => {
break;
}
case 'showUserStatusInTray': {
tray.toggleStatus();
break;
}
case 'showFullScreen': {
const mainWindow = getCurrentWindow();
mainWindow.setFullScreen(!mainWindow.isFullScreen());
......
......@@ -126,12 +126,24 @@ function createAppTray() {
};
}
let state = {
badge: null,
status: 'online',
};
function showTrayAlert(badge, status = 'online') {
if (mainWindow.tray === null || mainWindow.tray === undefined) {
return;
}
state = {
...state,
badge,
status,
};
const trayDisplayed = localStorage.getItem('hideTray') !== 'true';
const statusDisplayed = (localStorage.getItem('showUserStatusInTray') || 'true') === 'true';
const hasMentions = badge.showAlert && badge.count > 0;
if (!mainWindow.isFocused()) {
......@@ -152,10 +164,10 @@ function showTrayAlert(badge, status = 'online') {
countColor = messageCountColor.white;
}
let trayTitle = `${ statusBullet[status] }`;
if (hasMentions) {
trayTitle = `${ statusBullet[status] } ${ countColor }${ badge.title }`;
}
const trayTitle = [
statusDisplayed && statusBullet[status],
hasMentions && `${ countColor }${ badge.title }`,
].filter(Boolean).join(' ');
remote.app.dock.setBadge(badge.title);
if (trayDisplayed) {
mainWindow.tray.setTitle(trayTitle);
......@@ -179,12 +191,25 @@ function toggle() {
if (localStorage.getItem('hideTray') === 'true') {
createAppTray();
localStorage.setItem('hideTray', 'false');
showTrayAlert(state.badge, state.status);
} else {
removeAppTray();
localStorage.setItem('hideTray', 'true');
}
}
function toggleStatus() {
if (localStorage.getItem('showUserStatusInTray') === 'true') {
localStorage.setItem('showUserStatusInTray', 'false');
} else {
localStorage.setItem('showUserStatusInTray', 'true');
}
if (localStorage.getItem('hideTray') !== 'true') {
showTrayAlert(state.badge, state.status);
}
}
if (localStorage.getItem('hideTray') !== 'true') {
createAppTray();
}
......@@ -192,4 +217,5 @@ if (localStorage.getItem('hideTray') !== 'true') {
export default {
showTrayAlert,
toggle,
toggleStatus,
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment