make dev build work again
This commit is contained in:
parent
67fe4e8c20
commit
b916e53c68
@ -15,18 +15,16 @@
|
|||||||
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
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 { 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 = [
|
const devEntryPoints = [
|
||||||
"src/popupEntryPoint.tsx",
|
"src/popupEntryPoint.dev.tsx",
|
||||||
"src/walletEntryPoint.tsx",
|
"src/walletEntryPoint.dev.tsx",
|
||||||
"src/background.ts",
|
"src/background.dev.ts",
|
||||||
"src/taler-wallet-interaction-loader.ts",
|
|
||||||
"src/taler-wallet-interaction-support.ts",
|
|
||||||
"src/browserWorkerEntry.ts",
|
"src/browserWorkerEntry.ts",
|
||||||
"src/stories.tsx",
|
"src/stories.tsx",
|
||||||
];
|
];
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
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 { WalletOperations } from "@gnu-taler/taler-wallet-core";
|
||||||
import { BackgroundOperations } from "../wxApi.js";
|
import { BackgroundOperations } from "../wxApi.js";
|
||||||
import {
|
import {
|
||||||
@ -26,7 +26,7 @@ import {
|
|||||||
defaultSettings,
|
defaultSettings,
|
||||||
} from "./api.js";
|
} from "./api.js";
|
||||||
|
|
||||||
const frames = ["popup", "wallet"];
|
const logger = new Logger("dev.ts");
|
||||||
|
|
||||||
const api: BackgroundPlatformAPI & ForegroundPlatformAPI = {
|
const api: BackgroundPlatformAPI & ForegroundPlatformAPI = {
|
||||||
isFirefox: () => false,
|
isFirefox: () => false,
|
||||||
@ -47,15 +47,17 @@ const api: BackgroundPlatformAPI & ForegroundPlatformAPI = {
|
|||||||
version: "none",
|
version: "none",
|
||||||
}),
|
}),
|
||||||
notifyWhenAppIsReady: () => {
|
notifyWhenAppIsReady: () => {
|
||||||
let total = frames.length;
|
const knownFrames = ["popup", "wallet"];
|
||||||
|
let total = knownFrames.length;
|
||||||
return new Promise((fn) => {
|
return new Promise((fn) => {
|
||||||
function waitAndNotify(): void {
|
function waitAndNotify(): void {
|
||||||
total--;
|
total--;
|
||||||
|
logger.trace(`waitAndNotify ${total}`);
|
||||||
if (total < 1) {
|
if (total < 1) {
|
||||||
fn();
|
fn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
frames.forEach((f) => {
|
knownFrames.forEach((f) => {
|
||||||
const theFrame = window.frames[f as any];
|
const theFrame = window.frames[f as any];
|
||||||
if (theFrame.location.href === "about:blank") {
|
if (theFrame.location.href === "about:blank") {
|
||||||
waitAndNotify();
|
waitAndNotify();
|
||||||
@ -67,11 +69,15 @@ const api: BackgroundPlatformAPI & ForegroundPlatformAPI = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
openWalletPage: (page: string) => {
|
openWalletPage: (page: string) => {
|
||||||
window.frames["wallet" as any].location = `/wallet.html#${page}`;
|
// @ts-ignore
|
||||||
|
window.parent.redirectWallet(`wallet.html#${page}`);
|
||||||
},
|
},
|
||||||
openWalletPageFromPopup: (page: string) => {
|
openWalletPageFromPopup: (page: string) => {
|
||||||
window.parent.frames["wallet" as any].location = `/wallet.html#${page}`;
|
// @ts-ignore
|
||||||
window.location.href = "about:blank";
|
window.parent.redirectWallet(`wallet.html#${page}`);
|
||||||
|
// close the popup
|
||||||
|
// @ts-ignore
|
||||||
|
window.parent.closePopup();
|
||||||
},
|
},
|
||||||
openWalletURIFromPopup: (page: TalerUri) => {
|
openWalletURIFromPopup: (page: TalerUri) => {
|
||||||
alert("openWalletURIFromPopup not implemented yet");
|
alert("openWalletURIFromPopup not implemented yet");
|
||||||
@ -87,14 +93,16 @@ const api: BackgroundPlatformAPI & ForegroundPlatformAPI = {
|
|||||||
useServiceWorkerAsBackgroundProcess: () => false,
|
useServiceWorkerAsBackgroundProcess: () => false,
|
||||||
|
|
||||||
listenToAllChannels: (
|
listenToAllChannels: (
|
||||||
fn: (m: any, s: any, c: (r: CoreApiResponse) => void) => void,
|
notifyNewMessage: (message: any) => Promise<MessageResponse>,
|
||||||
) => {
|
) => {
|
||||||
window.addEventListener(
|
window.addEventListener(
|
||||||
"message",
|
"message",
|
||||||
(event: MessageEvent<IframeMessageType>) => {
|
(event: MessageEvent<IframeMessageType>) => {
|
||||||
if (event.data.type !== "command") return;
|
if (event.data.type !== "command") return;
|
||||||
const sender = event.data.header.replyMe;
|
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) {
|
if (event.source) {
|
||||||
const msg: IframeMessageResponse = {
|
const msg: IframeMessageResponse = {
|
||||||
type: "response",
|
type: "response",
|
||||||
@ -121,6 +129,7 @@ const api: BackgroundPlatformAPI & ForegroundPlatformAPI = {
|
|||||||
},
|
},
|
||||||
listenToWalletBackground: (onNewMessage: (m: MessageFromBackend) => void) => {
|
listenToWalletBackground: (onNewMessage: (m: MessageFromBackend) => void) => {
|
||||||
function listener(event: MessageEvent<IframeMessageType>): void {
|
function listener(event: MessageEvent<IframeMessageType>): void {
|
||||||
|
logger.trace(`listenToWalletBackground: `, event);
|
||||||
if (event.data.type !== "notification") return;
|
if (event.data.type !== "notification") return;
|
||||||
onNewMessage(event.data.body);
|
onNewMessage(event.data.body);
|
||||||
}
|
}
|
||||||
@ -141,7 +150,8 @@ const api: BackgroundPlatformAPI & ForegroundPlatformAPI = {
|
|||||||
header: { replyMe },
|
header: { replyMe },
|
||||||
body: payload,
|
body: payload,
|
||||||
};
|
};
|
||||||
window.parent.postMessage(message);
|
|
||||||
|
logger.trace(`sendMessageToBackground: `, message);
|
||||||
|
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
function listener(event: MessageEvent<IframeMessageType>): void {
|
function listener(event: MessageEvent<IframeMessageType>): void {
|
||||||
@ -155,6 +165,7 @@ const api: BackgroundPlatformAPI & ForegroundPlatformAPI = {
|
|||||||
window.parent.removeEventListener("message", listener);
|
window.parent.removeEventListener("message", listener);
|
||||||
}
|
}
|
||||||
window.parent.addEventListener("message", listener, {});
|
window.parent.addEventListener("message", listener, {});
|
||||||
|
window.parent.postMessage(message);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user