Bladeren bron

Fixes stale webview state on reload

main
Eric Amodio 1 jaar geleden
bovenliggende
commit
30673152be
8 gewijzigde bestanden met toevoegingen van 58 en 23 verwijderingen
  1. +14
    -12
      src/plus/webviews/account/accountWebview.ts
  2. +14
    -5
      src/plus/webviews/timeline/timelineWebview.ts
  3. +2
    -1
      src/webviews/apps/home/home.ts
  4. +1
    -0
      src/webviews/apps/plus/account/account.ts
  5. +14
    -5
      src/webviews/commitDetails/commitDetailsWebview.ts
  6. +4
    -0
      src/webviews/home/homeWebview.ts
  7. +5
    -0
      src/webviews/webviewController.ts
  8. +4
    -0
      src/webviews/welcome/welcomeWebview.ts

+ 14
- 12
src/plus/webviews/account/accountWebview.ts Bestand weergeven

@ -23,7 +23,19 @@ export class AccountWebviewProvider implements WebviewProvider {
}
private onSubscriptionChanged(e: SubscriptionChangeEvent) {
void this.notifyDidChangeData(e.current);
void this.notifyDidChangeSubscription(e.current);
}
registerCommands(): Disposable[] {
return [registerCommand(`${this.host.id}.refresh`, () => this.host.refresh(true), this)];
}
includeBootstrap(): Promise<State> {
return this.getState();
}
onReloaded(): void {
void this.notifyDidChangeSubscription();
}
onVisibilityChanged(visible: boolean): void {
@ -44,14 +56,6 @@ export class AccountWebviewProvider implements WebviewProvider {
queueMicrotask(() => void this.validateSubscription());
}
registerCommands(): Disposable[] {
return [registerCommand(`${this.host.id}.refresh`, () => this.host.refresh(true), this)];
}
includeBootstrap(): Promise<State> {
return this.getState();
}
private async getRepoVisibility(): Promise<RepositoriesVisibility> {
const visibility = await this.container.git.visibility();
return visibility;
@ -84,9 +88,7 @@ export class AccountWebviewProvider implements WebviewProvider {
};
}
private notifyDidChangeData(subscription?: Subscription) {
if (!this.host.ready) return false;
private notifyDidChangeSubscription(subscription?: Subscription) {
return window.withProgress({ location: { viewId: this.host.id } }, async () => {
const sub = await this.getSubscription(subscription);
return this.host.notify(DidChangeSubscriptionNotificationType, {

+ 14
- 5
src/plus/webviews/timeline/timelineWebview.ts Bestand weergeven

@ -79,6 +79,10 @@ export class TimelineWebviewProvider implements WebviewProvider {
this._disposable.dispose();
}
onReloaded(): void {
void this.notifyDidChangeState(true);
}
onShowing(
loading: boolean,
_options: { column?: ViewColumn; preserveFocus?: boolean },
@ -412,13 +416,18 @@ export class TimelineWebviewProvider implements WebviewProvider {
}
@debug()
private async notifyDidChangeState() {
private async notifyDidChangeState(force: boolean = false) {
this._notifyDidChangeStateDebounced?.cancel();
if (this._pendingContext == null) return false;
if (!force && this._pendingContext == null) return false;
const context = { ...this._context, ...this._pendingContext };
this._context = context;
this._pendingContext = undefined;
let context: Context;
if (this._pendingContext != null) {
context = { ...this._context, ...this._pendingContext };
this._context = context;
this._pendingContext = undefined;
} else {
context = this._context;
}
const task = async () =>
this.host.notify(DidChangeNotificationType, {

+ 2
- 1
src/webviews/apps/home/home.ts Bestand weergeven

@ -46,7 +46,8 @@ export class HomeApp extends App {
this.log(`onMessageReceived(${msg.id}): name=${msg.method}`);
onIpc(DidChangeRepositoriesType, msg, params => {
this.state.repositories = { ...params };
this.state.repositories = params;
this.state.timestamp = Date.now();
this.setState(this.state);
this.updateNoRepo();
});

+ 1
- 0
src/webviews/apps/plus/account/account.ts Bestand weergeven

@ -41,6 +41,7 @@ export class AccountApp extends App {
onIpc(DidChangeSubscriptionNotificationType, msg, params => {
this.state.subscription = params.subscription;
this.state.avatar = params.avatar;
this.state.timestamp = Date.now();
this.setState(this.state);
this.updateState();
});

+ 14
- 5
src/webviews/commitDetails/commitDetailsWebview.ts Bestand weergeven

@ -137,6 +137,10 @@ export class CommitDetailsWebviewProvider implements WebviewProvider
this._disposable.dispose();
}
onReloaded(): void {
void this.notifyDidChangeState(true);
}
async onShowing(
_loading: boolean,
options: { column?: ViewColumn; preserveFocus?: boolean },
@ -705,15 +709,20 @@ export class CommitDetailsWebviewProvider implements WebviewProvider
this.updateState();
}
private async notifyDidChangeState() {
private async notifyDidChangeState(force: boolean = false) {
const scope = getLogScope();
this._notifyDidChangeStateDebounced?.cancel();
if (this._pendingContext == null) return false;
if (!force && this._pendingContext == null) return false;
const context = { ...this._context, ...this._pendingContext };
this._context = context;
this._pendingContext = undefined;
let context: Context;
if (this._pendingContext != null) {
context = { ...this._context, ...this._pendingContext };
this._context = context;
this._pendingContext = undefined;
} else {
context = this._context;
}
return window.withProgress({ location: { viewId: this.host.id } }, async () => {
try {

+ 4
- 0
src/webviews/home/homeWebview.ts Bestand weergeven

@ -39,6 +39,10 @@ export class HomeWebviewProvider implements WebviewProvider {
return this.getState();
}
onReloaded() {
this.notifyDidChangeRepositories();
}
private getState(): State {
return {
timestamp: Date.now(),

+ 5
- 0
src/webviews/webviewController.ts Bestand weergeven

@ -47,6 +47,7 @@ export interface WebviewProvider extends Disposa
onReady?(): void;
onRefresh?(force?: boolean): void;
onReloaded?(): void;
onMessageReceived?(e: IpcMessage): void;
onActiveChanged?(active: boolean): void;
onFocusChanged?(focused: boolean): void;
@ -373,6 +374,10 @@ export class WebviewController<
if (visible) {
if (this._ready) {
this.sendPendingIpcNotifications();
} else if (this.provider.onReloaded != null) {
this.provider.onReloaded();
} else {
void this.refresh();
}
} else {
this._ready = false;

+ 4
- 0
src/webviews/welcome/welcomeWebview.ts Bestand weergeven

@ -33,6 +33,10 @@ export class WelcomeWebviewProvider implements WebviewProvider {
return this.getState();
}
onReloaded() {
this.notifyDidChange();
}
private onConfigurationChanged(e: ConfigurationChangeEvent) {
if (!configuration.changed(e, 'codeLens.enabled') && !configuration.changed(e, 'currentLine.enabled')) return;

Laden…
Annuleren
Opslaan