starting the plumbing for the extension
This commit is contained in:
@@ -2,42 +2,62 @@ import Alpine from "alpinejs";
|
||||
window.Alpine = Alpine;
|
||||
|
||||
Alpine.data('popup', () => ({
|
||||
privKey: '',
|
||||
profiles: [],
|
||||
profile: '',
|
||||
pubKey: '',
|
||||
profiles: [{name: 'Default', privKey: '', hosts: []}],
|
||||
activeProfile: 0,
|
||||
visibleKey: false,
|
||||
allowedSites: [],
|
||||
|
||||
async init() {
|
||||
await this.getProfiles();
|
||||
await this.getPrivKeyForProfile();
|
||||
await this.getAllowedSites();
|
||||
},
|
||||
|
||||
saveKey() {
|
||||
console.log(`Saving key ${this.privKey}`);
|
||||
async saveKey() {
|
||||
await this.getPubKey();
|
||||
},
|
||||
|
||||
async getProfiles() {
|
||||
this.profiles = ['Default', 'Extra'];
|
||||
this.profile = 'Default';
|
||||
this.profiles = await browser.runtime.sendMessage({kind: 'getProfiles'});
|
||||
this.activeProfile = await browser.runtime.sendMessage({kind: 'getActiveProfile'});
|
||||
},
|
||||
|
||||
async getPrivKeyForProfile() {
|
||||
this.privKey = this.profile;
|
||||
},
|
||||
|
||||
async getAllowedSites() {
|
||||
this.allowedSites = [
|
||||
{site: 'yosupp.app', allowed: true},
|
||||
{site: 'iris.to', allowed: false},
|
||||
];
|
||||
await this.getPubKey();
|
||||
},
|
||||
|
||||
async deleteSite(index) {
|
||||
let newSites = [...this.allowedSites];
|
||||
confirm("hello");
|
||||
let newSites = [...this.hosts];
|
||||
newSites.splice(index, 1);
|
||||
this.allowedSites = newSites;
|
||||
this.hosts = newSites;
|
||||
},
|
||||
|
||||
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;
|
||||
},
|
||||
|
||||
get hasValidPubKey() {
|
||||
return typeof(this.pubKey) === 'string' && this.pubKey.length > 0;
|
||||
},
|
||||
|
||||
get profile() {
|
||||
return this.profiles[this.activeProfile];
|
||||
},
|
||||
|
||||
get hosts() {
|
||||
return this.profile.hosts;
|
||||
},
|
||||
|
||||
set hosts(value) {
|
||||
this.profiles[this.activeProfile].hosts = value;
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user