diff options
author | Sebastian <sebasjm@gmail.com> | 2023-06-01 12:22:27 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-06-01 12:24:07 -0300 |
commit | b916e53c68fc4e31fc7d945c450aaf9b0aeefc50 (patch) | |
tree | 9144f41e691d7f068a412b7b63bc4c36e875cd99 /packages | |
parent | 67fe4e8c20dd810aa6bf124c457bf8161ce56589 (diff) | |
download | wallet-core-b916e53c68fc4e31fc7d945c450aaf9b0aeefc50.tar.xz |
make dev build work again
Diffstat (limited to 'packages')
-rwxr-xr-x | packages/taler-wallet-webextension/dev.mjs | 14 | ||||
-rw-r--r-- | packages/taler-wallet-webextension/src/platform/dev.ts | 31 |
2 files changed, 27 insertions, 18 deletions
diff --git a/packages/taler-wallet-webextension/dev.mjs b/packages/taler-wallet-webextension/dev.mjs index 4ba649a7e..5577b1f0e 100755 --- a/packages/taler-wallet-webextension/dev.mjs +++ b/packages/taler-wallet-webextension/dev.mjs @@ -15,18 +15,16 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import linaria from "@linaria/esbuild"; +import { getFilesInDirectory, initializeDev } from "@gnu-taler/web-util/build"; import { serve } from "@gnu-taler/web-util/node"; -import { initializeDev, getFilesInDirectory } from "@gnu-taler/web-util/build"; +import linaria from "@linaria/esbuild"; -const allStaticFiles = getFilesInDirectory("static"); +const allStaticFiles = getFilesInDirectory("src/spa"); const devEntryPoints = [ - "src/popupEntryPoint.tsx", - "src/walletEntryPoint.tsx", - "src/background.ts", - "src/taler-wallet-interaction-loader.ts", - "src/taler-wallet-interaction-support.ts", + "src/popupEntryPoint.dev.tsx", + "src/walletEntryPoint.dev.tsx", + "src/background.dev.ts", "src/browserWorkerEntry.ts", "src/stories.tsx", ]; 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); }); }, }; |