mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 07:23:00 +02:00
OSX notifications dismiss the previous notifications immediately when
sent, preventing 'click' behavior
This commit is contained in:
parent
b6fd302a83
commit
61aef14c64
1 changed files with 52 additions and 11 deletions
|
@ -7,12 +7,14 @@ const path = require('path');
|
||||||
const AccountInfo = require('./hf-acctinfo').AccountInfo;
|
const AccountInfo = require('./hf-acctinfo').AccountInfo;
|
||||||
const GetBuildInfo = hfApp.getBuildInfo;
|
const GetBuildInfo = hfApp.getBuildInfo;
|
||||||
const buildInfo = GetBuildInfo();
|
const buildInfo = GetBuildInfo();
|
||||||
|
const osType = os.type();
|
||||||
|
|
||||||
const notificationIcon = path.join(__dirname, '../../resources/console-notification.png');
|
const notificationIcon = path.join(__dirname, '../../resources/console-notification.png');
|
||||||
const STORIES_NOTIFICATION_POLL_TIME_MS = 15 * 1000; // 120 * 1000;
|
const STORIES_NOTIFICATION_POLL_TIME_MS = 15 * 1000; // 120 * 1000;
|
||||||
const PEOPLE_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 WALLET_NOTIFICATION_POLL_TIME_MS = 15 * 1000; // 600 * 1000;
|
||||||
const MARKETPLACE_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 METAVERSE_SERVER_URL= process.env.HIFI_METAVERSE_URL ? process.env.HIFI_METAVERSE_URL : 'https://metaverse.highfidelity.com'
|
||||||
const STORIES_URL= '/api/v1/user_stories';
|
const STORIES_URL= '/api/v1/user_stories';
|
||||||
|
@ -33,13 +35,15 @@ const NotificationType = {
|
||||||
MARKETPLACE: 'marketplace'
|
MARKETPLACE: 'marketplace'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function HifiNotification(notificationType, notificationData, menuNotificationCallback) {
|
function HifiNotification(notificationType, notificationData, menuNotificationCallback) {
|
||||||
this.type = notificationType;
|
this.type = notificationType;
|
||||||
this.data = notificationData;
|
this.data = notificationData;
|
||||||
}
|
}
|
||||||
|
|
||||||
HifiNotification.prototype = {
|
HifiNotification.prototype = {
|
||||||
show: function () {
|
show: function (finished) {
|
||||||
|
var _finished = finished;
|
||||||
var text = "";
|
var text = "";
|
||||||
var message = "";
|
var message = "";
|
||||||
var url = null;
|
var url = null;
|
||||||
|
@ -114,8 +118,16 @@ HifiNotification.prototype = {
|
||||||
message: message,
|
message: message,
|
||||||
wait: true,
|
wait: true,
|
||||||
appID: buildInfo.appUserModelId,
|
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.marketplaceSince = new Date(this.config.get("marketplaceNotifySince", "1970-01-01T00:00:00.000Z"));
|
||||||
|
|
||||||
this.enable(this.enabled());
|
this.enable(this.enabled());
|
||||||
|
this.pendingNotifications = [];
|
||||||
|
|
||||||
|
|
||||||
var _menuNotificationCallback = menuNotificationCallback;
|
var _menuNotificationCallback = menuNotificationCallback;
|
||||||
notifier.on('click', function (notifierObject, options) {
|
notifier.on('click', function (notifierObject, options) {
|
||||||
|
console.log("click.");
|
||||||
StartInterface(options.url);
|
StartInterface(options.url);
|
||||||
_menuNotificationCallback(options.notificationType, false);
|
_menuNotificationCallback(options.notificationType, false);
|
||||||
});
|
});
|
||||||
|
@ -195,6 +210,36 @@ HifiNotifications.prototype = {
|
||||||
|
|
||||||
this.enable(false);
|
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) {
|
_pollToDisableHighlight: function (notifyType, error, data) {
|
||||||
if (error || !data.body) {
|
if (error || !data.body) {
|
||||||
console.log("Error: unable to get " + url);
|
console.log("Error: unable to get " + url);
|
||||||
|
@ -248,8 +293,7 @@ HifiNotifications.prototype = {
|
||||||
}
|
}
|
||||||
_this.menuNotificationCallback(notifyType, true);
|
_this.menuNotificationCallback(notifyType, true);
|
||||||
if (content.total_entries >= maxNotificationItemCount) {
|
if (content.total_entries >= maxNotificationItemCount) {
|
||||||
var notification = new HifiNotification(notifyType, content.total_entries);
|
_this._addNotification(new HifiNotification(notifyType, content.total_entries));
|
||||||
notification.show();
|
|
||||||
} else {
|
} else {
|
||||||
var notifyData = []
|
var notifyData = []
|
||||||
switch (notifyType) {
|
switch (notifyType) {
|
||||||
|
@ -268,8 +312,7 @@ HifiNotifications.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyData.forEach(function (notifyDataEntry) {
|
notifyData.forEach(function (notifyDataEntry) {
|
||||||
var notification = new HifiNotification(notifyType, notifyDataEntry);
|
_this._addNotification(new HifiNotification(notifyType, notifyDataEntry));
|
||||||
notification.show();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
finished(true, token);
|
finished(true, token);
|
||||||
|
@ -376,13 +419,11 @@ HifiNotifications.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newUsers.size >= maxNotificationItemCount) {
|
if (newUsers.size >= maxNotificationItemCount) {
|
||||||
var notification = new HifiNotification(NotificationType.PEOPLE, newUsers.size);
|
_this._addNotification(new HifiNotification(NotificationType.PEOPLE, newUsers.size));
|
||||||
notification.show();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
newUsers.forEach(function (user) {
|
newUsers.forEach(function (user) {
|
||||||
var notification = new HifiNotification(NotificationType.PEOPLE, user);
|
_this._addNotification(new HifiNotification(NotificationType.PEOPLE, user));
|
||||||
notification.show();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue