[chrome-gnome-shell/feature/extensions_sync] Do not route duplicate signals.
- From: Yuri Konotopov <ykonotopov src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chrome-gnome-shell/feature/extensions_sync] Do not route duplicate signals.
- Date: Thu, 11 Aug 2016 10:08:57 +0000 (UTC)
commit 872a9b3cb1c9b68d888fae726bfb28d15fa58a3a
Author: Yuri Konotopov <ykonotopov gmail com>
Date: Wed Aug 10 19:27:04 2016 +0300
Do not route duplicate signals.
For example, install action produces duplicate equal signals.
extension/extension.js | 12 ++++++++++++
extension/include/gsc.js | 33 ++++++++++++++++++++++++++++++++-
2 files changed, 44 insertions(+), 1 deletions(-)
---
diff --git a/extension/extension.js b/extension/extension.js
index 3421ec2..8865dec 100644
--- a/extension/extension.js
+++ b/extension/extension.js
@@ -67,10 +67,17 @@ chrome.runtime.onMessageExternal.addListener(function (request, sender, sendResp
}
});
+var lastPortMessage = {message: null, date: 0};
var port = chrome.runtime.connectNative(NATIVE_HOST);
port.onMessage.addListener(function (message) {
if (message && message.signal && [SIGNAL_EXTENSIONS_CHANGED,
SIGNAL_SHELL_APPEARED].indexOf(message.signal) !== -1)
{
+ if((new Date().getTime()) - lastPortMessage.date < 500 && GSC.isSignalsEqual(message,
lastPortMessage.message))
+ {
+ lastPortMessage.date = new Date().getTime();
+ return;
+ }
+
chrome.tabs.query({
url: EXTENSIONS_WEBSITE + '*'
},
@@ -80,6 +87,11 @@ port.onMessage.addListener(function (message) {
chrome.tabs.sendMessage(tabs[k].id, message);
}
});
+
+ lastPortMessage = {
+ message: message,
+ date: new Date().getTime()
+ };
}
});
diff --git a/extension/include/gsc.js b/extension/include/gsc.js
index bedc8f7..8bc2f0f 100644
--- a/extension/include/gsc.js
+++ b/extension/include/gsc.js
@@ -73,6 +73,37 @@ GSC = (function() {
{
chrome.runtime.sendNativeMessage(NATIVE_HOST, request);
}
+ },
+
+ isSignalsEqual: function(newSignal, oldSignal) {
+ if(!oldSignal || !newSignal)
+ return false;
+
+ if(!newSignal.signal || !oldSignal.signal || newSignal.signal !== oldSignal.signal)
+ return false;
+
+ if(newSignal.parameters)
+ {
+ if(!oldSignal.parameters)
+ return false;
+
+ if(newSignal.parameters.length !== oldSignal.parameters.length)
+ return false;
+
+ for(var i = 0; i < newSignal.parameters.length; i++)
+ {
+ if(newSignal.parameters[i] !== oldSignal.parameters[i])
+ {
+ return false;
+ }
+ }
+ }
+ else if (oldSignal.parameters)
+ {
+ return false;
+ }
+
+ return true;
}
};
-})();
\ No newline at end of file
+})();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]