Browse Source

Adds commands to show/hide premium features

main
Eric Amodio 3 years ago
parent
commit
faca5f0221
9 changed files with 90 additions and 8 deletions
  1. +18
    -0
      package.json
  2. +2
    -0
      src/constants.ts
  3. +19
    -2
      src/premium/subscription/subscriptionService.ts
  4. +20
    -0
      src/premium/subscription/utils.ts
  5. +9
    -3
      src/premium/webviews/timeline/timelineWebview.ts
  6. +8
    -2
      src/premium/webviews/timeline/timelineWebviewView.ts
  7. +1
    -0
      src/subscription.ts
  8. +7
    -1
      src/views/worktreesView.ts
  9. +6
    -0
      src/webviews/home/homeWebviewView.ts

+ 18
- 0
package.json View File

@ -3634,6 +3634,16 @@
"category": "GitLens Premium"
},
{
"command": "gitlens.premium.hide",
"title": "Hide Premium Features...",
"category": "GitLens Premium"
},
{
"command": "gitlens.premium.restore",
"title": "Restore Premium Features...",
"category": "GitLens Premium"
},
{
"command": "gitlens.premium.reset",
"title": "Reset...",
"category": "GitLens Premium"
@ -5954,6 +5964,14 @@
"when": "gitlens:premium"
},
{
"command": "gitlens.premium.hide",
"when": "config.gitlens.premiumFeatures.enabled"
},
{
"command": "gitlens.premium.restore",
"when": "!config.gitlens.premiumFeatures.enabled"
},
{
"command": "gitlens.premium.reset",
"when": "gitlens:debugging"
},

+ 2
- 0
src/constants.ts View File

@ -137,12 +137,14 @@ export const enum Commands {
GitCommandsSwitch = 'gitlens.gitCommands.switch',
GitCommandsTag = 'gitlens.gitCommands.tag',
GitCommandsWorktree = 'gitlens.gitCommands.worktree',
PremiumHide = 'gitlens.premium.hide',
PremiumLearn = 'gitlens.premium.learn',
PremiumLoginOrSignUp = 'gitlens.premium.loginOrSignUp',
PremiumLogout = 'gitlens.premium.logout',
PremiumManage = 'gitlens.premium.manage',
PremiumPurchase = 'gitlens.premium.purchase',
PremiumResendVerification = 'gitlens.premium.resendVerification',
PremiumRestore = 'gitlens.premium.restore',
PremiumShowPlans = 'gitlens.premium.showPlans',
PremiumStartPreviewTrial = 'gitlens.premium.startPreviewTrial',
PremiumValidate = 'gitlens.premium.validate',

+ 19
- 2
src/premium/subscription/subscriptionService.ts View File

@ -18,6 +18,7 @@ import {
} from 'vscode';
import { fetch } from '@env/fetch';
import { getPlatform } from '@env/platform';
import { configuration } from '../../configuration';
import { Commands, ContextKeys } from '../../constants';
import type { Container } from '../../container';
import { setContext } from '../../context';
@ -46,6 +47,7 @@ import { memoize } from '../../system/decorators/memoize';
import { once } from '../../system/function';
import { pluralize } from '../../system/string';
import { openWalkthrough } from '../../system/utils';
import { ensurePremiumFeaturesEnabled } from './utils';
// TODO: What user-agent should we use?
const userAgent = 'Visual-Studio-Code-GitLens';
@ -172,6 +174,13 @@ export class SubscriptionService implements Disposable {
commands.registerCommand(Commands.PremiumShowPlans, () => this.showPlans()),
commands.registerCommand(Commands.PremiumHide, () =>
configuration.updateEffective('premiumFeatures.enabled', false),
),
commands.registerCommand(Commands.PremiumRestore, () =>
configuration.updateEffective('premiumFeatures.enabled', true),
),
commands.registerCommand('gitlens.premium.reset', () => this.logout(true)),
];
}
@ -189,6 +198,8 @@ export class SubscriptionService implements Disposable {
@gate()
@log()
async loginOrSignUp(): Promise<boolean> {
if (!(await ensurePremiumFeaturesEnabled())) return false;
void this.showHomeView();
await this.container.storage.deleteWorkspace(this.connectedKey);
@ -270,6 +281,8 @@ export class SubscriptionService implements Disposable {
@log()
async purchase(): Promise<void> {
if (!(await ensurePremiumFeaturesEnabled())) return;
if (this._subscription.account == null) {
void this.showPlans();
} else {
@ -287,7 +300,7 @@ export class SubscriptionService implements Disposable {
const cc = Logger.getCorrelationContext();
void this.showHomeView();
void this.showHomeView(true);
const session = await this.ensureSession(false);
if (session == null) return;
@ -331,7 +344,9 @@ export class SubscriptionService implements Disposable {
}
@log()
async showHomeView(): Promise<void> {
async showHomeView(silent: boolean = false): Promise<void> {
if (silent && !configuration.get('premiumFeatures.enabled', undefined, true)) return;
if (!this.container.homeView.visible) {
await executeCommand(Commands.ShowHomeView);
}
@ -344,6 +359,8 @@ export class SubscriptionService implements Disposable {
@gate()
@log()
async startPreviewTrial(): Promise<void> {
if (!(await ensurePremiumFeaturesEnabled())) return;
let { plan, previewTrial } = this._subscription;
if (previewTrial != null || plan.effective.id !== SubscriptionPlanId.Free) {
void this.showHomeView();

+ 20
- 0
src/premium/subscription/utils.ts View File

@ -0,0 +1,20 @@
import { MessageItem, window } from 'vscode';
import { configuration } from '../../configuration';
export async function ensurePremiumFeaturesEnabled(): Promise<boolean> {
if (configuration.get('premiumFeatures.enabled', undefined, true)) return true;
const confirm: MessageItem = { title: 'Enable' };
const cancel: MessageItem = { title: 'Cancel', isCloseAffordance: true };
const result = await window.showInformationMessage(
'Premium features are currently disabled. Would you like to enable them?',
{ modal: true },
confirm,
cancel,
);
if (result !== confirm) return false;
void (await configuration.updateEffective('premiumFeatures.enabled', true));
return true;
}

+ 9
- 3
src/premium/webviews/timeline/timelineWebview.ts View File

@ -1,6 +1,6 @@
'use strict';
import { commands, Disposable, TextEditor, Uri, window } from 'vscode';
import { ShowQuickCommitCommandArgs } from '../../../commands';
import { commands, Disposable, TextEditor, Uri, ViewColumn, window } from 'vscode';
import type { ShowQuickCommitCommandArgs } from '../../../commands';
import { configuration } from '../../../configuration';
import { Commands, ContextKeys } from '../../../constants';
import type { Container } from '../../../container';
@ -15,7 +15,8 @@ import { filter } from '../../../system/iterable';
import { hasVisibleTextEditor, isTextEditor } from '../../../system/utils';
import { IpcMessage, onIpc } from '../../../webviews/protocol';
import { WebviewBase } from '../../../webviews/webviewBase';
import { SubscriptionChangeEvent } from '../../subscription/subscriptionService';
import type { SubscriptionChangeEvent } from '../../subscription/subscriptionService';
import { ensurePremiumFeaturesEnabled } from '../../subscription/utils';
import {
Commit,
DidChangeStateNotificationType,
@ -61,6 +62,11 @@ export class TimelineWebview extends WebviewBase {
};
}
override async show(column: ViewColumn = ViewColumn.Beside): Promise<void> {
if (!(await ensurePremiumFeaturesEnabled())) return;
return super.show(column);
}
protected override onInitializing(): Disposable[] | undefined {
this._context = {
uri: undefined,

+ 8
- 2
src/premium/webviews/timeline/timelineWebviewView.ts View File

@ -1,11 +1,11 @@
'use strict';
import { commands, Disposable, TextEditor, Uri, window } from 'vscode';
import { ShowQuickCommitCommandArgs } from '../../../commands';
import type { ShowQuickCommitCommandArgs } from '../../../commands';
import { configuration } from '../../../configuration';
import { Commands } from '../../../constants';
import { Container } from '../../../container';
import { PremiumFeatures } from '../../../features';
import { RepositoriesChangeEvent } from '../../../git/gitProviderService';
import type { RepositoriesChangeEvent } from '../../../git/gitProviderService';
import { GitUri } from '../../../git/gitUri';
import { RepositoryChange, RepositoryChangeComparisonMode, RepositoryChangeEvent } from '../../../git/models';
import { createFromDateDelta } from '../../../system/date';
@ -16,6 +16,7 @@ import { hasVisibleTextEditor, isTextEditor } from '../../../system/utils';
import { IpcMessage, onIpc } from '../../../webviews/protocol';
import { WebviewViewBase } from '../../../webviews/webviewViewBase';
import type { SubscriptionChangeEvent } from '../../subscription/subscriptionService';
import { ensurePremiumFeaturesEnabled } from '../../subscription/utils';
import {
Commit,
DidChangeStateNotificationType,
@ -54,6 +55,11 @@ export class TimelineWebviewView extends WebviewViewBase {
};
}
override async show(options?: { preserveFocus?: boolean | undefined }): Promise<void> {
if (!(await ensurePremiumFeaturesEnabled())) return;
return super.show(options);
}
protected override onInitializing(): Disposable[] | undefined {
this._context = {
uri: undefined,

+ 1
- 0
src/subscription.ts View File

@ -1,3 +1,4 @@
// NOTE@eamodio This file is referenced in the webviews to we can't use anything vscode or other imports that aren't available in the webviews
import { getDateDifference } from './system/date';
export const enum SubscriptionPlanId {

+ 7
- 1
src/views/worktreesView.ts View File

@ -15,6 +15,7 @@ import { Container } from '../container';
import { PremiumFeatures } from '../features';
import { GitUri } from '../git/gitUri';
import { GitWorktree, RepositoryChange, RepositoryChangeComparisonMode, RepositoryChangeEvent } from '../git/models';
import { ensurePremiumFeaturesEnabled } from '../premium/subscription/utils';
import { getSubscriptionTimeRemaining, SubscriptionState } from '../subscription';
import { gate } from '../system/decorators/gate';
import { pluralize } from '../system/string';
@ -115,7 +116,7 @@ export class WorktreesView extends ViewBase
return {
badge: '●',
color: new ThemeColor('gitlens.decorations.worktreeView.hasUncommittedChangesForegroundColor'),
color: new ThemeColor('gitlens.decorations.worktreeView.hasUncommittedChangesForegroundColoSr'),
tooltip: 'Has Uncommitted Changes',
};
},
@ -127,6 +128,11 @@ export class WorktreesView extends ViewBase
return this.config.reveal || !configuration.get('views.repositories.showWorktrees');
}
override async show(options?: { preserveFocus?: boolean | undefined }): Promise<void> {
if (!(await ensurePremiumFeaturesEnabled())) return;
return super.show(options);
}
private _visibleDisposable: Disposable | undefined;
protected override onVisibilityChanged(e: TreeViewVisibilityChangeEvent): void {
if (e.visible) {

+ 6
- 0
src/webviews/home/homeWebviewView.ts View File

@ -1,6 +1,7 @@
import { commands, Disposable, window } from 'vscode';
import type { Container } from '../../container';
import type { SubscriptionChangeEvent } from '../../premium/subscription/subscriptionService';
import { ensurePremiumFeaturesEnabled } from '../../premium/subscription/utils';
import { SyncedStorageKeys } from '../../storage';
import type { Subscription } from '../../subscription';
import { WebviewViewBase } from '../webviewViewBase';
@ -13,6 +14,11 @@ export class HomeWebviewView extends WebviewViewBase {
this.disposables.push(this.container.subscription.onDidChange(this.onSubscriptionChanged, this));
}
override async show(options?: { preserveFocus?: boolean | undefined }): Promise<void> {
if (!(await ensurePremiumFeaturesEnabled())) return;
return super.show(options);
}
private onSubscriptionChanged(e: SubscriptionChangeEvent) {
void this.notifyDidChangeData(e.current);
}

Loading…
Cancel
Save