added delete profile button
This commit is contained in:
@@ -46,6 +46,9 @@ browser.runtime.onMessage.addListener(async (message, _sender, sendResponse) =>
|
||||
case 'clearData':
|
||||
await browser.storage.local.clear();
|
||||
break;
|
||||
case 'deleteProfile':
|
||||
await deleteProfile();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -122,4 +125,12 @@ async function saveProfile(profile) {
|
||||
let profiles = await get('profiles');
|
||||
profiles[index] = profile;
|
||||
await storage.set({profiles});
|
||||
}
|
||||
|
||||
async function deleteProfile() {
|
||||
let index = await getProfileIndex();
|
||||
let profiles = await get('profiles');
|
||||
profiles.splice(index, 1);
|
||||
let profileIndex = Math.max(index - 1, 0);
|
||||
await storage.set({profiles, profileIndex});
|
||||
}
|
||||
@@ -19,6 +19,10 @@ input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.profile-buttons {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#priv-key, #pub-key {
|
||||
font-family: monospace;
|
||||
}
|
||||
@@ -32,6 +36,10 @@ input {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.profile-name {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.key {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
@@ -9,12 +9,16 @@
|
||||
<body x-data="popup">
|
||||
<div class="profiles">
|
||||
<label for="profile">Profile</label>
|
||||
<select x-model.number="profileIndex" name="profile" id="profile">
|
||||
<template x-for="(prof, index) in profileNames" :key="index">
|
||||
<option x-text="prof" :value="index"></option>
|
||||
</template>
|
||||
</select>
|
||||
<button @click="newProfile">New</button>
|
||||
<div class="profile-buttons">
|
||||
<select x-model.number="profileIndex" name="profile" id="profile">
|
||||
<template x-for="(prof, index) in profileNames" :key="index">
|
||||
<option x-text="prof" :value="index"></option>
|
||||
</template>
|
||||
</select>
|
||||
<button @click="newProfile">New</button>
|
||||
<button @click="confirmDelete = true" x-show="!confirmDelete" :disabled="profileNames.length <= 1">Delete</button>
|
||||
<button @click="await deleteProfile()" x-show="confirmDelete">Confirm Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="profile-name">
|
||||
|
||||
@@ -10,6 +10,7 @@ Alpine.data('popup', () => ({
|
||||
profileIndex: 0,
|
||||
visibleKey: false,
|
||||
confirmClear: false,
|
||||
confirmDelete: false,
|
||||
|
||||
async init() {
|
||||
console.log("Initializing backend.");
|
||||
@@ -88,6 +89,12 @@ Alpine.data('popup', () => ({
|
||||
this.confirmClear = false;
|
||||
},
|
||||
|
||||
async deleteProfile() {
|
||||
await browser.runtime.sendMessage({kind: 'deleteProfile'});
|
||||
await this.init();
|
||||
this.confirmDelete = false;
|
||||
},
|
||||
|
||||
// Properties
|
||||
|
||||
get hasValidPubKey() {
|
||||
|
||||
Reference in New Issue
Block a user