Replace console.log with bglog.

This commit is contained in:
Ryan Breen
2023-01-26 20:26:23 -05:00
parent e08d19855e
commit f98ab34f0a
4 changed files with 15 additions and 11 deletions

View File

@@ -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;
}

View File

@@ -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];
});

View File

@@ -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 () => {

View File

@@ -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 },
});
}