Sfoglia il codice sorgente

Resets preview trial state on 12.2 upgrade

main
Eric Amodio 2 anni fa
parent
commit
60cd4edee0
3 ha cambiato i file con 33 aggiunte e 17 eliminazioni
  1. +19
    -6
      src/container.ts
  2. +2
    -2
      src/extension.ts
  3. +12
    -9
      src/plus/subscription/subscriptionService.ts

+ 19
- 6
src/container.ts Vedi File

@ -70,10 +70,16 @@ export class Container {
},
});
static create(context: ExtensionContext, storage: Storage, insiders: boolean) {
static create(
context: ExtensionContext,
storage: Storage,
insiders: boolean,
version: string,
previousVersion: string | undefined,
) {
if (Container.#instance != null) throw new Error('Container is already initialized');
Container.#instance = new Container(context, storage, insiders);
Container.#instance = new Container(context, storage, insiders, version, previousVersion);
return Container.#instance;
}
@ -140,9 +146,16 @@ export class Container {
private _configAffectedByModeRegex: RegExp | undefined;
private _terminalLinks: GitTerminalLinkProvider | undefined;
private constructor(context: ExtensionContext, storage: Storage, insiders: boolean) {
private constructor(
context: ExtensionContext,
storage: Storage,
insiders: boolean,
version: string,
previousVersion: string | undefined,
) {
this._context = context;
this._insiders = insiders;
this._version = version;
this.ensureModeApplied();
context.subscriptions.push((this._storage = storage));
@ -155,7 +168,7 @@ export class Container {
context.subscriptions.push(
(this._subscriptionAuthentication = new SubscriptionAuthenticationProvider(this, server)),
);
context.subscriptions.push((this._subscription = new SubscriptionService(this)));
context.subscriptions.push((this._subscription = new SubscriptionService(this, previousVersion)));
context.subscriptions.push((this._git = new GitProviderService(this)));
context.subscriptions.push(new GitFileSystemProvider(this));
@ -553,9 +566,9 @@ export class Container {
return this._usage;
}
@memoize()
private readonly _version: string;
get version(): string {
return this.context.extension.packageJSON.version as string;
return this._version;
}
private _viewCommands: ViewCommands | undefined;

+ 2
- 2
src/extension.ts Vedi File

@ -28,7 +28,7 @@ import { compare, fromString, satisfies } from './system/version';
import { isViewNode } from './views/nodes/viewNode';
export async function activate(context: ExtensionContext): Promise<GitLensApi | undefined> {
const gitlensVersion = context.extension.packageJSON.version;
const gitlensVersion: string = context.extension.packageJSON.version;
const insiders = context.extension.id === 'eamodio.gitlens-insiders' || satisfies(gitlensVersion, '> 2020.0.0');
const outputLevel = configuration.get('outputLevel');
@ -131,7 +131,7 @@ export async function activate(context: ExtensionContext): Promise
// await migrateSettings(context, previousVersion);
const container = Container.create(context, storage, insiders);
const container = Container.create(context, storage, insiders, gitlensVersion, previousVersion);
once(container.onReady)(() => {
context.subscriptions.push(...registerCommands(container));
registerBuiltInActionRunners(container);

+ 12
- 9
src/plus/subscription/subscriptionService.ts Vedi File

@ -49,6 +49,7 @@ import { memoize } from '../../system/decorators/memoize';
import { once } from '../../system/function';
import { pluralize } from '../../system/string';
import { openWalkthrough } from '../../system/utils';
import { satisfies } from '../../system/version';
import { ensurePlusFeaturesEnabled } from './utils';
// TODO: What user-agent should we use?
@ -74,7 +75,7 @@ export class SubscriptionService implements Disposable {
private _statusBarSubscription: StatusBarItem | undefined;
private _validationTimer: ReturnType<typeof setInterval> | undefined;
constructor(private readonly container: Container) {
constructor(private readonly container: Container, previousVersion: string | undefined) {
this._disposable = Disposable.from(
once(container.onReady)(this.onReady, this),
this.container.subscriptionAuthentication.onDidChangeSessions(
@ -83,7 +84,13 @@ export class SubscriptionService implements Disposable {
),
);
this.changeSubscription(this.getStoredSubscription(), true);
const subscription = this.getStoredSubscription();
// Resets the preview trial state on the upgrade to 12.2
if (subscription != null && satisfies(previousVersion, '< 12.2')) {
subscription.previewTrial = undefined;
}
this.changeSubscription(subscription, true);
setTimeout(() => void this.ensureSession(false), 10000);
}
@ -398,7 +405,7 @@ export class SubscriptionService implements Disposable {
if (!(await ensurePlusFeaturesEnabled())) return;
let { plan, previewTrial } = this._subscription;
if (previewTrial != null || plan.effective.id !== SubscriptionPlanId.Free) {
if (previewTrial != null) {
void this.showHomeView();
if (!silent && plan.effective.id === SubscriptionPlanId.Free) {
@ -767,12 +774,8 @@ export class SubscriptionService implements Disposable {
};
}
// If the effective plan is Free, then check if the preview has expired, if not apply it
if (
subscription.plan.effective.id === SubscriptionPlanId.Free &&
subscription.previewTrial != null &&
(getTimeRemaining(subscription.previewTrial.expiresOn) ?? 0) > 0
) {
// Check if the preview has expired, if not apply it
if (subscription.previewTrial != null && (getTimeRemaining(subscription.previewTrial.expiresOn) ?? 0) > 0) {
(subscription.plan as PickMutable<Subscription['plan'], 'effective'>).effective = getSubscriptionPlan(
SubscriptionPlanId.Pro,
new Date(subscription.previewTrial.startedOn),

Caricamento…
Annulla
Salva