rename activeProfile to profileIndex

This commit is contained in:
Ryan Breen
2023-01-15 15:12:42 -05:00
parent d33d9be72d
commit abc84d4694
4 changed files with 30 additions and 19 deletions

View File

@@ -1,5 +1,7 @@
import { generatePrivateKey, getPublicKey } from "nostr-tools";
const storage = browser.storage.local;
let profiles = [
{name: 'Default', privKey: generatePrivateKey(), hosts: [
{host: 'yosup.app', allowed: true},
@@ -8,9 +10,9 @@ let profiles = [
{name: 'Extra', privKey: generatePrivateKey(), hosts: []},
];
let activeProfile = 0;
let profileIndex = 0;
browser.runtime.onMessage.addListener((message, _sender, sendResponse) => {
browser.runtime.onMessage.addListener(async (message, _sender, sendResponse) => {
console.log(message);
if (message.kind === 'getPubKey') {
const privKey = getPublicKey(message.payload);
@@ -20,7 +22,17 @@ browser.runtime.onMessage.addListener((message, _sender, sendResponse) => {
sendResponse(privKey);
} else if (message.kind === 'getProfiles') {
sendResponse(profiles);
} else if (message.kind === 'getActiveProfile') {
sendResponse(activeProfile);
} else if (message.kind === 'getProfileIndex') {
sendResponse(await getProfileIndex());
} else if (message.kind === 'setProfileIndex') {
await setProfileIndex(message.payload);
}
});
async function getProfileIndex() {
return await storage.get('profileIndex').profileIndex;
}
async function setProfileIndex(profileIndex) {
await storage.set({profileIndex});
}