diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/platform')
-rw-r--r-- | packages/taler-wallet-webextension/src/platform/dev.ts | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/packages/taler-wallet-webextension/src/platform/dev.ts b/packages/taler-wallet-webextension/src/platform/dev.ts index 1d43ad549..005421876 100644 --- a/packages/taler-wallet-webextension/src/platform/dev.ts +++ b/packages/taler-wallet-webextension/src/platform/dev.ts @@ -14,7 +14,7 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { CoreApiResponse, TalerUri } from "@gnu-taler/taler-util"; +import { Logger, TalerUri } from "@gnu-taler/taler-util"; import { WalletOperations } from "@gnu-taler/taler-wallet-core"; import { BackgroundOperations } from "../wxApi.js"; import { @@ -26,7 +26,7 @@ import { defaultSettings, } from "./api.js"; -const frames = ["popup", "wallet"]; +const logger = new Logger("dev.ts"); const api: BackgroundPlatformAPI & ForegroundPlatformAPI = { isFirefox: () => false, @@ -47,15 +47,17 @@ const api: BackgroundPlatformAPI & ForegroundPlatformAPI = { version: "none", }), notifyWhenAppIsReady: () => { - let total = frames.length; + const knownFrames = ["popup", "wallet"]; + let total = knownFrames.length; return new Promise((fn) => { function waitAndNotify(): void { total--; + logger.trace(`waitAndNotify ${total}`); if (total < 1) { fn(); } } - frames.forEach((f) => { + knownFrames.forEach((f) => { const theFrame = window.frames[f as any]; if (theFrame.location.href === "about:blank") { waitAndNotify(); @@ -67,11 +69,15 @@ const api: BackgroundPlatformAPI & ForegroundPlatformAPI = { }, openWalletPage: (page: string) => { - window.frames["wallet" as any].location = `/wallet.html#${page}`; + // @ts-ignore + window.parent.redirectWallet(`wallet.html#${page}`); }, openWalletPageFromPopup: (page: string) => { - window.parent.frames["wallet" as any].location = `/wallet.html#${page}`; - window.location.href = "about:blank"; + // @ts-ignore + window.parent.redirectWallet(`wallet.html#${page}`); + // close the popup + // @ts-ignore + window.parent.closePopup(); }, openWalletURIFromPopup: (page: TalerUri) => { alert("openWalletURIFromPopup not implemented yet"); @@ -87,14 +93,16 @@ const api: BackgroundPlatformAPI & ForegroundPlatformAPI = { useServiceWorkerAsBackgroundProcess: () => false, listenToAllChannels: ( - fn: (m: any, s: any, c: (r: CoreApiResponse) => void) => void, + notifyNewMessage: (message: any) => Promise<MessageResponse>, ) => { window.addEventListener( "message", (event: MessageEvent<IframeMessageType>) => { if (event.data.type !== "command") return; const sender = event.data.header.replyMe; - fn(event.data.body, sender, (resp: CoreApiResponse) => { + + notifyNewMessage(event.data.body as any).then((resp) => { + logger.trace(`listenToAllChannels: from ${sender}`, event); if (event.source) { const msg: IframeMessageResponse = { type: "response", @@ -121,6 +129,7 @@ const api: BackgroundPlatformAPI & ForegroundPlatformAPI = { }, listenToWalletBackground: (onNewMessage: (m: MessageFromBackend) => void) => { function listener(event: MessageEvent<IframeMessageType>): void { + logger.trace(`listenToWalletBackground: `, event); if (event.data.type !== "notification") return; onNewMessage(event.data.body); } @@ -141,7 +150,8 @@ const api: BackgroundPlatformAPI & ForegroundPlatformAPI = { header: { replyMe }, body: payload, }; - window.parent.postMessage(message); + + logger.trace(`sendMessageToBackground: `, message); return new Promise((res, rej) => { function listener(event: MessageEvent<IframeMessageType>): void { @@ -155,6 +165,7 @@ const api: BackgroundPlatformAPI & ForegroundPlatformAPI = { window.parent.removeEventListener("message", listener); } window.parent.addEventListener("message", listener, {}); + window.parent.postMessage(message); }); }, }; |