rename activeProfile to profileIndex
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import { generatePrivateKey, getPublicKey } from "nostr-tools";
|
import { generatePrivateKey, getPublicKey } from "nostr-tools";
|
||||||
|
|
||||||
|
const storage = browser.storage.local;
|
||||||
|
|
||||||
let profiles = [
|
let profiles = [
|
||||||
{name: 'Default', privKey: generatePrivateKey(), hosts: [
|
{name: 'Default', privKey: generatePrivateKey(), hosts: [
|
||||||
{host: 'yosup.app', allowed: true},
|
{host: 'yosup.app', allowed: true},
|
||||||
@@ -8,9 +10,9 @@ let profiles = [
|
|||||||
{name: 'Extra', privKey: generatePrivateKey(), hosts: []},
|
{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);
|
console.log(message);
|
||||||
if (message.kind === 'getPubKey') {
|
if (message.kind === 'getPubKey') {
|
||||||
const privKey = getPublicKey(message.payload);
|
const privKey = getPublicKey(message.payload);
|
||||||
@@ -20,7 +22,17 @@ browser.runtime.onMessage.addListener((message, _sender, sendResponse) => {
|
|||||||
sendResponse(privKey);
|
sendResponse(privKey);
|
||||||
} else if (message.kind === 'getProfiles') {
|
} else if (message.kind === 'getProfiles') {
|
||||||
sendResponse(profiles);
|
sendResponse(profiles);
|
||||||
} else if (message.kind === 'getActiveProfile') {
|
} else if (message.kind === 'getProfileIndex') {
|
||||||
sendResponse(activeProfile);
|
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});
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
<body x-data="popup">
|
<body x-data="popup">
|
||||||
<div class="profiles">
|
<div class="profiles">
|
||||||
<label for="profile">Profile</label>
|
<label for="profile">Profile</label>
|
||||||
<select x-model="activeProfile" name="profile" id="profile" @change="getPrivKeyForProfile()">
|
<select x-model="profileIndex" name="profile" id="profile" @change="setProfileIndex()">
|
||||||
<template x-for="(prof, index) in profiles">
|
<template x-for="(prof, index) in profiles">
|
||||||
<option x-text="prof.name" :value="index"></option>
|
<option x-text="prof.name" :value="index"></option>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ window.Alpine = Alpine;
|
|||||||
Alpine.data('popup', () => ({
|
Alpine.data('popup', () => ({
|
||||||
pubKey: '',
|
pubKey: '',
|
||||||
profiles: [{name: 'Default', privKey: '', hosts: []}],
|
profiles: [{name: 'Default', privKey: '', hosts: []}],
|
||||||
activeProfile: 0,
|
profileIndex: 0,
|
||||||
visibleKey: false,
|
visibleKey: false,
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
await this.getProfiles();
|
await this.getProfiles();
|
||||||
await this.getPrivKeyForProfile();
|
await this.getPubKey();
|
||||||
},
|
},
|
||||||
|
|
||||||
async saveKey() {
|
async saveKey() {
|
||||||
@@ -18,15 +18,15 @@ Alpine.data('popup', () => ({
|
|||||||
|
|
||||||
async getProfiles() {
|
async getProfiles() {
|
||||||
this.profiles = await browser.runtime.sendMessage({kind: '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();
|
await this.getPubKey();
|
||||||
},
|
},
|
||||||
|
|
||||||
async deleteSite(index) {
|
async deleteSite(index) {
|
||||||
confirm("hello");
|
|
||||||
let newSites = [...this.hosts];
|
let newSites = [...this.hosts];
|
||||||
newSites.splice(index, 1);
|
newSites.splice(index, 1);
|
||||||
this.hosts = newSites;
|
this.hosts = newSites;
|
||||||
@@ -34,15 +34,14 @@ Alpine.data('popup', () => ({
|
|||||||
|
|
||||||
async getPubKey() {
|
async getPubKey() {
|
||||||
this.pubKey = await browser.runtime.sendMessage({kind: 'getPubKey', payload: this.profile.privKey});
|
this.pubKey = await browser.runtime.sendMessage({kind: 'getPubKey', payload: this.profile.privKey});
|
||||||
console.log('Pub key: ', this.pubKey);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async newProfile() {
|
async newProfile() {
|
||||||
let newKey = await browser.runtime.sendMessage({kind: 'newKey'});
|
let newKey = await browser.runtime.sendMessage({kind: 'newKey'});
|
||||||
const newProfile = {name: 'New Profile', privKey: newKey};
|
const newProfile = {name: 'New Profile', privKey: newKey};
|
||||||
this.profiles.push(newProfile);
|
this.profiles.push(newProfile);
|
||||||
this.activeProfile = this.profiles.length - 1;
|
this.profileIndex = this.profiles.length - 1;
|
||||||
browser.notifications.create('confirm-me', {type: "basic", message: "New private key generated"});
|
await this.setProfileIndex();
|
||||||
},
|
},
|
||||||
|
|
||||||
get hasValidPubKey() {
|
get hasValidPubKey() {
|
||||||
@@ -50,7 +49,7 @@ Alpine.data('popup', () => ({
|
|||||||
},
|
},
|
||||||
|
|
||||||
get profile() {
|
get profile() {
|
||||||
return this.profiles[this.activeProfile];
|
return this.profiles[this.profileIndex];
|
||||||
},
|
},
|
||||||
|
|
||||||
get hosts() {
|
get hosts() {
|
||||||
@@ -58,7 +57,7 @@ Alpine.data('popup', () => ({
|
|||||||
},
|
},
|
||||||
|
|
||||||
set hosts(value) {
|
set hosts(value) {
|
||||||
this.profiles[this.activeProfile].hosts = value;
|
this.profiles[this.profileIndex].hosts = value;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
id="svg19420"
|
id="svg19420"
|
||||||
inkscape:version="1.2.2 (b0a84865, 2022-12-01)"
|
inkscape:version="1.2.2 (b0a84865, 2022-12-01)"
|
||||||
sodipodi:docname="logo5.svg"
|
sodipodi:docname="logo5.svg"
|
||||||
inkscape:export-filename="icon-512.png"
|
inkscape:export-filename="toolbar-16.png"
|
||||||
inkscape:export-xdpi="61.927616"
|
inkscape:export-xdpi="8.667181"
|
||||||
inkscape:export-ydpi="61.927616"
|
inkscape:export-ydpi="8.667181"
|
||||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
inkscape:document-units="mm"
|
inkscape:document-units="mm"
|
||||||
showgrid="false"
|
showgrid="false"
|
||||||
inkscape:zoom="1.241849"
|
inkscape:zoom="1.241849"
|
||||||
inkscape:cx="380.88367"
|
inkscape:cx="212.18361"
|
||||||
inkscape:cy="471.47439"
|
inkscape:cy="471.47439"
|
||||||
inkscape:window-width="1390"
|
inkscape:window-width="1390"
|
||||||
inkscape:window-height="1205"
|
inkscape:window-height="1205"
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 8.0 KiB |
Reference in New Issue
Block a user