Skip to content

Commit

Permalink
Updates the home view to be omnipresent
Browse files Browse the repository at this point in the history
  • Loading branch information
d13 committed Oct 21, 2022
1 parent 21f3ea6 commit a312aa4
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 3 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -12198,7 +12198,6 @@
"type": "webview",
"id": "gitlens.views.home",
"name": "Home",
"when": "!gitlens:disabled && gitlens:plus:enabled",
"contextualTitle": "GitLens",
"icon": "$(gitlens-gitlens)",
"visibility": "visible"
Expand Down
12 changes: 12 additions & 0 deletions src/webviews/apps/home/home.html
Expand Up @@ -123,6 +123,18 @@
GitLens is deeply integrated into many areas and aspects of VS Code, especially editors and
views.
</p>
<card-section no-heading id="no-repo" aria-hidden="true">
<div class="centered">
<p>
To use GitLens, open a folder containing a git repository or clone from a URL from the
Explorer.
</p>

<vscode-button class="mb-1" data-action="command:workbench.view.explorer"
>Open a Folder or Repository</vscode-button
>
</div>
</card-section>
<div class="activitybar-banner">
<ul>
<li>
Expand Down
12 changes: 12 additions & 0 deletions src/webviews/apps/home/home.scss
Expand Up @@ -246,6 +246,18 @@ ul {
max-width: 10rem;
height: auto;
}

#no-repo[aria-hidden='false'] ~ & {
display: none;
}
}

#no-repo {
margin-bottom: 0;

&[aria-hidden='true'] {
display: none;
}
}

.video-banner {
Expand Down
19 changes: 19 additions & 0 deletions src/webviews/apps/home/home.ts
Expand Up @@ -6,6 +6,7 @@ import { getSubscriptionTimeRemaining, SubscriptionState } from '../../../subscr
import type { State } from '../../home/protocol';
import {
CompleteStepCommandType,
DidChangeExtensionEnabledType,
DidChangeSubscriptionNotificationType,
DismissSectionCommandType,
} from '../../home/protocol';
Expand Down Expand Up @@ -78,6 +79,14 @@ export class HomeApp extends App<State> {
this.updateState();
});
break;
case DidChangeExtensionEnabledType.method:
this.log(`${this.appName}.onMessageReceived(${msg.id}): name=${msg.method}`);

onIpc(DidChangeExtensionEnabledType, msg, params => {
this.state.extensionEnabled = params.extensionEnabled;
this.updateNoRepo();
});
break;

default:
super.onMessageReceived?.(e);
Expand Down Expand Up @@ -157,6 +166,15 @@ export class HomeApp extends App<State> {
}
}

private updateNoRepo() {
const { extensionEnabled } = this.state;

const $el = document.getElementById('no-repo');
if ($el) {
$el.setAttribute('aria-hidden', extensionEnabled ? 'true' : 'false');
}
}

private updatePlusContent(days = this.getDaysRemaining()) {
const { subscription, visibility } = this.state;

Expand Down Expand Up @@ -211,6 +229,7 @@ export class HomeApp extends App<State> {
private updateState() {
const { completedSteps, dismissedSections, plusEnabled } = this.state;

this.updateNoRepo();
document.getElementById('restore-plus')?.classList.toggle('hide', plusEnabled);

const showRestoreWelcome = completedSteps?.length || dismissedSections?.length;
Expand Down
25 changes: 23 additions & 2 deletions src/webviews/home/homeWebviewView.ts
Expand Up @@ -2,8 +2,9 @@ import type { Disposable } from 'vscode';
import { window } from 'vscode';
import { getAvatarUriFromGravatarEmail } from '../../avatars';
import { configuration } from '../../configuration';
import { CoreCommands } from '../../constants';
import { ContextKeys, CoreCommands } from '../../constants';
import type { Container } from '../../container';
import { getContext, onDidChangeContext } from '../../context';
import type { RepositoriesVisibility } from '../../git/gitProviderService';
import type { SubscriptionChangeEvent } from '../../plus/subscription/subscriptionService';
import { ensurePlusFeaturesEnabled } from '../../plus/subscription/utils';
Expand All @@ -16,6 +17,7 @@ import type { CompleteStepParams, DismissSectionParams, State } from './protocol
import {
CompletedActions,
CompleteStepCommandType,
DidChangeExtensionEnabledType,
DidChangeSubscriptionNotificationType,
DismissSectionCommandType,
} from './protocol';
Expand All @@ -24,7 +26,13 @@ export class HomeWebviewView extends WebviewViewBase<State> {
constructor(container: Container) {
super(container, 'gitlens.views.home', 'home.html', 'Home', 'homeView');

this.disposables.push(this.container.subscription.onDidChange(this.onSubscriptionChanged, this));
this.disposables.push(
this.container.subscription.onDidChange(this.onSubscriptionChanged, this),
onDidChangeContext(key => {
if (key !== ContextKeys.Disabled) return;
this.notifyExtensionEnabled();
}),
);
}

override async show(options?: { preserveFocus?: boolean | undefined }): Promise<void> {
Expand Down Expand Up @@ -158,6 +166,7 @@ export class HomeWebviewView extends WebviewViewBase<State> {
const sections = this.container.storage.get('home:sections:dismissed', []);

return {
extensionEnabled: this.getExtensionEnabled(),
webroot: this.getWebRoot(),
subscription: subscriptionState.subscription,
completedActions: subscriptionState.completedActions,
Expand All @@ -177,6 +186,18 @@ export class HomeWebviewView extends WebviewViewBase<State> {
);
}

private getExtensionEnabled() {
return !getContext(ContextKeys.Disabled, false);
}

private notifyExtensionEnabled() {
if (!this.isReady) return;

void this.notify(DidChangeExtensionEnabledType, {
extensionEnabled: this.getExtensionEnabled(),
});
}

private _validating: Promise<void> | undefined;
private async validateSubscription(): Promise<void> {
if (this._validating == null) {
Expand Down
8 changes: 8 additions & 0 deletions src/webviews/home/protocol.ts
Expand Up @@ -8,6 +8,7 @@ export const enum CompletedActions {
}

export interface State {
extensionEnabled: boolean;
webroot?: string;
subscription: Subscription;
completedActions: CompletedActions[];
Expand Down Expand Up @@ -37,3 +38,10 @@ export interface DidChangeSubscriptionParams {
export const DidChangeSubscriptionNotificationType = new IpcNotificationType<DidChangeSubscriptionParams>(
'subscription/didChange',
);

export interface DidChangeExtensionEnabledParams {
extensionEnabled: boolean;
}
export const DidChangeExtensionEnabledType = new IpcNotificationType<DidChangeExtensionEnabledParams>(
'extensionEnabled/didChange',
);

0 comments on commit a312aa4

Please sign in to comment.