diff --git a/.env.beta b/.env.beta index 44afc1d5..2ebe645f 100644 --- a/.env.beta +++ b/.env.beta @@ -1,2 +1,2 @@ VITE_APP_SIGNALING_SERVER_BASE_URL=wss://signaling-server-betanet.radixdlt.com -VITE_APP_LOG_LEVEL=debug \ No newline at end of file +VITE_APP_LOG_LEVEL=info \ No newline at end of file diff --git a/src/chrome/chrome-connector-client.ts b/src/chrome/chrome-connector-client.ts index 38a26e4a..669eb797 100644 --- a/src/chrome/chrome-connector-client.ts +++ b/src/chrome/chrome-connector-client.ts @@ -1,7 +1,7 @@ import { Connector, ConnectorType } from 'connector/connector' import { StorageClient } from 'connector/storage/storage-client' import { config } from 'config' -import { LogLevelDesc } from 'loglevel' +import log, { LogLevelDesc } from 'loglevel' import { map, Subscription } from 'rxjs' import { ChromeDAppClient } from './chrome-dapp-client' @@ -10,10 +10,20 @@ const chromeDAppClient = ChromeDAppClient() export const ChromeConnectorClient = (logLevel: LogLevelDesc) => { let connector: ConnectorType | undefined let subscriptions: Subscription | undefined + const logger = log + + chrome.storage.local.get('loglevel').then((value) => { + const storedLoglevel = value['loglevel'] + + if (storedLoglevel === 'DEBUG') + console.log(`Radix Connector loglevel: 'debug'`) + + logger.setLevel(storedLoglevel || logLevel) + }) const createConnector = () => { connector = Connector({ - logLevel, + logger, storageClient: StorageClient({ id: config.storage.key }), generateConnectionPassword: false, }) diff --git a/src/chrome/content.ts b/src/chrome/content.ts index 4532c891..b5151057 100644 --- a/src/chrome/content.ts +++ b/src/chrome/content.ts @@ -1,18 +1,27 @@ +import { config } from 'config' import { ChromeConnectorClient } from './chrome-connector-client' import { ChromeDAppClient, messageLifeCycleEvent } from './chrome-dapp-client' import { decorateMessage } from './helpers/decorate-message' -const connectorClient = ChromeConnectorClient('debug') +const connectorClient = ChromeConnectorClient(config.logLevel) const chromeDAppClient = ChromeDAppClient() chromeDAppClient.messageListener((message) => { - decorateMessage(message) - .map(connectorClient.getConnector().sendMessage) - .map(chrome.runtime.sendMessage) - .andThen(() => - chromeDAppClient.sendMessageEvent( - message.requestId, - messageLifeCycleEvent.receivedByExtension - ) + if (message.type === 'debugMode') { + const loglevel = message.value ? 'DEBUG' : 'INFO' + console.log( + `🛠 Setting loglevel to: ${loglevel}, reload the window for effects to take place` ) + chrome.storage.local.set({ loglevel }) + } else { + decorateMessage(message) + .map(connectorClient.getConnector().sendMessage) + .map(chrome.runtime.sendMessage) + .andThen(() => + chromeDAppClient.sendMessageEvent( + message.requestId, + messageLifeCycleEvent.receivedByExtension + ) + ) + } })