Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Optional status on tray for MacOS #899

Merged
merged 2 commits into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/background/menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const createTemplate = ({
servers = [],
currentServerUrl = null,
showTrayIcon = true,
showUserStatusInTray = true,
showFullScreen = false,
showMenuBar = true,
showServerList = true,
Expand Down Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/lang/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"Update_skip_message": "We will notify you when the next update is available\nIf you change your mind you can check for updates from the About menu.",
"Update_skip_remind": "Remind Me Later",
"Update_skip_version": "Skip This Version",
"User status in tray": "User status in tray",
"Validating": "Validating...",
"Version": "Version",
"&View": "&View",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/lang/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"Update_skip_message": "Nós iremos lembrá-lo quando a próxima atualização estiver disponível.\nSe você mudar de ideia, pode verificar as atualizações no menu Sobre.",
"Update_skip_remind": "Lembrar Depois",
"Update_skip_version": "Pular Versão",
"User status in tray": "Status do usuário na bandeja",
"Validating": "Validando...",
"Version": "Versão",
"&View": "&Exibir",
Expand Down
6 changes: 6 additions & 0 deletions src/scripts/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -88,6 +89,11 @@ export default () => {
break;
}

case 'showUserStatusInTray': {
tray.toggleStatus();
break;
}

case 'showFullScreen': {
const mainWindow = getCurrentWindow();
mainWindow.setFullScreen(!mainWindow.isFullScreen());
Expand Down
34 changes: 30 additions & 4 deletions src/scripts/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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);
Expand All @@ -179,17 +191,31 @@ 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();
}

export default {
showTrayAlert,
toggle,
toggleStatus,
};