diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-03-05 01:36:38 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-03-05 01:36:38 +0100 |
commit | 8cbef4c4c7a976967527234b6c3b6117b6de9808 (patch) | |
tree | 4f8d47dd0ba7e953245d19ca361f7477b785b121 /content_scripts | |
parent | 1b2897c03b08e730a2e965e50bbd2104a7a81eef (diff) |
fix inadvertent double spending with coin selection
Diffstat (limited to 'content_scripts')
-rw-r--r-- | content_scripts/notify.js | 34 | ||||
-rw-r--r-- | content_scripts/notify.ts | 33 |
2 files changed, 15 insertions, 52 deletions
diff --git a/content_scripts/notify.js b/content_scripts/notify.js index 4768b09db..0719d5892 100644 --- a/content_scripts/notify.js +++ b/content_scripts/notify.js @@ -35,34 +35,16 @@ var TalerNotify; return url; } var handlers = []; - var connected = false; // Hack to know when the extension is unloaded - var port; - var connect = function (dh) { - port = chrome.runtime.connect(); - port.onDisconnect.addListener(dh); - chrome.runtime.sendMessage({ type: "ping" }, function () { - console.log("registering handlers"); - connected = true; - registerHandlers(); - }); - }; - var disconectHandler = function () { - if (connected) { - console.log("chrome runtime disconnected, removing handlers"); - for (var _i = 0, handlers_1 = handlers; _i < handlers_1.length; _i++) { - var handler = handlers_1[_i]; - document.removeEventListener(handler.type, handler.listener); - } - } - else { - // We got disconnected before the extension was ready, reconnect ... - window.setTimeout(function () { - connect(disconectHandler); - }, 200); + var port = chrome.runtime.connect(); + port.onDisconnect.addListener(function () { + console.log("chrome runtime disconnected, removing handlers"); + for (var _i = 0, handlers_1 = handlers; _i < handlers_1.length; _i++) { + var handler = handlers_1[_i]; + document.removeEventListener(handler.type, handler.listener); } - }; - connect(disconectHandler); + }); + registerHandlers(); function registerHandlers() { var $ = function (x) { return document.getElementById(x); }; function addHandler(type, listener) { diff --git a/content_scripts/notify.ts b/content_scripts/notify.ts index a37617726..7929c3045 100644 --- a/content_scripts/notify.ts +++ b/content_scripts/notify.ts @@ -45,36 +45,17 @@ namespace TalerNotify { const handlers = []; - let connected = false; - // Hack to know when the extension is unloaded - let port; - - const connect = (dh) => { - port = chrome.runtime.connect(); - port.onDisconnect.addListener(dh); - chrome.runtime.sendMessage({type: "ping"}, () => { - console.log("registering handlers"); - connected = true; - registerHandlers(); - }); - }; + let port = chrome.runtime.connect(); - var disconectHandler = () => { - if (connected) { - console.log("chrome runtime disconnected, removing handlers"); - for (let handler of handlers) { - document.removeEventListener(handler.type, handler.listener); - } - } else { - // We got disconnected before the extension was ready, reconnect ... - window.setTimeout(() => { - connect(disconectHandler); - }, 200); + port.onDisconnect.addListener(() => { + console.log("chrome runtime disconnected, removing handlers"); + for (let handler of handlers) { + document.removeEventListener(handler.type, handler.listener); } - }; + }); - connect(disconectHandler); + registerHandlers(); function registerHandlers() { const $ = (x) => document.getElementById(x); |