Skip to content

Commit

Permalink
execute sending message to background before window.open()
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaleleka committed Jan 25, 2024
1 parent 8a5e5c1 commit ce06236
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/options/components/Sidebar/Rate/Rate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ export const Rate = observer(() => {
await hideRate();
};

const handleChange = (e: React.ChangeEvent<HTMLInputElement>): void => {
const handleChange = async (e: React.ChangeEvent<HTMLInputElement>): Promise<void> => {
const { value } = e.target;

await handleHideRate();

if (value && parseInt(value, 10) >= 4) {
window.open(OPTIONS_STORE_URL, '_blank');
} else {
window.open(FEEDBACK_URL, '_blank');
}

handleHideRate();
};

if (!isRateVisible) {
Expand Down
9 changes: 5 additions & 4 deletions src/popup/components/RatePopup/RatePopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ export const RatePopup = observer(() => {
const handleChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
const { value } = e.target;

// wait until the message is sent to the background and execute it before opening the new tab
// because window.open() may close the popup and abort the message sending in some browsers
// https://github.com/AdguardTeam/AdGuardVPNExtension/issues/150
await handleHideRate();

if (value && parseInt(value, 10) >= 4) {
window.open(POPUP_STORE_URL, '_blank');
} else {
window.open(FEEDBACK_URL, '_blank');
}

// wait until the message is sent to the background
// https://github.com/AdguardTeam/AdGuardVPNExtension/issues/150
await handleHideRate();

// close popup after click on rate star
window.close();
};
Expand Down

0 comments on commit ce06236

Please sign in to comment.