diff --git a/Shared (Extension)/Resources/background.js b/Shared (Extension)/Resources/background.js index 0b84c33..eb0381d 100644 --- a/Shared (Extension)/Resources/background.js +++ b/Shared (Extension)/Resources/background.js @@ -7,6 +7,7 @@ import { } from 'nostr-tools'; const storage = browser.storage.local; +const log = msg => console.log('Background: ', msg); browser.runtime.onInstalled.addListener(async ({ reason }) => { // I would like to be able to skip this for development purposes @@ -24,11 +25,14 @@ browser.runtime.onInstalled.addListener(async ({ reason }) => { browser.runtime.onMessage.addListener( async (message, _sender, sendResponse) => { - console.log(message); + log(message); switch (message.kind) { case 'log': - console.log('Background Log: ', message.payload); + console.log( + message.payload.module ? `${module}: ` : '', + message.payload.msg + ); break; case 'init': await initialize(); @@ -146,9 +150,7 @@ async function getPrivKey() { async function getNpubKey() { let pubKey = await getPubKey(); - console.log('pubKey: ', pubKey); let npubKey = nip19.npubEncode(pubKey); - console.log('npub key: ', npubKey); return npubKey; } diff --git a/Shared (Extension)/Resources/nostr.js b/Shared (Extension)/Resources/nostr.js index f302f14..83371fd 100644 --- a/Shared (Extension)/Resources/nostr.js +++ b/Shared (Extension)/Resources/nostr.js @@ -23,7 +23,6 @@ window.nostr = { let reqId = Math.random().toString(); return new Promise((resolve, _reject) => { this.requests[reqId] = resolve; - console.log(`Event ${reqId}: ${kind}, payload: `, payload); window.postMessage({ kind, reqId, payload }, '*'); }); }, @@ -57,7 +56,6 @@ window.addEventListener('message', message => { if (!validEvents.includes(kind)) return; - console.log(`Event ${reqId}: Received payload:`, payload); window.nostr.requests[reqId](payload); delete window.nostr.requests[reqId]; }); diff --git a/Shared (Extension)/Resources/popup.js b/Shared (Extension)/Resources/popup.js index f092782..29b3323 100644 --- a/Shared (Extension)/Resources/popup.js +++ b/Shared (Extension)/Resources/popup.js @@ -1,8 +1,9 @@ -console.log('test!'); - +import { bglog } from './utils'; import Alpine from 'alpinejs'; window.Alpine = Alpine; +const log = msg => bglog(msg, 'popup'); + Alpine.data('popup', () => ({ privKey: '', pubKey: '', @@ -17,7 +18,7 @@ Alpine.data('popup', () => ({ confirmDelete: false, async init() { - console.log('Initializing backend.'); + log('Initializing backend.'); await browser.runtime.sendMessage({ kind: 'init' }); this.$watch('profileIndex', async () => { diff --git a/Shared (Extension)/Resources/utils.js b/Shared (Extension)/Resources/utils.js index 34c825a..7e7aa29 100644 --- a/Shared (Extension)/Resources/utils.js +++ b/Shared (Extension)/Resources/utils.js @@ -1,3 +1,6 @@ -export async function bglog(msg) { - await browser.runtime.sendMessage({ kind: 'log', payload: msg }); +export async function bglog(msg, module = null) { + await browser.runtime.sendMessage({ + kind: 'log', + payload: { msg, module }, + }); }