diff options
author | Sebastian <sebasjm@gmail.com> | 2023-01-17 15:59:55 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-01-17 16:01:28 -0300 |
commit | 252382a9375ea05f62389e33f111c3fa008d8fff (patch) | |
tree | e362956a60796fb533260ac2e3f159af6c1c5168 /packages/taler-wallet-webextension/src/platform/chrome.ts | |
parent | 2c14a180c12229623a64e1626da6b05777a7b397 (diff) | |
download | wallet-core-252382a9375ea05f62389e33f111c3fa008d8fff.tar.xz |
throw error after 5 seconds if wallet-core didn't reply to a command
Diffstat (limited to 'packages/taler-wallet-webextension/src/platform/chrome.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/platform/chrome.ts | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/packages/taler-wallet-webextension/src/platform/chrome.ts b/packages/taler-wallet-webextension/src/platform/chrome.ts index fc51a65fb..23730c2d3 100644 --- a/packages/taler-wallet-webextension/src/platform/chrome.ts +++ b/packages/taler-wallet-webextension/src/platform/chrome.ts @@ -14,8 +14,13 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { classifyTalerUri, Logger, TalerUriType } from "@gnu-taler/taler-util"; -import { WalletOperations } from "@gnu-taler/taler-wallet-core"; +import { + classifyTalerUri, + Logger, + TalerErrorCode, + TalerUriType, +} from "@gnu-taler/taler-util"; +import { TalerError, WalletOperations } from "@gnu-taler/taler-wallet-core"; import { BackgroundOperations } from "../wxApi.js"; import { BackgroundPlatformAPI, @@ -321,12 +326,15 @@ async function sendMessageToBackground< return new Promise<any>((resolve, reject) => { logger.trace("send operation to the wallet background", message); let timedout = false; - setTimeout(() => { + const timerId = setTimeout(() => { timedout = true; - reject("timedout"); - }, 2000); + throw TalerError.fromDetail(TalerErrorCode.GENERIC_TIMEOUT, {}); + }, 5 * 1000); //five seconds chrome.runtime.sendMessage(messageWithId, (backgroundResponse) => { - if (timedout) return false; + if (timedout) { + return false; //already rejected + } + clearTimeout(timerId); if (chrome.runtime.lastError) { reject(chrome.runtime.lastError.message); } else { @@ -576,26 +584,26 @@ function setAlertedIcon(): void { interface OffscreenCanvasRenderingContext2D extends CanvasState, - CanvasTransform, - CanvasCompositing, - CanvasImageSmoothing, - CanvasFillStrokeStyles, - CanvasShadowStyles, - CanvasFilters, - CanvasRect, - CanvasDrawPath, - CanvasUserInterface, - CanvasText, - CanvasDrawImage, - CanvasImageData, - CanvasPathDrawingStyles, - CanvasTextDrawingStyles, - CanvasPath { + CanvasTransform, + CanvasCompositing, + CanvasImageSmoothing, + CanvasFillStrokeStyles, + CanvasShadowStyles, + CanvasFilters, + CanvasRect, + CanvasDrawPath, + CanvasUserInterface, + CanvasText, + CanvasDrawImage, + CanvasImageData, + CanvasPathDrawingStyles, + CanvasTextDrawingStyles, + CanvasPath { readonly canvas: OffscreenCanvas; } declare const OffscreenCanvasRenderingContext2D: { prototype: OffscreenCanvasRenderingContext2D; - new (): OffscreenCanvasRenderingContext2D; + new(): OffscreenCanvasRenderingContext2D; }; interface OffscreenCanvas extends EventTarget { @@ -608,7 +616,7 @@ interface OffscreenCanvas extends EventTarget { } declare const OffscreenCanvas: { prototype: OffscreenCanvas; - new (width: number, height: number): OffscreenCanvas; + new(width: number, height: number): OffscreenCanvas; }; function createCanvas(size: number): OffscreenCanvas { |