fix #4474
This commit is contained in:
parent
0a1b775b48
commit
5825e7b476
@ -33,10 +33,6 @@ namespace TalerNotify {
|
|||||||
|
|
||||||
console.log("Taler injected", chrome.runtime.id);
|
console.log("Taler injected", chrome.runtime.id);
|
||||||
|
|
||||||
// FIXME: only do this for test wallets?
|
|
||||||
// This is no security risk, since the extension ID for published
|
|
||||||
// extension is publicly known.
|
|
||||||
|
|
||||||
function subst(url: string, H_contract) {
|
function subst(url: string, H_contract) {
|
||||||
url = url.replace("${H_contract}", H_contract);
|
url = url.replace("${H_contract}", H_contract);
|
||||||
url = url.replace("${$}", "$");
|
url = url.replace("${$}", "$");
|
||||||
@ -45,17 +41,28 @@ namespace TalerNotify {
|
|||||||
|
|
||||||
const handlers = [];
|
const handlers = [];
|
||||||
|
|
||||||
// Hack to know when the extension is unloaded
|
function init() {
|
||||||
let port = chrome.runtime.connect();
|
chrome.runtime.sendMessage({type: "ping"}, () => {
|
||||||
|
if (chrome.runtime.lastError) {
|
||||||
|
console.log("extension not yet ready");
|
||||||
|
window.setTimeout(init, 200);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log("got pong");
|
||||||
|
registerHandlers();
|
||||||
|
// Hack to know when the extension is unloaded
|
||||||
|
let port = chrome.runtime.connect();
|
||||||
|
|
||||||
port.onDisconnect.addListener(() => {
|
port.onDisconnect.addListener(() => {
|
||||||
console.log("chrome runtime disconnected, removing handlers");
|
console.log("chrome runtime disconnected, removing handlers");
|
||||||
for (let handler of handlers) {
|
for (let handler of handlers) {
|
||||||
document.removeEventListener(handler.type, handler.listener);
|
document.removeEventListener(handler.type, handler.listener);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
registerHandlers();
|
init();
|
||||||
|
|
||||||
function registerHandlers() {
|
function registerHandlers() {
|
||||||
const $ = (x) => document.getElementById(x);
|
const $ = (x) => document.getElementById(x);
|
||||||
|
Loading…
Reference in New Issue
Block a user