Browse Source

Adds timestamp to state models for webviews

main
Eric Amodio 1 year ago
parent
commit
2ff1890571
18 changed files with 47 additions and 10 deletions
  1. +3
    -0
      src/plus/webviews/focus/focusWebview.ts
  2. +2
    -0
      src/plus/webviews/focus/protocol.ts
  3. +3
    -2
      src/plus/webviews/graph/graphWebview.ts
  4. +2
    -0
      src/plus/webviews/graph/protocol.ts
  5. +2
    -0
      src/plus/webviews/timeline/protocol.ts
  6. +4
    -0
      src/plus/webviews/timeline/timelineWebview.ts
  7. +13
    -3
      src/webviews/apps/shared/appBase.ts
  8. +2
    -0
      src/webviews/apps/shared/appWithConfigBase.ts
  9. +1
    -0
      src/webviews/commitDetails/commitDetailsWebview.ts
  10. +2
    -0
      src/webviews/commitDetails/protocol.ts
  11. +1
    -0
      src/webviews/home/homeWebview.ts
  12. +3
    -5
      src/webviews/home/protocol.ts
  13. +2
    -0
      src/webviews/rebase/protocol.ts
  14. +1
    -0
      src/webviews/rebase/rebaseEditor.ts
  15. +2
    -0
      src/webviews/settings/protocol.ts
  16. +1
    -0
      src/webviews/settings/settingsWebview.ts
  17. +2
    -0
      src/webviews/welcome/protocol.ts
  18. +1
    -0
      src/webviews/welcome/welcomeWebview.ts

+ 3
- 0
src/plus/webviews/focus/focusWebview.ts View File

@ -261,6 +261,7 @@ export class FocusWebviewProvider implements WebviewProvider {
const { subscription, isPlus } = await this.getSubscription();
if (!isPlus) {
return {
timestamp: Date.now(),
isPlus: isPlus,
subscription: subscription,
};
@ -273,6 +274,7 @@ export class FocusWebviewProvider implements WebviewProvider {
if (deferState || !hasConnectedRepos) {
return {
timestamp: Date.now(),
isPlus: isPlus,
subscription: subscription,
repos: (hasConnectedRepos ? connectedRepos : githubRepos).map(r => serializeRepoWithRichRemote(r)),
@ -296,6 +298,7 @@ export class FocusWebviewProvider implements WebviewProvider {
}));
return {
timestamp: Date.now(),
isPlus: isPlus,
subscription: subscription,
pullRequests: serializedPrs,

+ 2
- 0
src/plus/webviews/focus/protocol.ts View File

@ -4,6 +4,8 @@ import type { Subscription } from '../../../subscription';
import { IpcCommandType, IpcNotificationType } from '../../../webviews/protocol';
export type State = {
timestamp: number;
isPlus: boolean;
subscription: Subscription;
pullRequests?: PullRequestResult[];

+ 3
- 2
src/plus/webviews/graph/graphWebview.ts View File

@ -1712,7 +1712,7 @@ export class GraphWebviewProvider implements WebviewProvider {
private async getState(deferRows?: boolean): Promise<State> {
if (this.container.git.repositoryCount === 0) {
return { debugging: this.container.debugging, allowed: true, repositories: [] };
return { timestamp: Date.now(), debugging: this.container.debugging, allowed: true, repositories: [] };
}
if (this.trialBanner == null) {
@ -1725,7 +1725,7 @@ export class GraphWebviewProvider implements WebviewProvider {
if (this.repository == null) {
this.repository = this.container.git.getBestRepositoryOrFirst();
if (this.repository == null) {
return { debugging: this.container.debugging, allowed: true, repositories: [] };
return { timestamp: Date.now(), debugging: this.container.debugging, allowed: true, repositories: [] };
}
}
@ -1802,6 +1802,7 @@ export class GraphWebviewProvider implements WebviewProvider {
}
return {
timestamp: Date.now(),
windowFocused: this.isWindowFocused,
trialBanner: this.trialBanner,
repositories: formatRepositories(this.container.git.openRepositories),

+ 2
- 0
src/plus/webviews/graph/protocol.ts View File

@ -84,6 +84,8 @@ export const enum GraphMinimapMarkerTypes {
export const supportedRefMetadataTypes: GraphRefMetadataType[] = Object.values(GraphRefMetadataTypes);
export interface State {
timestamp: number;
windowFocused?: boolean;
repositories?: GraphRepository[];
selectedRepository?: string;

+ 2
- 0
src/plus/webviews/timeline/protocol.ts View File

@ -2,6 +2,8 @@ import type { FeatureAccess } from '../../../features';
import { IpcCommandType, IpcNotificationType } from '../../../webviews/protocol';
export interface State {
timestamp: number;
dataset?: Commit[];
emptyMessage?: string;
period: Period;

+ 4
- 0
src/plus/webviews/timeline/timelineWebview.ts View File

@ -252,6 +252,7 @@ export class TimelineWebviewProvider implements WebviewProvider {
if (current.uri == null) {
const access = await this.container.git.access(PlusFeatures.Timeline);
return {
timestamp: Date.now(),
emptyMessage: 'There are no editors open that can provide file history information',
period: period,
title: '',
@ -268,6 +269,7 @@ export class TimelineWebviewProvider implements WebviewProvider {
if (access.allowed === false) {
const dataset = generateRandomTimelineDataset();
return {
timestamp: Date.now(),
dataset: dataset.sort((a, b) => b.sort - a.sort),
period: period,
title: 'src/app/index.ts',
@ -296,6 +298,7 @@ export class TimelineWebviewProvider implements WebviewProvider {
if (log == null) {
return {
timestamp: Date.now(),
dataset: [],
emptyMessage: 'No commits found for the specified time period',
period: period,
@ -354,6 +357,7 @@ export class TimelineWebviewProvider implements WebviewProvider {
dataset.sort((a, b) => b.sort - a.sort);
return {
timestamp: Date.now(),
dataset: dataset,
period: period,
title: title,

+ 13
- 3
src/webviews/apps/shared/appBase.ts View File

@ -38,7 +38,7 @@ function nextIpcId() {
return `webview:${ipcSequence}`;
}
export abstract class App<State = undefined> {
export abstract class App<State extends { timestamp: number } = { timestamp: number }> {
private readonly _api: VsCodeApi;
protected state: State;
@ -65,6 +65,16 @@ export abstract class App {
// this.log(`ctor(${this.state ? JSON.stringify(this.state) : ''})`);
this._api = acquireVsCodeApi();
if (this.state != null) {
const state = this.getState();
if (state != null) {
if (this.state.timestamp > (state.timestamp ?? 0)) {
this._api.setState(this.state);
} else {
this.state = state;
}
}
}
const disposables: Disposable[] = [];
@ -151,8 +161,8 @@ export abstract class App {
Logger.log(message, ...optionalParams);
}
protected getState(): State {
return this._api.getState() as State;
protected getState(): State | undefined {
return this._api.getState() as State | undefined;
}
protected sendCommand<TCommand extends IpcCommandType<any>>(

+ 2
- 0
src/webviews/apps/shared/appWithConfigBase.ts View File

@ -19,6 +19,8 @@ const date = new Date(
);
interface AppStateWithConfig {
timestamp: number;
config: Config;
customSettings?: Record<string, boolean>;
}

+ 1
- 0
src/webviews/commitDetails/commitDetailsWebview.ts View File

@ -447,6 +447,7 @@ export class CommitDetailsWebviewProvider implements WebviewProvider
// const commitChoices = await Promise.all(this.commits.map(async commit => summaryModel(commit)));
const state = serialize<State>({
timestamp: Date.now(),
pinned: current.pinned,
includeRichContent: current.richStateLoaded,
// commits: commitChoices,

+ 2
- 0
src/webviews/commitDetails/protocol.ts View File

@ -37,6 +37,8 @@ export type Preferences = {
};
export type State = {
timestamp: number;
pinned: boolean;
preferences?: Preferences;
// commits?: CommitSummary[];

+ 1
- 0
src/webviews/home/homeWebview.ts View File

@ -227,6 +227,7 @@ export class HomeWebviewProvider implements WebviewProvider {
const dismissedBanners = this.container.storage.get('home:banners:dismissed', []);
return {
timestamp: Date.now(),
repositories: this.getRepositoriesState(),
webroot: this.host.getWebRoot(),
subscription: sub.subscription,

+ 3
- 5
src/webviews/home/protocol.ts View File

@ -9,11 +9,9 @@ export const enum CompletedActions {
}
export interface State {
repositories: {
count: number;
openCount: number;
hasUnsafe: boolean;
};
timestamp: number;
repositories: DidChangeRepositoriesParams;
webroot?: string;
subscription: Subscription;
completedActions: CompletedActions[];

+ 2
- 0
src/webviews/rebase/protocol.ts View File

@ -1,6 +1,8 @@
import { IpcCommandType, IpcNotificationType } from '../protocol';
export interface State {
timestamp: number;
branch: string;
onto: { sha: string; commit?: Commit } | undefined;

+ 1
- 0
src/webviews/rebase/rebaseEditor.ts View File

@ -691,6 +691,7 @@ async function parseRebaseTodo(
}
return {
timestamp: Date.now(),
branch: context.branchName ?? '',
onto: onto
? {

+ 2
- 0
src/webviews/settings/protocol.ts View File

@ -1,6 +1,8 @@
import type { Config } from '../../config';
export interface State {
timestamp: number;
config: Config;
customSettings?: Record<string, boolean>;
scope: 'user' | 'workspace';

+ 1
- 0
src/webviews/settings/settingsWebview.ts View File

@ -40,6 +40,7 @@ export class SettingsWebviewProvider extends WebviewProviderWithConfigBase
}
return {
timestamp: Date.now(),
// Make sure to get the raw config, not from the container which has the modes mixed in
config: configuration.getAll(true),
customSettings: this.getCustomSettings(),

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

@ -1,6 +1,8 @@
import type { Config } from '../../config';
export interface State {
timestamp: number;
config: Config;
customSettings?: Record<string, boolean>;
}

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

@ -6,6 +6,7 @@ import type { State } from './protocol';
export class WelcomeWebviewProvider extends WebviewProviderWithConfigBase<State> implements WebviewProvider<State> {
includeBootstrap(): State {
return {
timestamp: Date.now(),
// Make sure to get the raw config, not from the container which has the modes mixed in
config: configuration.getAll(true),
};

Loading…
Cancel
Save