Skip to content

Commit

Permalink
feat: reload options page when client app is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
dessant committed Jun 3, 2024
1 parent cb4811e commit 290dfba
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/background/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,8 @@ async function processMessage(request, sender) {
return getBrowser();
} else if (request.id === 'optionChange') {
await onOptionChange();
} else if (request.id === 'clientAppInstall') {
await onClientAppInstall();
}
}

Expand All @@ -908,6 +910,14 @@ function onMessage(request, sender, sendResponse) {
return processMessageResponse(response, sendResponse);
}

async function onClientAppInstall() {
await storage.set({simulateUserInput: true});

await browser.runtime
.sendMessage({id: 'reloadOptionsPage'})
.catch(() => null);
}

async function onOptionChange() {
await setChallengeLocale();
}
Expand Down
8 changes: 8 additions & 0 deletions src/options/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ export default {
getText,
setup: async function () {
browser.runtime.onMessage.addListener(this.onMessage);
const options = await storage.get(optionKeys);
for (const option of Object.keys(this.options)) {
Expand Down Expand Up @@ -388,6 +390,12 @@ export default {
this.dataLoaded = true;
},
onMessage: function (request, sender) {
if (request.id === 'reloadOptionsPage') {
self.location.reload();
}
},
verifyClientApp: async function () {
try {
await pingClientApp();
Expand Down
4 changes: 2 additions & 2 deletions src/setup/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
<script>
import {App, Button, TextField} from 'vueton';
import storage from 'storage/storage';
import {pingClientApp} from 'utils/app';
import {getText} from 'utils/common';
Expand Down Expand Up @@ -139,6 +138,8 @@ export default {
method: 'POST',
body: data
});
await browser.runtime.sendMessage({id: 'clientAppInstall'});
}
},
Expand Down Expand Up @@ -179,7 +180,6 @@ export default {
if (rsp.status === 200) {
await pingClientApp();
await storage.set({simulateUserInput: true});
this.isInstallSuccess = true;
} else {
Expand Down

0 comments on commit 290dfba

Please sign in to comment.