embedded: allow setting logLevel in init message

This commit is contained in:
Florian Dold 2023-02-02 20:46:16 +01:00
parent 9d6613619e
commit a0ecc7ca8d
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B

View File

@ -37,6 +37,7 @@ import {
CoreApiMessageEnvelope,
CoreApiResponse,
CoreApiResponseSuccess,
InitRequest,
j2s,
Logger,
setGlobalLogLevelFromString,
@ -265,6 +266,7 @@ export async function getWallet(args: DefaultNodeWalletArgs = {}): Promise<{
class NativeWalletMessageHandler {
walletArgs: DefaultNodeWalletArgs | undefined;
initRequest: InitRequest = {};
maybeWallet: Wallet | undefined;
wp = openPromise<Wallet>();
httpLib = new NativeHttpLib();
@ -293,11 +295,9 @@ class NativeWalletMessageHandler {
const wR = await getWallet(this.walletArgs);
const w = wR.wallet;
this.maybeWallet = w;
const resp = await w.handleCoreApiRequest(
"initWallet",
"native-init",
{...this.walletArgs},
);
const resp = await w.handleCoreApiRequest("initWallet", "native-init", {
...this.initRequest,
});
initResponse = resp.type == "response" ? resp.result : resp.error;
w.runTaskLoop().catch((e) => {
logger.error(
@ -309,8 +309,10 @@ class NativeWalletMessageHandler {
switch (operation) {
case "init": {
this.walletArgs = {
this.initRequest = {
...args,
};
this.walletArgs = {
notifyHandler: async (notification: WalletNotification) => {
sendNativeMessage({ type: "notification", payload: notification });
},
@ -318,6 +320,10 @@ class NativeWalletMessageHandler {
httpLib: this.httpLib,
cryptoWorkerType: args.cryptoWorkerType,
};
const logLevel = args.logLevel;
if (logLevel) {
setGlobalLogLevelFromString(logLevel);
}
await reinit();
return wrapResponse({
...initResponse,
@ -383,7 +389,11 @@ export function installNativeWalletListener(): void {
logger.info(`native listener: got request for ${operation} (${id})`);
try {
const respMsg = await handler.handleMessage(operation, id, msg.args ?? {});
const respMsg = await handler.handleMessage(
operation,
id,
msg.args ?? {},
);
logger.info(
`native listener: sending success response for ${operation} (${id})`,
);
@ -400,7 +410,7 @@ export function installNativeWalletListener(): void {
}
};
qjsOs.setMessageFromHostHandler((m) => onMessage(m))
qjsOs.setMessageFromHostHandler((m) => onMessage(m));
logger.info("native wallet listener installed");
}