diff --git a/Shared (Extension)/Resources/background.js b/Shared (Extension)/Resources/background.js index c450103..5af13d6 100644 --- a/Shared (Extension)/Resources/background.js +++ b/Shared (Extension)/Resources/background.js @@ -40,6 +40,12 @@ browser.runtime.onMessage.addListener(async (message, _sender, sendResponse) => let newIndex = await newProfile(); sendResponse(newIndex); break; + case 'saveProfile': + await saveProfile(message.payload); + break; + case 'clearData': + await browser.storage.local.clear(); + break; default: break; } @@ -109,4 +115,11 @@ async function newProfile() { profiles.push(newProfile); await storage.set({profiles}); return profiles.length - 1; +} + +async function saveProfile(profile) { + let index = await getProfileIndex(); + let profiles = await get('profiles'); + profiles[index] = profile; + await storage.set({profiles}); } \ No newline at end of file diff --git a/Shared (Extension)/Resources/popup.html b/Shared (Extension)/Resources/popup.html index be978df..43750a0 100644 --- a/Shared (Extension)/Resources/popup.html +++ b/Shared (Extension)/Resources/popup.html @@ -28,8 +28,9 @@
- - + + +
diff --git a/Shared (Extension)/Resources/popup.js b/Shared (Extension)/Resources/popup.js index 5f4bc97..6edfef3 100644 --- a/Shared (Extension)/Resources/popup.js +++ b/Shared (Extension)/Resources/popup.js @@ -9,6 +9,7 @@ Alpine.data('popup', () => ({ profileNames: ['Default'], profileIndex: 0, visibleKey: false, + confirmClear: false, async init() { console.log("Initializing backend."); @@ -74,6 +75,19 @@ Alpine.data('popup', () => ({ this.profileIndex = newIndex; }, + async saveProfile() { + let {name, privKey, hosts} = this; + let profile = {name, privKey, hosts}; + await browser.runtime.sendMessage({kind: 'saveProfile', payload: profile}); + await this.refreshProfile(); + }, + + async clearData() { + await browser.runtime.sendMessage({kind: 'clearData'}); + await this.init(); // Re-initialize after clearing + this.confirmClear = false; + }, + // Properties get hasValidPubKey() {