From 61aef14c64cfb2cf40858ff2df03c6a36991c2b3 Mon Sep 17 00:00:00 2001 From: Roxanne Skelly Date: Thu, 27 Sep 2018 10:16:21 -0700 Subject: [PATCH] OSX notifications dismiss the previous notifications immediately when sent, preventing 'click' behavior --- .../src/modules/hf-notifications.js | 63 +++++++++++++++---- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/server-console/src/modules/hf-notifications.js b/server-console/src/modules/hf-notifications.js index a95a553631..c7f4e24a17 100644 --- a/server-console/src/modules/hf-notifications.js +++ b/server-console/src/modules/hf-notifications.js @@ -7,12 +7,14 @@ const path = require('path'); const AccountInfo = require('./hf-acctinfo').AccountInfo; const GetBuildInfo = hfApp.getBuildInfo; const buildInfo = GetBuildInfo(); +const osType = os.type(); const notificationIcon = path.join(__dirname, '../../resources/console-notification.png'); const STORIES_NOTIFICATION_POLL_TIME_MS = 15 * 1000; // 120 * 1000; const PEOPLE_NOTIFICATION_POLL_TIME_MS = 15 * 1000; // 120 * 1000; const WALLET_NOTIFICATION_POLL_TIME_MS = 15 * 1000; // 600 * 1000; const MARKETPLACE_NOTIFICATION_POLL_TIME_MS = 15 * 1000; // 600 * 1000; +const OSX_CLICK_DELAY_TIMEOUT = 500; const METAVERSE_SERVER_URL= process.env.HIFI_METAVERSE_URL ? process.env.HIFI_METAVERSE_URL : 'https://metaverse.highfidelity.com' const STORIES_URL= '/api/v1/user_stories'; @@ -33,13 +35,15 @@ const NotificationType = { MARKETPLACE: 'marketplace' }; + function HifiNotification(notificationType, notificationData, menuNotificationCallback) { this.type = notificationType; this.data = notificationData; } HifiNotification.prototype = { - show: function () { + show: function (finished) { + var _finished = finished; var text = ""; var message = ""; var url = null; @@ -114,8 +118,16 @@ HifiNotification.prototype = { message: message, wait: true, appID: buildInfo.appUserModelId, - url: url - }); + url: url, + timeout: 5 + }, + function (error, reason, metadata) { + if (osType == 'Darwin') { + setTimeout(_finished, OSX_CLICK_DELAY_TIMEOUT); + } else { + _finished(); + } + }); } } @@ -129,9 +141,12 @@ function HifiNotifications(config, menuNotificationCallback) { this.marketplaceSince = new Date(this.config.get("marketplaceNotifySince", "1970-01-01T00:00:00.000Z")); this.enable(this.enabled()); + this.pendingNotifications = []; + var _menuNotificationCallback = menuNotificationCallback; notifier.on('click', function (notifierObject, options) { + console.log("click."); StartInterface(options.url); _menuNotificationCallback(options.notificationType, false); }); @@ -195,6 +210,36 @@ HifiNotifications.prototype = { this.enable(false); }, + _showNotification: function () { + var _this = this; + + if (osType == 'Darwin') { + this.pendingNotifications[0].show(function () { + // For OSX + // don't attempt to show the next notification + // until the current is clicked or times out + // as the OSX Notifier stuff will dismiss + // the previous notification immediately + // when a new one is submitted + _this.pendingNotifications.shift(); + if(_this.pendingNotifications.length > 0) { + _this._showNotification(); + } + }); + } else { + // For Windows + // All notifications are sent immediately as they are queued + // by windows in Tray Notifications and can be bulk seen and + // dismissed + _this._showNotification(_this.pendingNotifications.shift()); + } + }, + _addNotification: function (notification) { + this.pendingNotifications.push(notification); + if(this.pendingNotifications.length == 1) { + this._showNotification(); + } + }, _pollToDisableHighlight: function (notifyType, error, data) { if (error || !data.body) { console.log("Error: unable to get " + url); @@ -248,8 +293,7 @@ HifiNotifications.prototype = { } _this.menuNotificationCallback(notifyType, true); if (content.total_entries >= maxNotificationItemCount) { - var notification = new HifiNotification(notifyType, content.total_entries); - notification.show(); + _this._addNotification(new HifiNotification(notifyType, content.total_entries)); } else { var notifyData = [] switch (notifyType) { @@ -268,8 +312,7 @@ HifiNotifications.prototype = { } notifyData.forEach(function (notifyDataEntry) { - var notification = new HifiNotification(notifyType, notifyDataEntry); - notification.show(); + _this._addNotification(new HifiNotification(notifyType, notifyDataEntry)); }); } finished(true, token); @@ -376,13 +419,11 @@ HifiNotifications.prototype = { } if (newUsers.size >= maxNotificationItemCount) { - var notification = new HifiNotification(NotificationType.PEOPLE, newUsers.size); - notification.show(); + _this._addNotification(new HifiNotification(NotificationType.PEOPLE, newUsers.size)); return; } newUsers.forEach(function (user) { - var notification = new HifiNotification(NotificationType.PEOPLE, user); - notification.show(); + _this._addNotification(new HifiNotification(NotificationType.PEOPLE, user)); }); }); });