From e67f1994f096f59d9faacc9e6a93666f1282be6c Mon Sep 17 00:00:00 2001 From: HappyTobi Date: Sat, 6 Oct 2018 23:27:43 +0200 Subject: [PATCH 1/6] =?UTF-8?q?[UPDATE]=C2=A0i18n=20pluralize=20implementa?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/i18n/index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/i18n/index.js b/src/i18n/index.js index 99d242b88e..67dd50743f 100644 --- a/src/i18n/index.js +++ b/src/i18n/index.js @@ -19,8 +19,10 @@ function loadTranslation(phrase = '', count) { if (loadedLanguageTranslation === undefined) { translation = phrase; } else if (loadedLanguageTranslation instanceof Object) { - translation = loadedLanguageTranslation.one; - if (count > 1) { + translation = loadedLanguageTranslation.zero; + if (count == 1) { + translation = loadedLanguageTranslation.one; + } else if (count > 1) { translation = loadedLanguageTranslation.multi; } } @@ -75,7 +77,10 @@ class I18n { */ pluralize(phrase, count, ...replacements) { const translation = loadTranslation(phrase, count); - return util.format(translation, ...replacements); + if(translation.includes('%s')){ + return util.format(translation, ...replacements); + } + return translation; } } From 716c78e8972b18ace13019e9a26b102e286c72d4 Mon Sep 17 00:00:00 2001 From: HappyTobi Date: Sat, 6 Oct 2018 23:28:08 +0200 Subject: [PATCH 2/6] [NEW] add tooltip to show unread message count --- src/i18n/lang/en.i18n.json | 5 +++++ src/scripts/tray.js | 1 + 2 files changed, 6 insertions(+) diff --git a/src/i18n/lang/en.i18n.json b/src/i18n/lang/en.i18n.json index 293c02a59a..553e31176c 100644 --- a/src/i18n/lang/en.i18n.json +++ b/src/i18n/lang/en.i18n.json @@ -42,6 +42,11 @@ "Invalid_url": "Invalid url", "Learn more": "Learn more", "Menu bar": "Menu bar", + "Message_count": { + "zero": "Rocket.Chat: no unread messages", + "one": "Rocket.Chat: you have %s unread message", + "multi": "Rocket.Chat: you have %s unread messages" + }, "Minimize": "Minimize", "More_spelling_suggestions": "More spelling suggestions", "New_Version": "New Version:", diff --git a/src/scripts/tray.js b/src/scripts/tray.js index 3d0393665c..bef4cb0e9b 100644 --- a/src/scripts/tray.js +++ b/src/scripts/tray.js @@ -171,6 +171,7 @@ function showTrayAlert(badge, status = 'online') { remote.app.dock.setBadge(badge.title); if (trayDisplayed) { mainWindow.tray.setTitle(trayTitle); + mainWindow.tray.setToolTip(i18n.pluralize('Message_count', badge.count, badge.count)); } } From 9791aa399c85b570ad50bd75c2be87e95aba18f2 Mon Sep 17 00:00:00 2001 From: HappyTobi Date: Sat, 6 Oct 2018 23:29:30 +0200 Subject: [PATCH 3/6] [FIX] english text --- src/i18n/lang/en.i18n.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i18n/lang/en.i18n.json b/src/i18n/lang/en.i18n.json index 553e31176c..4800522370 100644 --- a/src/i18n/lang/en.i18n.json +++ b/src/i18n/lang/en.i18n.json @@ -43,7 +43,7 @@ "Learn more": "Learn more", "Menu bar": "Menu bar", "Message_count": { - "zero": "Rocket.Chat: no unread messages", + "zero": "Rocket.Chat: no unread message", "one": "Rocket.Chat: you have %s unread message", "multi": "Rocket.Chat: you have %s unread messages" }, From 60f758cdaa8eca9dfd3c4728c0b4bbbf3d260e18 Mon Sep 17 00:00:00 2001 From: HappyTobi Date: Sat, 6 Oct 2018 23:30:31 +0200 Subject: [PATCH 4/6] [FIX] linting errors --- src/i18n/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/i18n/index.js b/src/i18n/index.js index 67dd50743f..29664e3885 100644 --- a/src/i18n/index.js +++ b/src/i18n/index.js @@ -20,7 +20,7 @@ function loadTranslation(phrase = '', count) { translation = phrase; } else if (loadedLanguageTranslation instanceof Object) { translation = loadedLanguageTranslation.zero; - if (count == 1) { + if (count === 1) { translation = loadedLanguageTranslation.one; } else if (count > 1) { translation = loadedLanguageTranslation.multi; @@ -77,7 +77,7 @@ class I18n { */ pluralize(phrase, count, ...replacements) { const translation = loadTranslation(phrase, count); - if(translation.includes('%s')){ + if (translation.includes('%s')) { return util.format(translation, ...replacements); } return translation; From d5f38d58d937792d362baf6b0d4eaf0c4b00a45b Mon Sep 17 00:00:00 2001 From: Tasso Evangelista Date: Tue, 16 Oct 2018 09:48:55 -0300 Subject: [PATCH 5/6] Delete tray.js --- src/scripts/tray.js | 222 -------------------------------------------- 1 file changed, 222 deletions(-) delete mode 100644 src/scripts/tray.js diff --git a/src/scripts/tray.js b/src/scripts/tray.js deleted file mode 100644 index bef4cb0e9b..0000000000 --- a/src/scripts/tray.js +++ /dev/null @@ -1,222 +0,0 @@ -'use strict'; - -import { remote } from 'electron'; -import path from 'path'; -import i18n from '../i18n/index.js'; - -const { Tray, Menu } = remote; - -const mainWindow = remote.getCurrentWindow(); - -const icons = { - win32: { - dir: 'windows', - }, - linux: { - dir: 'linux', - }, - darwin: { - dir: 'osx', - }, -}; - -const statusBullet = { - online: '\u001B[32m•', - away: '\u001B[33m•', - busy: '\u001B[31m•', - offline: '\u001B[37m•', -}; - -const messageCountColor = { - white: '\u001B[37m', - black: '\u001B[0m', -}; - -function getTrayImagePath(badge) { - let iconFilename; - if (badge.title === '•') { - iconFilename = 'icon-tray-dot'; - } else if (badge.count > 0) { - if (badge.count > 9) { - iconFilename = 'icon-tray-9plus'; - } else { - iconFilename = `icon-tray-${ badge.count }`; - } - } else if (badge.showAlert) { - iconFilename = 'icon-tray-alert'; - } else { - iconFilename = 'icon-tray-Template'; - } - - if (process.platform === 'win32') { - iconFilename += '.ico'; - } else { - iconFilename += '.png'; - } - - return path.join(__dirname, 'images', icons[process.platform].dir, iconFilename); -} - -function createAppTray() { - const _tray = new Tray(getTrayImagePath({ title:'', count:0, showAlert:false })); - mainWindow.tray = _tray; - - const contextMenuShow = Menu.buildFromTemplate([{ - label: i18n.__('Show'), - click() { - mainWindow.show(); - }, - }, { - label: i18n.__('Quit'), - click() { - remote.app.quit(); - }, - }]); - - const contextMenuHide = Menu.buildFromTemplate([{ - label: i18n.__('Hide'), - click() { - mainWindow.hide(); - }, - }, { - label: i18n.__('Quit'), - click() { - remote.app.quit(); - }, - }]); - - if (!mainWindow.isMinimized() && !mainWindow.isVisible()) { - _tray.setContextMenu(contextMenuShow); - } else { - _tray.setContextMenu(contextMenuHide); - } - - const onShow = function() { - _tray.setContextMenu(contextMenuHide); - }; - - const onHide = function() { - _tray.setContextMenu(contextMenuShow); - }; - - mainWindow.on('show', onShow); - mainWindow.on('restore', onShow); - - mainWindow.on('hide', onHide); - mainWindow.on('minimize', onHide); - - _tray.setToolTip(remote.app.getName()); - - _tray.on('right-click', function(e, b) { - _tray.popUpContextMenu(undefined, b); - }); - - _tray.on('click', () => { - if (mainWindow.isVisible()) { - return mainWindow.hide(); - } - - mainWindow.show(); - }); - - mainWindow.destroyTray = function() { - mainWindow.removeListener('show', onShow); - mainWindow.removeListener('hide', onHide); - _tray.destroy(); - }; -} - -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()) { - mainWindow.flashFrame(hasMentions); - } - - if (process.platform === 'win32') { - if (hasMentions) { - mainWindow.webContents.send('render-taskbar-icon', badge.count); - } else { - mainWindow.setOverlayIcon(null, ''); - } - } - - if (process.platform === 'darwin') { - let countColor = messageCountColor.black; - if (remote.systemPreferences.isDarkMode()) { - countColor = messageCountColor.white; - } - - const trayTitle = [ - statusDisplayed && statusBullet[status], - hasMentions && `${ countColor }${ badge.title }`, - ].filter(Boolean).join(' '); - remote.app.dock.setBadge(badge.title); - if (trayDisplayed) { - mainWindow.tray.setTitle(trayTitle); - mainWindow.tray.setToolTip(i18n.pluralize('Message_count', badge.count, badge.count)); - } - } - - if (process.platform === 'linux') { - remote.app.setBadgeCount(badge.count); - } - - if (trayDisplayed) { - mainWindow.tray.setImage(getTrayImagePath(badge)); - } -} - -function removeAppTray() { - mainWindow.destroyTray(); -} - -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, -}; From 280b589ff9a3122eec92d728534ac61e37af5cef Mon Sep 17 00:00:00 2001 From: Tasso Evangelista Date: Tue, 16 Oct 2018 09:50:25 -0300 Subject: [PATCH 6/6] Add tooltip handling in tray module --- src/background/tray.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/background/tray.js b/src/background/tray.js index 58745a9f62..50c2f833b9 100644 --- a/src/background/tray.js +++ b/src/background/tray.js @@ -47,6 +47,8 @@ const getTrayIconTitle = ({ badge: { title, count, showAlert }, status, showUser return [statusBulletString, badgeTitleString].filter(Boolean).join(' '); }; +const getTrayIconTooltip = ({ badge: { count } }) => i18n.pluralize('Message_count', count, count); + const createContextMenuTemplate = ({ isMainWindowVisible }, events) => ([ { label: !isMainWindowVisible ? i18n.__('Show') : i18n.__('Hide'), @@ -127,6 +129,8 @@ class Tray extends EventEmitter { if (process.platform === 'darwin') { this.trayIcon.setTitle(getTrayIconTitle(this.state)); } + + this.trayIcon.setToolTip(getTrayIconTooltip(this.state)); this.trayIcon.setImage(getTrayIconPath(this.state));