diff --git a/Shared (Extension)/Resources/background.js b/Shared (Extension)/Resources/background.js
index c1885b1..90fb50f 100644
--- a/Shared (Extension)/Resources/background.js
+++ b/Shared (Extension)/Resources/background.js
@@ -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});
+}
\ No newline at end of file
diff --git a/Shared (Extension)/Resources/popup.html b/Shared (Extension)/Resources/popup.html
index 5444e1f..08c55a4 100644
--- a/Shared (Extension)/Resources/popup.html
+++ b/Shared (Extension)/Resources/popup.html
@@ -8,7 +8,7 @@
-