From ae5983b117375cf346f467539fd86499443dba2d Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 29 Aug 2022 01:19:11 -0400 Subject: [PATCH] Adds auto-start of preview trial on Graph --- src/plus/subscription/subscriptionService.ts | 27 +++++++++++++++------------ src/plus/webviews/graph/graphWebview.ts | 13 ++++++++----- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/plus/subscription/subscriptionService.ts b/src/plus/subscription/subscriptionService.ts index 2c31712..8e05f54 100644 --- a/src/plus/subscription/subscriptionService.ts +++ b/src/plus/subscription/subscriptionService.ts @@ -394,14 +394,14 @@ export class SubscriptionService implements Disposable { @gate() @log() - async startPreviewTrial(): Promise { + async startPreviewTrial(silent?: boolean): Promise { if (!(await ensurePlusFeaturesEnabled())) return; let { plan, previewTrial } = this._subscription; if (previewTrial != null || plan.effective.id !== SubscriptionPlanId.Free) { void this.showHomeView(); - if (plan.effective.id === SubscriptionPlanId.Free) { + if (!silent && plan.effective.id === SubscriptionPlanId.Free) { const confirm: MessageItem = { title: 'Sign in to GitLens+', isCloseAffordance: true }; const cancel: MessageItem = { title: 'Cancel' }; const result = await window.showInformationMessage( @@ -415,6 +415,7 @@ export class SubscriptionService implements Disposable { void this.loginOrSignUp(); } } + return; } @@ -446,17 +447,19 @@ export class SubscriptionService implements Disposable { previewTrial: previewTrial, }); - const confirm: MessageItem = { title: 'OK', isCloseAffordance: true }; - const learn: MessageItem = { title: 'Learn More' }; - const result = await window.showInformationMessage( - `You have started a ${days} day trial of GitLens+ features for both public and private repos.`, - { modal: true }, - confirm, - learn, - ); + if (!silent) { + const confirm: MessageItem = { title: 'OK', isCloseAffordance: true }; + const learn: MessageItem = { title: 'Learn More' }; + const result = await window.showInformationMessage( + `You have started a ${days} day trial of GitLens+ features for both public and private repos.`, + { modal: true }, + confirm, + learn, + ); - if (result === learn) { - this.learn(); + if (result === learn) { + this.learn(); + } } } diff --git a/src/plus/webviews/graph/graphWebview.ts b/src/plus/webviews/graph/graphWebview.ts index 9e98b21..23aa48d 100644 --- a/src/plus/webviews/graph/graphWebview.ts +++ b/src/plus/webviews/graph/graphWebview.ts @@ -450,11 +450,14 @@ export class GraphWebview extends WebviewBase { // If we have a set of data refresh to the same set const limit = this._graph?.paging?.limit ?? config.defaultItemLimit; - // only check on private - const access = await this.container.git.access(PlusFeatures.Graph, this.repository?.path); - // TODO: probably not the right place to set this - if (this._etagSubscription == null) { - this._etagSubscription = this.container.subscription.etag; + // Check for GitLens+ access + let access = await this.container.git.access(PlusFeatures.Graph, this.repository?.path); + this._etagSubscription = this.container.subscription.etag; + + // If we don't have access to GitLens+, but the preview trial hasn't been started, auto-start it + if (!access.allowed && access.subscription.current.previewTrial == null) { + await this.container.subscription.startPreviewTrial(true); + access = await this.container.git.access(PlusFeatures.Graph, this.repository?.path); } const data = await this.container.git.getCommitsForGraph(