Browse Source

Adds auto account validation/refresh on focus/vis

main
Eric Amodio 3 years ago
parent
commit
39b246c777
2 changed files with 40 additions and 23 deletions
  1. +27
    -3
      src/webviews/premium/home/homeWebviewView.ts
  2. +13
    -20
      src/webviews/webviewViewBase.ts

+ 27
- 3
src/webviews/premium/home/homeWebviewView.ts View File

@ -16,11 +16,35 @@ export class HomeWebviewView extends WebviewViewBase {
void this.notifyDidChangeData(e.current);
}
protected override onVisibilityChanged(visible: boolean): void {
if (!visible) return;
void this.validateSubscription();
}
protected override onWindowFocusChanged(focused: boolean): void {
if (!focused) return;
void this.validateSubscription();
}
private _validating: Promise<void> | undefined;
private async validateSubscription(): Promise<void> {
if (this._validating == null) {
this._validating = this.container.subscription.validate();
try {
void (await this._validating);
} finally {
this._validating = undefined;
}
}
}
protected override registerCommands(): Disposable[] {
// TODO@eamodio implement hide commands
return [
commands.registerCommand('gitlens.home.hideWelcome', () => {}),
commands.registerCommand('gitlens.home.hideSubscription', () => {}),
commands.registerCommand('gitlens.home.hideWelcome', () => {
// TODO@eamodio implement hiding the welcome section and show a help/links section
}),
];
}

+ 13
- 20
src/webviews/webviewViewBase.ts View File

@ -7,6 +7,7 @@ import {
WebviewViewProvider,
WebviewViewResolveContext,
window,
WindowState,
workspace,
} from 'vscode';
import { getNonce } from '@env/crypto';
@ -89,6 +90,8 @@ export abstract class WebviewViewBase implements WebviewViewProvider, Dis
protected onReady?(): void;
protected onMessageReceived?(e: IpcMessage): void;
protected onVisibilityChanged?(visible: boolean): void;
protected onWindowFocusChanged?(focused: boolean): void;
protected registerCommands(): Disposable[] {
return emptyCommands;
@ -115,14 +118,15 @@ export abstract class WebviewViewBase implements WebviewViewProvider, Dis
this._disposableView = Disposable.from(
this._view.onDidDispose(this.onViewDisposed, this),
// this._view.onDidChangeVisibility(this.onViewVisibilityChanged, this),
this._view.onDidChangeVisibility(this.onViewVisibilityChanged, this),
this._view.webview.onDidReceiveMessage(this.onMessageReceivedCore, this),
window.onDidChangeWindowState(this.onWindowStateChanged, this),
...this.registerCommands(),
);
webviewView.webview.html = await this.getHtml(webviewView.webview);
// this.onViewVisibilityChanged();
this.onViewVisibilityChanged();
}
private onViewDisposed() {
@ -131,24 +135,13 @@ export abstract class WebviewViewBase implements WebviewViewProvider, Dis
this._view = undefined;
}
// private _disposableVisibility: Disposable | undefined;
// private onViewVisibilityChanged() {
// if (this._view?.visible) {
// console.log('became visible');
// if (this._disposableVisibility == null) {
// // this._disposableVisibility = window.onDidChangeActiveTextEditor(
// // debounce(this.onActiveEditorChanged, 500),
// // this,
// // );
// // this.onActiveEditorChanged(window.activeTextEditor);
// }
// } else {
// console.log('became hidden');
// this._disposableVisibility?.dispose();
// this._disposableVisibility = undefined;
// // this.setTitle(this.title);
// }
// }
private onViewVisibilityChanged() {
this.onVisibilityChanged?.(this.visible);
}
private onWindowStateChanged(e: WindowState) {
this.onWindowFocusChanged?.(e.focused);
}
private onMessageReceivedCore(e: IpcMessage) {
if (e == null) return;

Loading…
Cancel
Save