embedded: allow setting logLevel in init message
This commit is contained in:
parent
9d6613619e
commit
a0ecc7ca8d
@ -37,6 +37,7 @@ import {
|
|||||||
CoreApiMessageEnvelope,
|
CoreApiMessageEnvelope,
|
||||||
CoreApiResponse,
|
CoreApiResponse,
|
||||||
CoreApiResponseSuccess,
|
CoreApiResponseSuccess,
|
||||||
|
InitRequest,
|
||||||
j2s,
|
j2s,
|
||||||
Logger,
|
Logger,
|
||||||
setGlobalLogLevelFromString,
|
setGlobalLogLevelFromString,
|
||||||
@ -265,6 +266,7 @@ export async function getWallet(args: DefaultNodeWalletArgs = {}): Promise<{
|
|||||||
|
|
||||||
class NativeWalletMessageHandler {
|
class NativeWalletMessageHandler {
|
||||||
walletArgs: DefaultNodeWalletArgs | undefined;
|
walletArgs: DefaultNodeWalletArgs | undefined;
|
||||||
|
initRequest: InitRequest = {};
|
||||||
maybeWallet: Wallet | undefined;
|
maybeWallet: Wallet | undefined;
|
||||||
wp = openPromise<Wallet>();
|
wp = openPromise<Wallet>();
|
||||||
httpLib = new NativeHttpLib();
|
httpLib = new NativeHttpLib();
|
||||||
@ -293,11 +295,9 @@ class NativeWalletMessageHandler {
|
|||||||
const wR = await getWallet(this.walletArgs);
|
const wR = await getWallet(this.walletArgs);
|
||||||
const w = wR.wallet;
|
const w = wR.wallet;
|
||||||
this.maybeWallet = w;
|
this.maybeWallet = w;
|
||||||
const resp = await w.handleCoreApiRequest(
|
const resp = await w.handleCoreApiRequest("initWallet", "native-init", {
|
||||||
"initWallet",
|
...this.initRequest,
|
||||||
"native-init",
|
});
|
||||||
{...this.walletArgs},
|
|
||||||
);
|
|
||||||
initResponse = resp.type == "response" ? resp.result : resp.error;
|
initResponse = resp.type == "response" ? resp.result : resp.error;
|
||||||
w.runTaskLoop().catch((e) => {
|
w.runTaskLoop().catch((e) => {
|
||||||
logger.error(
|
logger.error(
|
||||||
@ -309,8 +309,10 @@ class NativeWalletMessageHandler {
|
|||||||
|
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
case "init": {
|
case "init": {
|
||||||
this.walletArgs = {
|
this.initRequest = {
|
||||||
...args,
|
...args,
|
||||||
|
};
|
||||||
|
this.walletArgs = {
|
||||||
notifyHandler: async (notification: WalletNotification) => {
|
notifyHandler: async (notification: WalletNotification) => {
|
||||||
sendNativeMessage({ type: "notification", payload: notification });
|
sendNativeMessage({ type: "notification", payload: notification });
|
||||||
},
|
},
|
||||||
@ -318,6 +320,10 @@ class NativeWalletMessageHandler {
|
|||||||
httpLib: this.httpLib,
|
httpLib: this.httpLib,
|
||||||
cryptoWorkerType: args.cryptoWorkerType,
|
cryptoWorkerType: args.cryptoWorkerType,
|
||||||
};
|
};
|
||||||
|
const logLevel = args.logLevel;
|
||||||
|
if (logLevel) {
|
||||||
|
setGlobalLogLevelFromString(logLevel);
|
||||||
|
}
|
||||||
await reinit();
|
await reinit();
|
||||||
return wrapResponse({
|
return wrapResponse({
|
||||||
...initResponse,
|
...initResponse,
|
||||||
@ -383,7 +389,11 @@ export function installNativeWalletListener(): void {
|
|||||||
logger.info(`native listener: got request for ${operation} (${id})`);
|
logger.info(`native listener: got request for ${operation} (${id})`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const respMsg = await handler.handleMessage(operation, id, msg.args ?? {});
|
const respMsg = await handler.handleMessage(
|
||||||
|
operation,
|
||||||
|
id,
|
||||||
|
msg.args ?? {},
|
||||||
|
);
|
||||||
logger.info(
|
logger.info(
|
||||||
`native listener: sending success response for ${operation} (${id})`,
|
`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");
|
logger.info("native wallet listener installed");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user