Replace console.log with bglog.
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
} from 'nostr-tools';
|
} from 'nostr-tools';
|
||||||
|
|
||||||
const storage = browser.storage.local;
|
const storage = browser.storage.local;
|
||||||
|
const log = msg => console.log('Background: ', msg);
|
||||||
|
|
||||||
browser.runtime.onInstalled.addListener(async ({ reason }) => {
|
browser.runtime.onInstalled.addListener(async ({ reason }) => {
|
||||||
// I would like to be able to skip this for development purposes
|
// 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(
|
browser.runtime.onMessage.addListener(
|
||||||
async (message, _sender, sendResponse) => {
|
async (message, _sender, sendResponse) => {
|
||||||
console.log(message);
|
log(message);
|
||||||
|
|
||||||
switch (message.kind) {
|
switch (message.kind) {
|
||||||
case 'log':
|
case 'log':
|
||||||
console.log('Background Log: ', message.payload);
|
console.log(
|
||||||
|
message.payload.module ? `${module}: ` : '',
|
||||||
|
message.payload.msg
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 'init':
|
case 'init':
|
||||||
await initialize();
|
await initialize();
|
||||||
@@ -146,9 +150,7 @@ async function getPrivKey() {
|
|||||||
|
|
||||||
async function getNpubKey() {
|
async function getNpubKey() {
|
||||||
let pubKey = await getPubKey();
|
let pubKey = await getPubKey();
|
||||||
console.log('pubKey: ', pubKey);
|
|
||||||
let npubKey = nip19.npubEncode(pubKey);
|
let npubKey = nip19.npubEncode(pubKey);
|
||||||
console.log('npub key: ', npubKey);
|
|
||||||
return npubKey;
|
return npubKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ window.nostr = {
|
|||||||
let reqId = Math.random().toString();
|
let reqId = Math.random().toString();
|
||||||
return new Promise((resolve, _reject) => {
|
return new Promise((resolve, _reject) => {
|
||||||
this.requests[reqId] = resolve;
|
this.requests[reqId] = resolve;
|
||||||
console.log(`Event ${reqId}: ${kind}, payload: `, payload);
|
|
||||||
window.postMessage({ kind, reqId, payload }, '*');
|
window.postMessage({ kind, reqId, payload }, '*');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -57,7 +56,6 @@ window.addEventListener('message', message => {
|
|||||||
|
|
||||||
if (!validEvents.includes(kind)) return;
|
if (!validEvents.includes(kind)) return;
|
||||||
|
|
||||||
console.log(`Event ${reqId}: Received payload:`, payload);
|
|
||||||
window.nostr.requests[reqId](payload);
|
window.nostr.requests[reqId](payload);
|
||||||
delete window.nostr.requests[reqId];
|
delete window.nostr.requests[reqId];
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
console.log('test!');
|
import { bglog } from './utils';
|
||||||
|
|
||||||
import Alpine from 'alpinejs';
|
import Alpine from 'alpinejs';
|
||||||
window.Alpine = Alpine;
|
window.Alpine = Alpine;
|
||||||
|
|
||||||
|
const log = msg => bglog(msg, 'popup');
|
||||||
|
|
||||||
Alpine.data('popup', () => ({
|
Alpine.data('popup', () => ({
|
||||||
privKey: '',
|
privKey: '',
|
||||||
pubKey: '',
|
pubKey: '',
|
||||||
@@ -17,7 +18,7 @@ Alpine.data('popup', () => ({
|
|||||||
confirmDelete: false,
|
confirmDelete: false,
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
console.log('Initializing backend.');
|
log('Initializing backend.');
|
||||||
await browser.runtime.sendMessage({ kind: 'init' });
|
await browser.runtime.sendMessage({ kind: 'init' });
|
||||||
|
|
||||||
this.$watch('profileIndex', async () => {
|
this.$watch('profileIndex', async () => {
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
export async function bglog(msg) {
|
export async function bglog(msg, module = null) {
|
||||||
await browser.runtime.sendMessage({ kind: 'log', payload: msg });
|
await browser.runtime.sendMessage({
|
||||||
|
kind: 'log',
|
||||||
|
payload: { msg, module },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user