From f67d7f54f9d0fed97446898942e3dfee67ee2985 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 5 Dec 2019 19:38:19 +0100 Subject: threads, retries and notifications WIP --- src/webex/chromeBadge.ts | 5 +---- src/webex/messages.ts | 4 ---- src/webex/wxApi.ts | 7 ------- src/webex/wxBackend.ts | 51 ++---------------------------------------------- 4 files changed, 3 insertions(+), 64 deletions(-) (limited to 'src/webex') diff --git a/src/webex/chromeBadge.ts b/src/webex/chromeBadge.ts index 15b68ef02..e6b21ad91 100644 --- a/src/webex/chromeBadge.ts +++ b/src/webex/chromeBadge.ts @@ -14,9 +14,6 @@ TALER; see the file COPYING. If not, see */ -import { - Badge, -} from "../walletTypes"; import { isFirefox } from "./compat"; @@ -36,7 +33,7 @@ function rAF(cb: (ts: number) => void) { * Badge for Chrome that renders a Taler logo with a rotating ring if some * background activity is happening. */ -export class ChromeBadge implements Badge { +export class ChromeBadge { private canvas: HTMLCanvasElement; private ctx: CanvasRenderingContext2D; /** diff --git a/src/webex/messages.ts b/src/webex/messages.ts index cf409b44e..6c57385c3 100644 --- a/src/webex/messages.ts +++ b/src/webex/messages.ts @@ -145,10 +145,6 @@ export interface MessageMap { request: { talerTipUri: string }; response: walletTypes.TipStatus; }; - "clear-notification": { - request: {}; - response: void; - }; "accept-refund": { request: { refundUrl: string }; response: string; diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts index ea26cd2eb..c4fa65186 100644 --- a/src/webex/wxApi.ts +++ b/src/webex/wxApi.ts @@ -280,13 +280,6 @@ export function acceptTip(talerTipUri: string): Promise { } -/** - * Clear notifications that the wallet shows to the user. - */ -export function clearNotification(): Promise { - return callBackend("clear-notification", { }); -} - /** * Download a refund and accept it. */ diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts index 752027b70..4363890eb 100644 --- a/src/webex/wxBackend.ts +++ b/src/webex/wxBackend.ts @@ -28,7 +28,6 @@ import { AmountJson } from "../util/amounts"; import { ConfirmReserveRequest, CreateReserveRequest, - Notifier, ReturnCoinsRequest, WalletDiagnostics, } from "../walletTypes"; @@ -41,7 +40,7 @@ import { MessageType } from "./messages"; import * as wxApi from "./wxApi"; import Port = chrome.runtime.Port; import MessageSender = chrome.runtime.MessageSender; -import { BrowserCryptoWorkerFactory } from "../crypto/cryptoApi"; +import { BrowserCryptoWorkerFactory } from "../crypto/workers/cryptoApi"; import { OpenedPromise, openPromise } from "../util/promiseUtils"; const NeedsWallet = Symbol("NeedsWallet"); @@ -225,9 +224,6 @@ async function handleMessage( case "accept-tip": { return needsWallet().acceptTip(detail.talerTipUri); } - case "clear-notification": { - return needsWallet().clearNotification(); - } case "abort-failed-payment": { if (!detail.contractTermsHash) { throw Error("contracTermsHash not given"); @@ -331,31 +327,6 @@ async function dispatch( } } -class ChromeNotifier implements Notifier { - private ports: Port[] = []; - - constructor() { - chrome.runtime.onConnect.addListener(port => { - console.log("got connect!"); - this.ports.push(port); - port.onDisconnect.addListener(() => { - const i = this.ports.indexOf(port); - if (i >= 0) { - this.ports.splice(i, 1); - } else { - console.error("port already removed"); - } - }); - }); - } - - notify() { - for (const p of this.ports) { - p.postMessage({ notify: true }); - } - } -} - function getTab(tabId: number): Promise { return new Promise((resolve, reject) => { chrome.tabs.get(tabId, (tab: chrome.tabs.Tab) => resolve(tab)); @@ -458,16 +429,13 @@ async function reinitWallet() { return; } const http = new BrowserHttpLib(); - const notifier = new ChromeNotifier(); console.log("setting wallet"); const wallet = new Wallet( currentDatabase, http, - badge, - notifier, new BrowserCryptoWorkerFactory(), ); - wallet.runLoopScheduledRetries().catch((e) => { + wallet.runRetryLoop().catch((e) => { console.log("error during wallet retry loop", e); }); // Useful for debugging in the background page. @@ -621,21 +589,6 @@ export async function wxMain() { return true; }); - // Clear notifications both when the popop opens, - // as well when it closes. - chrome.runtime.onConnect.addListener(port => { - if (port.name === "popup") { - if (currentWallet) { - currentWallet.clearNotification(); - } - port.onDisconnect.addListener(() => { - if (currentWallet) { - currentWallet.clearNotification(); - } - }); - } - }); - // Handlers for catching HTTP requests chrome.webRequest.onHeadersReceived.addListener( details => { -- cgit v1.2.3