From abc84d46941b72ffc6ef3cc7999f8579f808e650 Mon Sep 17 00:00:00 2001 From: Ryan Breen Date: Sun, 15 Jan 2023 15:12:42 -0500 Subject: [PATCH] rename activeProfile to profileIndex --- Shared (Extension)/Resources/background.js | 20 ++++++++++++++++---- Shared (Extension)/Resources/popup.html | 2 +- Shared (Extension)/Resources/popup.js | 19 +++++++++---------- logo5.svg | 8 ++++---- 4 files changed, 30 insertions(+), 19 deletions(-) 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 @@
- diff --git a/Shared (Extension)/Resources/popup.js b/Shared (Extension)/Resources/popup.js index b1bb99a..b3e43a7 100644 --- a/Shared (Extension)/Resources/popup.js +++ b/Shared (Extension)/Resources/popup.js @@ -4,12 +4,12 @@ window.Alpine = Alpine; Alpine.data('popup', () => ({ pubKey: '', profiles: [{name: 'Default', privKey: '', hosts: []}], - activeProfile: 0, + profileIndex: 0, visibleKey: false, async init() { await this.getProfiles(); - await this.getPrivKeyForProfile(); + await this.getPubKey(); }, async saveKey() { @@ -18,15 +18,15 @@ Alpine.data('popup', () => ({ async getProfiles() { this.profiles = await browser.runtime.sendMessage({kind: 'getProfiles'}); - this.activeProfile = await browser.runtime.sendMessage({kind: 'getActiveProfile'}); + this.profileIndex = await browser.runtime.sendMessage({kind: 'getProfileIndex'}); }, - async getPrivKeyForProfile() { + async setProfileIndex() { + await browser.runtime.sendMessage({kind: 'setProfileIndex', payload: this.profileIndex}); await this.getPubKey(); }, async deleteSite(index) { - confirm("hello"); let newSites = [...this.hosts]; newSites.splice(index, 1); this.hosts = newSites; @@ -34,15 +34,14 @@ Alpine.data('popup', () => ({ async getPubKey() { this.pubKey = await browser.runtime.sendMessage({kind: 'getPubKey', payload: this.profile.privKey}); - console.log('Pub key: ', this.pubKey); }, async newProfile() { let newKey = await browser.runtime.sendMessage({kind: 'newKey'}); const newProfile = {name: 'New Profile', privKey: newKey}; this.profiles.push(newProfile); - this.activeProfile = this.profiles.length - 1; - browser.notifications.create('confirm-me', {type: "basic", message: "New private key generated"}); + this.profileIndex = this.profiles.length - 1; + await this.setProfileIndex(); }, get hasValidPubKey() { @@ -50,7 +49,7 @@ Alpine.data('popup', () => ({ }, get profile() { - return this.profiles[this.activeProfile]; + return this.profiles[this.profileIndex]; }, get hosts() { @@ -58,7 +57,7 @@ Alpine.data('popup', () => ({ }, set hosts(value) { - this.profiles[this.activeProfile].hosts = value; + this.profiles[this.profileIndex].hosts = value; } })); diff --git a/logo5.svg b/logo5.svg index 7a4448d..c501339 100644 --- a/logo5.svg +++ b/logo5.svg @@ -9,9 +9,9 @@ id="svg19420" inkscape:version="1.2.2 (b0a84865, 2022-12-01)" sodipodi:docname="logo5.svg" - inkscape:export-filename="icon-512.png" - inkscape:export-xdpi="61.927616" - inkscape:export-ydpi="61.927616" + inkscape:export-filename="toolbar-16.png" + inkscape:export-xdpi="8.667181" + inkscape:export-ydpi="8.667181" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns="http://www.w3.org/2000/svg" @@ -28,7 +28,7 @@ inkscape:document-units="mm" showgrid="false" inkscape:zoom="1.241849" - inkscape:cx="380.88367" + inkscape:cx="212.18361" inkscape:cy="471.47439" inkscape:window-width="1390" inkscape:window-height="1205"