Browse Source

Adds a Try Pro section to the welcome view

main
Keith Daulton 1 year ago
parent
commit
a70fd47c6c
5 changed files with 57 additions and 8 deletions
  1. +11
    -0
      src/webviews/apps/welcome/welcome.html
  2. +10
    -0
      src/webviews/apps/welcome/welcome.scss
  3. +6
    -0
      src/webviews/apps/welcome/welcome.ts
  4. +1
    -0
      src/webviews/welcome/protocol.ts
  5. +29
    -8
      src/webviews/welcome/welcomeWebview.ts

+ 11
- 0
src/webviews/apps/welcome/welcome.html View File

@ -383,6 +383,17 @@
>
</nav>
<div id="try-pro">
<h2>Try Pro</h2>
<p class="h-space-half">Unlock the full power of GitLens ✨ and ☁️ features</p>
<p>
<gk-button appearance="secondary" href="command:gitlens.plus.loginOrSignUp"
>Start a Pro trial</gk-button
>
or <a href="command:gitlens.plus.loginOrSignUp">sign in</a>
</p>
</div>
<h2>Quick Access</h2>
<p data-requires="norepo">
<code-icon icon="question"></code-icon> Features which need a repository are currently unavailable

+ 10
- 0
src/webviews/apps/welcome/welcome.scss View File

@ -167,6 +167,16 @@ li {
color: var(--color-foreground--50);
margin: 0;
}
&-nowrap {
white-space: nowrap;
}
}
.h {
&-space-half {
margin-bottom: 0.65rem;
}
}
gk-card p {

+ 6
- 0
src/webviews/apps/welcome/welcome.ts View File

@ -96,6 +96,7 @@ export class WelcomeApp extends App {
this.updateVersion();
this.updateFeatures();
this.updateRepoState();
this.updateAccountState();
}
private updateVersion() {
@ -120,6 +121,11 @@ export class WelcomeApp extends App {
const { repoFeaturesBlocked } = this.state;
document.body.dataset.repos = repoFeaturesBlocked ? 'blocked' : 'allowed';
}
private updateAccountState() {
const { isTrialOrPaid } = this.state;
document.getElementById('try-pro')!.hidden = isTrialOrPaid ?? false;
}
}
new WelcomeApp();

+ 1
- 0
src/webviews/welcome/protocol.ts View File

@ -9,6 +9,7 @@ export interface State {
currentLine: Config['currentLine']['enabled'];
};
repoFeaturesBlocked?: boolean;
isTrialOrPaid?: boolean;
}
export interface UpdateConfigurationParams {

+ 29
- 8
src/webviews/welcome/welcomeWebview.ts View File

@ -1,6 +1,9 @@
import type { ConfigurationChangeEvent } from 'vscode';
import { Disposable, workspace } from 'vscode';
import type { Container } from '../../container';
import type { SubscriptionChangeEvent } from '../../plus/subscription/subscriptionService';
import type { Subscription } from '../../subscription';
import { SubscriptionState } from '../../subscription';
import { configuration } from '../../system/configuration';
import type { IpcMessage } from '../protocol';
import { onIpc } from '../protocol';
@ -23,8 +26,11 @@ export class WelcomeWebviewProvider implements WebviewProvider {
) {
this._disposable = Disposable.from(
configuration.onDidChange(this.onConfigurationChanged, this),
this.container.git.onDidChangeRepositories(this.notifyDidChange, this),
!workspace.isTrusted ? workspace.onDidGrantWorkspaceTrust(this.notifyDidChange, this) : emptyDisposable,
this.container.git.onDidChangeRepositories(() => this.notifyDidChange(), this),
!workspace.isTrusted
? workspace.onDidGrantWorkspaceTrust(() => this.notifyDidChange(), this)
: emptyDisposable,
this.container.subscription.onDidChange(this.onSubscriptionChanged, this),
);
}
@ -32,18 +38,22 @@ export class WelcomeWebviewProvider implements WebviewProvider {
this._disposable.dispose();
}
includeBootstrap(): State {
includeBootstrap(): Promise<State> {
return this.getState();
}
onReloaded() {
this.notifyDidChange();
void this.notifyDidChange();
}
private onSubscriptionChanged(e: SubscriptionChangeEvent) {
void this.notifyDidChange(e.current);
}
private onConfigurationChanged(e: ConfigurationChangeEvent) {
if (!configuration.changed(e, 'codeLens.enabled') && !configuration.changed(e, 'currentLine.enabled')) return;
this.notifyDidChange();
void this.notifyDidChange();
}
onMessageReceived(e: IpcMessage) {
@ -53,7 +63,7 @@ export class WelcomeWebviewProvider implements WebviewProvider {
break;
}
}
private getState(): State {
private async getState(subscription?: Subscription): Promise<State> {
return {
timestamp: Date.now(),
version: this.container.version,
@ -66,14 +76,25 @@ export class WelcomeWebviewProvider implements WebviewProvider {
!workspace.isTrusted ||
this.container.git.openRepositoryCount === 0 ||
this.container.git.hasUnsafeRepositories(),
isTrialOrPaid: await this.getTrialOrPaidState(subscription),
};
}
private async getTrialOrPaidState(subscription?: Subscription): Promise<boolean> {
const sub = subscription ?? (await this.container.subscription.getSubscription(true));
if ([SubscriptionState.FreePlusInTrial, SubscriptionState.Paid].includes(sub.state)) {
return true;
}
return false;
}
private updateConfiguration(params: UpdateConfigurationParams) {
void configuration.updateEffective(`${params.type}.enabled`, params.value);
}
private notifyDidChange() {
void this.host.notify(DidChangeNotificationType, { state: this.getState() });
private async notifyDidChange(subscription?: Subscription) {
void this.host.notify(DidChangeNotificationType, { state: await this.getState(subscription) });
}
}

Loading…
Cancel
Save