From 306e0f3b5e05d867ec59b0b89c6ce449b9382cd4 Mon Sep 17 00:00:00 2001 From: Akash Nimare Date: Tue, 10 Jul 2018 10:01:36 +0530 Subject: [PATCH] macOS: Add dock bouncing effect on macOS. This PR adds a new setting option of controlling the dock bouncing feature on macOS. Fixes: #510. --- app/renderer/js/components/webview.js | 5 +++++ app/renderer/js/main.js | 5 +++++ .../js/pages/preference/general-section.js | 21 +++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/app/renderer/js/components/webview.js b/app/renderer/js/components/webview.js index 4efe6d2a..123bcf0b 100644 --- a/app/renderer/js/components/webview.js +++ b/app/renderer/js/components/webview.js @@ -75,11 +75,16 @@ class WebView extends BaseComponent { this.$el.addEventListener('page-favicon-updated', event => { const { favicons } = event; + // This returns a string of favicons URL. If there is a PM counts in unread messages then the URL would be like // https://chat.zulip.org/static/images/favicon/favicon-pms.png if (favicons[0].indexOf('favicon-pms') > 0 && process.platform === 'darwin') { // This api is only supported on macOS app.dock.setBadge('●'); + // bounce the dock + if (ConfigUtil.getConfigItem('dockBouncing')) { + app.dock.bounce(); + } } }); diff --git a/app/renderer/js/main.js b/app/renderer/js/main.js index 27b75a91..1d46e77d 100644 --- a/app/renderer/js/main.js +++ b/app/renderer/js/main.js @@ -127,6 +127,11 @@ class ServerManagerView { settingOptions.dndPreviousSettings.flashTaskbarOnMessage = true; } + if (process.platform === 'darwin') { + // Only available on macOS + settingOptions.dockBouncing = true; + } + for (const i in settingOptions) { if (ConfigUtil.getConfigItem(i) === null) { ConfigUtil.setConfigItem(i, settingOptions[i]); diff --git a/app/renderer/js/pages/preference/general-section.js b/app/renderer/js/pages/preference/general-section.js index 096950f7..bcf590f4 100644 --- a/app/renderer/js/pages/preference/general-section.js +++ b/app/renderer/js/pages/preference/general-section.js @@ -31,6 +31,10 @@ class GeneralSection extends BaseSection {
Show app unread badge
+
+
Bounce dock on new private message
+
+
Flash taskbar on new message
@@ -121,10 +125,15 @@ class GeneralSection extends BaseSection { this.removeCustomCSS(); // Platform specific settings + // Flashing taskbar on Windows if (process.platform === 'win32') { this.updateFlashTaskbar(); } + // Dock bounce on macOS + if (process.platform === 'darwin') { + this.updateDockBouncing(); + } } updateTrayOption() { @@ -153,6 +162,18 @@ class GeneralSection extends BaseSection { }); } + updateDockBouncing() { + this.generateSettingOption({ + $element: document.querySelector('#dock-bounce-option .setting-control'), + value: ConfigUtil.getConfigItem('dockBouncing', true), + clickHandler: () => { + const newValue = !ConfigUtil.getConfigItem('dockBouncing'); + ConfigUtil.setConfigItem('dockBouncing', newValue); + this.updateDockBouncing(); + } + }); + } + updateFlashTaskbar() { this.generateSettingOption({ $element: document.querySelector('#flash-taskbar-option .setting-control'),