Skip to content

Commit

Permalink
Don't reset activation due to slow loading Firefox sync
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayyy committed Aug 31, 2023
1 parent 2a5f13b commit 906c229
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ setupTabUpdates(Config);
setupBackgroundRequestProxy();

waitFor(() => Config.isReady()).then(() => {
if (!Config.config!.activated && (Config.config!.alreadyActivated || Config.config!.licenseKey)) {
Config.config!.activated = true;
}
if (Config.config!.activated && Config.config!.userID) {
Config.config!.alreadyActivated = true;
}

registerNeededContentScripts().then(() => {
if (!isFirefoxOrSafari()) {
// Chrome doesn't trigger onInstall when this happens, but they need to be
Expand All @@ -29,7 +36,6 @@ waitFor(() => Config.isReady()).then(() => {
}
}).catch(logError);


setupAlarms();

// Check every time since sometimes initial onInstall isn't called
Expand All @@ -44,7 +50,8 @@ waitFor(() => Config.isReady()).then(() => {
&& !navigator.userAgent.includes("Mobile;")
&& await isPaywallEnabled()
&& !groupPolicyLicenseKey
&& !Config.config!.licenseKey;
&& !Config.config!.licenseKey
&& !Config.config!.alreadyActivated;
if (paywallEnabled) {
Config.config!.activated = false;
Config.config!.showActivatedMessage = true;
Expand Down
2 changes: 2 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ interface SBConfig {
thumbnailReplacements: number;
licenseKey: string | null;
activated: boolean;
alreadyActivated: boolean;
freeActivation: boolean;
freeTrialStart: number | null;
freeTrialEnded: boolean;
Expand Down Expand Up @@ -169,6 +170,7 @@ const syncDefaults = {
thumbnailReplacements: 0,
licenseKey: null,
activated: true,
alreadyActivated: false,
freeActivation: true,
freeTrialStart: null,
freeTrialEnded: false,
Expand Down
9 changes: 9 additions & 0 deletions src/help/PaymentComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ waitFor(() => Config.isReady()).then(() => {
}
});

Config.configSyncListeners.push((changes) => {
if ((changes.activated && changes.activated.newValue)
|| (changes.alreadyActivated && changes.alreadyActivated.newValue)) {
Config.config!.activated = true;

chrome.runtime.sendMessage({ "message": "openHelp" }, () => window.close());
}
});

export const PaymentComponent = () => {
const [paymentResult, setPaymentResult] = React.useState<PaymentResultMessageType | null>(isFreeAccessRequestActive()
? PaymentResultMessageType.FreeAccess : (freeTrialActive() ? PaymentResultMessageType.FreeTrial : null));
Expand Down

0 comments on commit 906c229

Please sign in to comment.