From e5be5bbba278aef8f2f522540a29291322636230 Mon Sep 17 00:00:00 2001 From: HappyTobi Date: Wed, 11 Jul 2018 18:44:24 +0200 Subject: [PATCH 1/6] [FIX] User status badge and icon visualisation --- src/scripts/start.js | 6 +++--- src/scripts/tray.js | 24 ++++++++++++++---------- src/scripts/webview.js | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/scripts/start.js b/src/scripts/start.js index c8bc1f6e17..43a5a06fe0 100644 --- a/src/scripts/start.js +++ b/src/scripts/start.js @@ -11,10 +11,10 @@ import './menus'; sidebar.on('badge-setted', function () { const badge = sidebar.getGlobalBadge(); - if (process.platform === 'darwin') { - remote.app.dock.setBadge(badge.title); + if (process.platform === 'darwin' && badge.showAlert) { + remote.app.dock.setBadge(badge.count.toString()); } - tray.showTrayAlert(badge.showAlert, badge.title); + tray.showTrayAlert(badge); }); export const start = function () { diff --git a/src/scripts/tray.js b/src/scripts/tray.js index 26a5fef219..701aad02c7 100644 --- a/src/scripts/tray.js +++ b/src/scripts/tray.js @@ -101,37 +101,41 @@ function createAppTray () { }; } -function getImageTitle (title) { +function getImageTitle (title, showAlert, count) { if (title === '•') { return "Dot"; - } else if (!isNaN(parseInt(title)) && title > 9) { + } else if (showAlert && !isNaN(parseInt(title)) && title > 9) { return "9Plus"; + } else { + return count; } } -function getTrayIcon (platform, showAlert, title, status) { +function getTrayIcon (platform, showAlert, title) { if (platform !== 'darwin') { - return path.join(__dirname, 'images', icons[process.platform].dir, `icon-tray${title}-${status}.png`); + return path.join(__dirname, 'images', icons[process.platform].dir, `icon-tray${title}.png`); } if (showAlert) { - return path.join(__dirname, 'images', icons[process.platform].dir, icons[process.platform].iconAlert ||`icon-tray-alert-${status}Template.png`); + return path.join(__dirname, 'images', icons[process.platform].dir, icons[process.platform].iconAlert); } else { - return path.join(__dirname, 'images', icons[process.platform].dir, icons[process.platform].icon ||`icon-tray-${status}Template.png`); + return path.join(__dirname, 'images', icons[process.platform].dir, icons[process.platform].icon); } } -function showTrayAlert (showAlert, title, status = 'online') { +function showTrayAlert (badge, status = 'online') { if (mainWindow.tray === null || mainWindow.tray === undefined) { return; } - mainWindow.flashFrame(showAlert, title); - const trayImagePath = getTrayIcon(process.platform, showAlert, getImageTitle(title), status); + const imageTitle = getImageTitle(badge.title, badge.showAlert, badge.count); + + mainWindow.flashFrame(badge.showAlert, imageTitle); + const trayImagePath = getTrayIcon(process.platform, badge.showAlert, imageTitle); mainWindow.tray.setImage(trayImagePath); if (process.platform === 'darwin') { - mainWindow.tray.setTitle(`${icons[process.platform].title[status]}${title}`); + mainWindow.tray.setTitle(`${icons[process.platform].title[status]}${badge.title}`); } } diff --git a/src/scripts/webview.js b/src/scripts/webview.js index ea3346b96d..c48bd858aa 100644 --- a/src/scripts/webview.js +++ b/src/scripts/webview.js @@ -93,7 +93,7 @@ class WebView extends EventEmitter { break; case 'user-status-manually-set': const badge = sidebar.getGlobalBadge(); - tray.showTrayAlert(badge.showAlert, badge.title, event.args[0]); + tray.showTrayAlert(badge, event.args[0]); break; case 'get-sourceId': desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => { From ad6118777d2e56b9a1e2a0d25f756c4766e35dfc Mon Sep 17 00:00:00 2001 From: HappyTobi Date: Wed, 25 Jul 2018 07:12:19 +0200 Subject: [PATCH 2/6] [FIX] trailing slashes --- src/scripts/start.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/scripts/start.js b/src/scripts/start.js index 43a5a06fe0..ca905ffead 100644 --- a/src/scripts/start.js +++ b/src/scripts/start.js @@ -52,7 +52,6 @@ export const start = function () { hostField.classList.remove('wrong'); let host = hostField.value.trim(); - host = host.replace(/\/$/, ''); hostField.value = host; if (host.length === 0) { From 80f9ec68dde77334f6948b991d864b221247ae67 Mon Sep 17 00:00:00 2001 From: HappyTobi Date: Thu, 2 Aug 2018 23:21:20 +0200 Subject: [PATCH 3/6] [NEW] add pluralize method to translation lib --- src/i18n/index.js | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/i18n/index.js b/src/i18n/index.js index cdfe3259d8..c0cafb37f3 100644 --- a/src/i18n/index.js +++ b/src/i18n/index.js @@ -5,22 +5,45 @@ import { app, remote } from 'electron'; const eApp = app || remote.app; +var loadedLanguage = []; + +/** + * Load singular and plural translation based on count + * @param {string} phrase The key fore the translation string + * @param {number} chount Count to check for singular / plural (0-1,2-n) + * @returns {string} Translation in user language + */ +function loadTranslation(phrase = '', count) { + const loadedLanguageTranslation = loadedLanguage[phrase]; + var translation = loadedLanguageTranslation; + if (loadedLanguageTranslation === undefined) { + translation = phrase; + } else if(loadedLanguageTranslation instanceof Object) { + translation = loadedLanguageTranslation['one']; + if(count > 1) { + translation = loadedLanguageTranslation['multi']; + } + } + return translation; +} + class I18n { /** * Load users language if available, and fallback to english for any missing strings * @constructor */ constructor () { + console.log('18n constructor loaded') let dir = path.join(__dirname, '../i18n/lang'); if (!fs.existsSync(dir)) { dir = path.join(__dirname, 'i18n/lang'); } const defaultLocale = path.join(dir, 'en.i18n.json'); - this.loadedLanguage = JSON.parse(fs.readFileSync(defaultLocale, 'utf8')); + loadedLanguage = JSON.parse(fs.readFileSync(defaultLocale, 'utf8')); const locale = path.join(dir, `${eApp.getLocale()}.i18n.json`); if (fs.existsSync(locale)) { const lang = JSON.parse(fs.readFileSync(locale, 'utf8')); - this.loadedLanguage = Object.assign(this.loadedLanguage, lang); + loadedLanguage = Object.assign(loadedLanguage, lang); } } @@ -31,7 +54,19 @@ class I18n { * @return {string} Translation in users language */ __ (phrase, ...replacements) { - const translation = this.loadedLanguage[phrase] ? this.loadedLanguage[phrase] : phrase; + const translation = loadTranslation(phrase, 0); + return util.format(translation, ...replacements); + } + + /** + * Get translation string + * @param {string} phrase The key for the translation string + * @param {number} count Count to check for singular / plural (0-1,2-n) + * @param {...string|number} replacements List of replacements in template strings + * @return {string} Translation in users language + */ + pluralize(phrase, count, ...replacements) { + const translation = loadTranslation(phrase, count); return util.format(translation, ...replacements); } } From 74f4f51dd12482a93edffc5f5faf32b7a48f0384 Mon Sep 17 00:00:00 2001 From: HappyTobi Date: Fri, 3 Aug 2018 00:01:36 +0200 Subject: [PATCH 4/6] [FIX] message count state in mac osx menubar --- src/scripts/tray.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/scripts/tray.js b/src/scripts/tray.js index 6941228379..e03a6cecbd 100644 --- a/src/scripts/tray.js +++ b/src/scripts/tray.js @@ -1,12 +1,13 @@ 'use strict'; -import { remote } from 'electron'; +import { remote, systemPreferences } from 'electron'; import path from 'path'; import i18n from '../i18n/index.js'; const { Tray, Menu } = remote; const mainWindow = remote.getCurrentWindow(); +console.log() const icons = { win32: { @@ -21,10 +22,15 @@ const icons = { }; const statusBullet = { - online: '\u001B[32m•\u001B[0m', - away: '\u001B[33m•\u001B[0m', - busy: '\u001B[31m•\u001B[0m', - offline: '\u001B[30m•\u001B[0m' + online: '\u001B[32m•', + away: '\u001B[33m•', + busy: '\u001B[31m•', + offline: '\u001B[30m•' +} + +const messageCountColor = { + white: '\u001B[37m', + black: '\u001B[0m' } function createAppTray () { @@ -129,7 +135,11 @@ function showTrayAlert (badge, status = 'online') { mainWindow.flashFrame(badge.showAlert); if (process.platform === 'darwin') { - mainWindow.tray.setTitle(`${statusBullet[status]}${badge.count}`); + let countColor = messageCountColor['black']; + if(remote.systemPreferences.isDarkMode()) { + countColor = messageCountColor['white']; + } + mainWindow.tray.setTitle(`${statusBullet[status]} ${countColor}${badge.count}`); } } From b4896156a8836dbb5fff7a34c4619647f0216124 Mon Sep 17 00:00:00 2001 From: HappyTobi Date: Fri, 3 Aug 2018 00:12:30 +0200 Subject: [PATCH 5/6] [FIX] linting errors --- src/scripts/tray.js | 57 ++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/src/scripts/tray.js b/src/scripts/tray.js index e03a6cecbd..42498d0d55 100644 --- a/src/scripts/tray.js +++ b/src/scripts/tray.js @@ -1,13 +1,12 @@ 'use strict'; -import { remote, systemPreferences } from 'electron'; +import { remote } from 'electron'; import path from 'path'; import i18n from '../i18n/index.js'; const { Tray, Menu } = remote; const mainWindow = remote.getCurrentWindow(); -console.log() const icons = { win32: { @@ -26,11 +25,36 @@ const statusBullet = { away: '\u001B[33m•', busy: '\u001B[31m•', offline: '\u001B[30m•' -} +}; const messageCountColor = { white: '\u001B[37m', black: '\u001B[0m' +}; + +function getTrayImagePath (badge) { + let iconFilename; + if (badge.title === '•') { + iconFilename = "icon-tray-dot"; + } else if (!isNaN(parseInt(badge.title)) && badge.title > 0) { + if (badge.title > 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 () { @@ -102,31 +126,6 @@ function createAppTray () { }; } -function getTrayImagePath (badge) { - let iconFilename; - if (badge.title === '•') { - iconFilename = "icon-tray-dot"; - } else if (!isNaN(parseInt(badge.title)) && badge.title > 0) { - if (badge.title > 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 showTrayAlert (badge, status = 'online') { if (mainWindow.tray === null || mainWindow.tray === undefined) { return; @@ -136,7 +135,7 @@ function showTrayAlert (badge, status = 'online') { if (process.platform === 'darwin') { let countColor = messageCountColor['black']; - if(remote.systemPreferences.isDarkMode()) { + if (remote.systemPreferences.isDarkMode()) { countColor = messageCountColor['white']; } mainWindow.tray.setTitle(`${statusBullet[status]} ${countColor}${badge.count}`); From 02ee8d51702944185ef1416fee9284f1d6d644aa Mon Sep 17 00:00:00 2001 From: HappyTobi Date: Fri, 3 Aug 2018 00:20:00 +0200 Subject: [PATCH 6/6] [FIX] linting --- src/i18n/index.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/i18n/index.js b/src/i18n/index.js index c0cafb37f3..d0800010ca 100644 --- a/src/i18n/index.js +++ b/src/i18n/index.js @@ -5,7 +5,7 @@ import { app, remote } from 'electron'; const eApp = app || remote.app; -var loadedLanguage = []; +let loadedLanguage = []; /** * Load singular and plural translation based on count @@ -13,19 +13,19 @@ var loadedLanguage = []; * @param {number} chount Count to check for singular / plural (0-1,2-n) * @returns {string} Translation in user language */ -function loadTranslation(phrase = '', count) { +function loadTranslation (phrase = '', count) { const loadedLanguageTranslation = loadedLanguage[phrase]; - var translation = loadedLanguageTranslation; + let translation = loadedLanguageTranslation; if (loadedLanguageTranslation === undefined) { translation = phrase; - } else if(loadedLanguageTranslation instanceof Object) { + } else if (loadedLanguageTranslation instanceof Object) { translation = loadedLanguageTranslation['one']; - if(count > 1) { + if (count > 1) { translation = loadedLanguageTranslation['multi']; - } + } } - return translation; -} + return translation; +} class I18n { /** @@ -33,7 +33,6 @@ class I18n { * @constructor */ constructor () { - console.log('18n constructor loaded') let dir = path.join(__dirname, '../i18n/lang'); if (!fs.existsSync(dir)) { dir = path.join(__dirname, 'i18n/lang'); @@ -65,7 +64,7 @@ class I18n { * @param {...string|number} replacements List of replacements in template strings * @return {string} Translation in users language */ - pluralize(phrase, count, ...replacements) { + pluralize (phrase, count, ...replacements) { const translation = loadTranslation(phrase, count); return util.format(translation, ...replacements); }