Quellcode durchsuchen

Adds `webviewId` to all webview state

Adds `data-vscode-context` w/ a webview id property for context menus
main
Eric Amodio vor 1 Jahr
Ursprung
Commit
b2408d05c5
30 geänderte Dateien mit 76 neuen und 18 gelöschten Zeilen
  1. +1
    -0
      src/plus/webviews/account/accountWebview.ts
  2. +2
    -0
      src/plus/webviews/account/protocol.ts
  3. +6
    -0
      src/plus/webviews/focus/focusWebview.ts
  4. +2
    -0
      src/plus/webviews/focus/protocol.ts
  5. +3
    -2
      src/plus/webviews/graph/graphWebview.ts
  6. +2
    -0
      src/plus/webviews/graph/protocol.ts
  7. +2
    -0
      src/plus/webviews/timeline/protocol.ts
  8. +3
    -0
      src/plus/webviews/timeline/timelineWebview.ts
  9. +5
    -1
      src/webviews/apps/commitDetails/commitDetails.html
  10. +1
    -1
      src/webviews/apps/home/home.html
  11. +5
    -1
      src/webviews/apps/plus/account/account.html
  12. +1
    -1
      src/webviews/apps/plus/focus/focus.html
  13. +1
    -1
      src/webviews/apps/plus/graph/graph.html
  14. +1
    -1
      src/webviews/apps/plus/timeline/timeline.html
  15. +1
    -1
      src/webviews/apps/rebase/rebase.html
  16. +1
    -1
      src/webviews/apps/settings/settings.html
  17. +7
    -1
      src/webviews/apps/shared/appBase.ts
  18. +5
    -1
      src/webviews/apps/welcome/welcome.html
  19. +1
    -0
      src/webviews/commitDetails/commitDetailsWebview.ts
  20. +2
    -0
      src/webviews/commitDetails/protocol.ts
  21. +1
    -0
      src/webviews/home/homeWebview.ts
  22. +2
    -0
      src/webviews/home/protocol.ts
  23. +2
    -0
      src/webviews/rebase/protocol.ts
  24. +2
    -0
      src/webviews/rebase/rebaseEditor.ts
  25. +2
    -0
      src/webviews/settings/protocol.ts
  26. +1
    -0
      src/webviews/settings/settingsWebview.ts
  27. +5
    -1
      src/webviews/webviewController.ts
  28. +5
    -5
      src/webviews/webviewsController.ts
  29. +3
    -0
      src/webviews/welcome/protocol.ts
  30. +1
    -0
      src/webviews/welcome/welcomeWebview.ts

+ 1
- 0
src/plus/webviews/account/accountWebview.ts Datei anzeigen

@ -84,6 +84,7 @@ export class AccountWebviewProvider implements WebviewProvider {
const subscriptionResult = await this.getSubscription(subscription);
return {
webviewId: this.host.id,
timestamp: Date.now(),
webroot: this.host.getWebRoot(),
subscription: subscriptionResult.subscription,

+ 2
- 0
src/plus/webviews/account/protocol.ts Datei anzeigen

@ -1,7 +1,9 @@
import type { WebviewIds, WebviewViewIds } from '../../../constants';
import type { Subscription } from '../../../subscription';
import { IpcNotificationType } from '../../../webviews/protocol';
export interface State {
webviewId: WebviewIds | WebviewViewIds;
timestamp: number;
webroot?: string;

+ 6
- 0
src/plus/webviews/focus/focusWebview.ts Datei anzeigen

@ -243,9 +243,12 @@ export class FocusWebviewProvider implements WebviewProvider {
}
private async getState(deferState?: boolean): Promise<State> {
const webviewId = this.host.id;
const access = await this.container.git.access(PlusFeatures.Focus);
if (access.allowed !== true) {
return {
webviewId: webviewId,
timestamp: Date.now(),
access: access,
};
@ -258,6 +261,7 @@ export class FocusWebviewProvider implements WebviewProvider {
if (!hasConnectedRepos) {
return {
webviewId: webviewId,
timestamp: Date.now(),
access: access,
repos: githubRepos.map(r => serializeRepoWithRichRemote(r)),
@ -274,6 +278,7 @@ export class FocusWebviewProvider implements WebviewProvider {
async function getStateCore() {
const [prsResult, issuesResult] = await statePromise;
return {
webviewId: webviewId,
timestamp: Date.now(),
access: access,
repos: repos,
@ -299,6 +304,7 @@ export class FocusWebviewProvider implements WebviewProvider {
});
return {
webviewId: webviewId,
timestamp: Date.now(),
access: access,
repos: repos,

+ 2
- 0
src/plus/webviews/focus/protocol.ts Datei anzeigen

@ -1,9 +1,11 @@
import type { WebviewIds, WebviewViewIds } from '../../../constants';
import type { FeatureAccess } from '../../../features';
import type { IssueShape } from '../../../git/models/issue';
import type { PullRequestShape } from '../../../git/models/pullRequest';
import { IpcCommandType, IpcNotificationType } from '../../../webviews/protocol';
export interface State {
webviewId: WebviewIds | WebviewViewIds;
timestamp: number;
access: FeatureAccess;

+ 3
- 2
src/plus/webviews/graph/graphWebview.ts Datei anzeigen

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

+ 2
- 0
src/plus/webviews/graph/protocol.ts Datei anzeigen

@ -23,6 +23,7 @@ import type {
WorkDirStats,
} from '@gitkraken/gitkraken-components';
import type { Config, DateStyle } from '../../../config';
import type { WebviewIds, WebviewViewIds } from '../../../constants';
import type { RepositoryVisibility } from '../../../git/gitProvider';
import type { GitTrackingState } from '../../../git/models/branch';
import type { GitGraphRowType } from '../../../git/models/graph';
@ -84,6 +85,7 @@ export type GraphMinimapMarkerTypes =
export const supportedRefMetadataTypes: GraphRefMetadataType[] = Object.values(GraphRefMetadataTypes);
export interface State {
webviewId: WebviewIds | WebviewViewIds;
timestamp: number;
windowFocused?: boolean;

+ 2
- 0
src/plus/webviews/timeline/protocol.ts Datei anzeigen

@ -1,7 +1,9 @@
import type { WebviewIds, WebviewViewIds } from '../../../constants';
import type { FeatureAccess } from '../../../features';
import { IpcCommandType, IpcNotificationType } from '../../../webviews/protocol';
export interface State {
webviewId: WebviewIds | WebviewViewIds;
timestamp: number;
dataset?: Commit[];

+ 3
- 0
src/plus/webviews/timeline/timelineWebview.ts Datei anzeigen

@ -282,6 +282,7 @@ export class TimelineWebviewProvider implements WebviewProvider {
if (current.uri == null || gitUri == null || repoPath == null || access.allowed === false) {
const access = await this.container.git.access(PlusFeatures.Timeline, repoPath);
return {
webviewId: this.host.id,
timestamp: Date.now(),
period: period,
title: gitUri?.relativePath,
@ -304,6 +305,7 @@ export class TimelineWebviewProvider implements WebviewProvider {
if (log == null) {
return {
webviewId: this.host.id,
timestamp: Date.now(),
dataset: [],
period: period,
@ -362,6 +364,7 @@ export class TimelineWebviewProvider implements WebviewProvider {
dataset.sort((a, b) => b.sort - a.sort);
return {
webviewId: this.host.id,
timestamp: Date.now(),
dataset: dataset,
period: period,

+ 5
- 1
src/webviews/apps/commitDetails/commitDetails.html Datei anzeigen

@ -16,7 +16,11 @@
</style>
</head>
<body class="preload" data-placement="#{placement}">
<body
class="preload"
data-placement="#{placement}"
data-vscode-context='{ "preventDefaultContextMenuItems": true, "webview": "#{webviewId}" }'
>
<gl-commit-details-app id="app"></gl-commit-details-app>
#{endOfBody}
</body>

+ 1
- 1
src/webviews/apps/home/home.html Datei anzeigen

@ -16,7 +16,7 @@
</style>
</head>
<body class="home preload" data-placement="#{placement}">
<body class="home preload" data-placement="#{placement}" data-vscode-context='{ "webview": "#{webviewId}" }'>
<div class="home__nav">
<nav class="inline-nav" id="links" aria-label="Help and Resources">
<div class="inline-nav__group">

+ 5
- 1
src/webviews/apps/plus/account/account.html Datei anzeigen

@ -11,7 +11,11 @@
</style>
</head>
<body class="account scrollable preload" data-placement="#{placement}">
<body
class="account scrollable preload"
data-placement="#{placement}"
data-vscode-context='{ "webview": "#{webviewId}" }'
>
<account-content id="account-content"></account-content>
#{endOfBody}

+ 1
- 1
src/webviews/apps/plus/focus/focus.html Datei anzeigen

@ -20,7 +20,7 @@
</style>
</head>
<body class="preload" data-placement="#{placement}">
<body class="preload" data-placement="#{placement}" data-vscode-context='{ "webview": "#{webviewId}" }'>
<gl-focus-app id="app"></gl-focus-app>
#{endOfBody}
</body>

+ 1
- 1
src/webviews/apps/plus/graph/graph.html Datei anzeigen

@ -22,7 +22,7 @@
<body
class="graph-app scrollable"
data-placement="#{placement}"
data-vscode-context='{ "preventDefaultContextMenuItems": true }'
data-vscode-context='{ "preventDefaultContextMenuItems": true, "webview": "#{webviewId}" }'
>
<div id="root" class="graph-app__container"></div>
#{endOfBody}

+ 1
- 1
src/webviews/apps/plus/timeline/timeline.html Datei anzeigen

@ -16,7 +16,7 @@
</style>
</head>
<body class="preload" data-placement="#{placement}">
<body class="preload" data-placement="#{placement}" data-vscode-context='{ "webview": "#{webviewId}" }'>
<gk-feature-gate id="subscription-gate" class="scrollable"
><p slot="feature">
Visualize the evolution of a file, including when changes were made, how large they were, and who made

+ 1
- 1
src/webviews/apps/rebase/rebase.html Datei anzeigen

@ -11,7 +11,7 @@
</style>
</head>
<body class="scrollable preload" data-placement="#{placement}">
<body class="scrollable preload" data-placement="#{placement}" data-vscode-context='{ "webview": "#{webviewId}" }'>
<div class="container">
<header>
<h2>GitLens Interactive Rebase</h2>

+ 1
- 1
src/webviews/apps/settings/settings.html Datei anzeigen

@ -11,7 +11,7 @@
</style>
</head>
<body class="scrollable preload" data-placement="#{placement}">
<body class="scrollable preload" data-placement="#{placement}" data-vscode-context='{ "webview": "#{webviewId}" }'>
<!-- <canvas class="snow"></canvas>
<img
class="snow__trigger snow__trigger--fixed-right snow__trigger--flipped"

+ 7
- 1
src/webviews/apps/shared/appBase.ts Datei anzeigen

@ -1,4 +1,5 @@
/*global window document*/
import type { CustomEditorIds, WebviewIds, WebviewViewIds } from '../../../constants';
import { debounce } from '../../../system/function';
import { Logger } from '../../../system/logger';
import { LogLevel } from '../../../system/logger.constants';
@ -38,7 +39,12 @@ function nextIpcId() {
return `webview:${ipcSequence}`;
}
export abstract class App<State extends { timestamp: number } = { timestamp: number }> {
export abstract class App<
State extends { webviewId: CustomEditorIds | WebviewIds | WebviewViewIds; timestamp: number } = {
webviewId: CustomEditorIds | WebviewIds | WebviewViewIds;
timestamp: number;
},
> {
private readonly _api: VsCodeApi;
protected state: State;
protected readonly placement: 'editor' | 'view';

+ 5
- 1
src/webviews/apps/welcome/welcome.html Datei anzeigen

@ -16,7 +16,11 @@
</style>
</head>
<body class="welcome scrollable preload" data-placement="#{placement}">
<body
class="welcome scrollable preload"
data-placement="#{placement}"
data-vscode-context='{ "webview": "#{webviewId}" }'
>
<!-- <canvas class="snow"></canvas>
<img
class="snow__trigger snow__trigger--fixed-right snow__trigger--flipped"

+ 1
- 0
src/webviews/commitDetails/commitDetailsWebview.ts Datei anzeigen

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

+ 2
- 0
src/webviews/commitDetails/protocol.ts Datei anzeigen

@ -1,6 +1,7 @@
import type { TextDocumentShowOptions } from 'vscode';
import type { Autolink } from '../../annotations/autolinks';
import type { Config } from '../../config';
import type { WebviewIds, WebviewViewIds } from '../../constants';
import type { GitCommitIdentityShape, GitCommitStats } from '../../git/models/commit';
import type { GitFileChangeShape } from '../../git/models/file';
import type { IssueOrPullRequest } from '../../git/models/issue';
@ -36,6 +37,7 @@ export interface Preferences {
}
export interface State {
webviewId: WebviewIds | WebviewViewIds;
timestamp: number;
pinned: boolean;

+ 1
- 0
src/webviews/home/homeWebview.ts Datei anzeigen

@ -48,6 +48,7 @@ export class HomeWebviewProvider implements WebviewProvider {
private getState(): State {
return {
webviewId: this.host.id,
timestamp: Date.now(),
repositories: this.getRepositoriesState(),
webroot: this.host.getWebRoot(),

+ 2
- 0
src/webviews/home/protocol.ts Datei anzeigen

@ -1,6 +1,8 @@
import type { WebviewIds, WebviewViewIds } from '../../constants';
import { IpcNotificationType } from '../protocol';
export interface State {
webviewId: WebviewIds | WebviewViewIds;
timestamp: number;
repositories: DidChangeRepositoriesParams;

+ 2
- 0
src/webviews/rebase/protocol.ts Datei anzeigen

@ -1,6 +1,8 @@
import type { CustomEditorIds } from '../../constants';
import { IpcCommandType, IpcNotificationType } from '../protocol';
export interface State {
webviewId: CustomEditorIds;
timestamp: number;
branch: string;

+ 2
- 0
src/webviews/rebase/rebaseEditor.ts Datei anzeigen

@ -598,6 +598,7 @@ export class RebaseEditorProvider implements CustomTextEditorProvider, Disposabl
const html = replaceWebviewHtmlTokens(
utf8TextDecoder.decode(bytes),
'gitlens.rebase',
context.panel.webview.cspSource,
getNonce(),
context.panel.webview.asWebviewUri(this.container.context.extensionUri).toString(),
@ -691,6 +692,7 @@ async function parseRebaseTodo(
}
return {
webviewId: 'gitlens.rebase',
timestamp: Date.now(),
branch: context.branchName ?? '',
onto: onto

+ 2
- 0
src/webviews/settings/protocol.ts Datei anzeigen

@ -1,6 +1,8 @@
import type { Config } from '../../config';
import type { WebviewIds, WebviewViewIds } from '../../constants';
export interface State {
webviewId: WebviewIds | WebviewViewIds;
timestamp: number;
version: string;

+ 1
- 0
src/webviews/settings/settingsWebview.ts Datei anzeigen

@ -47,6 +47,7 @@ export class SettingsWebviewProvider implements WebviewProvider {
}
return {
webviewId: this.host.id,
timestamp: Date.now(),
version: this.container.version,
// Make sure to get the raw config, not from the container which has the modes mixed in

+ 5
- 1
src/webviews/webviewController.ts Datei anzeigen

@ -447,6 +447,7 @@ export class WebviewController<
const html = replaceWebviewHtmlTokens(
utf8TextDecoder.decode(bytes),
this.descriptor.id,
webview.cspSource,
this._cspNonce,
this.asWebviewUri(this.getRootUri()).toString(),
@ -547,6 +548,7 @@ export class WebviewController<
export function replaceWebviewHtmlTokens<SerializedState>(
html: string,
webviewId: string,
cspSource: string,
cspNonce: string,
root: string,
@ -558,7 +560,7 @@ export function replaceWebviewHtmlTokens(
endOfBody?: string,
) {
return html.replace(
/#{(head|body|endOfBody|placement|cspSource|cspNonce|root|webroot)}/g,
/#{(head|body|endOfBody|webviewId|placement|cspSource|cspNonce|root|webroot)}/g,
(_substring: string, token: string) => {
switch (token) {
case 'head':
@ -573,6 +575,8 @@ export function replaceWebviewHtmlTokens(
)};</script>`
: ''
}${endOfBody ?? ''}`;
case 'webviewId':
return webviewId;
case 'placement':
return placement;
case 'cspSource':

+ 5
- 5
src/webviews/webviewsController.ts Datei anzeigen

@ -7,7 +7,7 @@ import type {
WebviewViewResolveContext,
} from 'vscode';
import { Disposable, Uri, ViewColumn, window } from 'vscode';
import type { Commands, WebviewTypes, WebviewViewTypes } from '../constants';
import type { Commands, WebviewIds, WebviewTypes, WebviewViewIds, WebviewViewTypes } from '../constants';
import type { Container } from '../container';
import { ensurePlusFeaturesEnabled } from '../plus/subscription/utils';
import { executeCoreCommand, registerCommand } from '../system/command';
@ -19,7 +19,7 @@ import type { WebviewProvider } from './webviewController';
import { WebviewController } from './webviewController';
export interface WebviewPanelDescriptor {
id: `gitlens.${WebviewTypes}`;
id: WebviewIds;
readonly fileName: string;
readonly iconPath: string;
readonly title: string;
@ -37,7 +37,7 @@ interface WebviewPanelRegistration {
}
export interface WebviewPanelProxy extends Disposable {
readonly id: `gitlens.${WebviewTypes}`;
readonly id: WebviewIds;
readonly ready: boolean;
readonly visible: boolean;
close(): void;
@ -46,7 +46,7 @@ export interface WebviewPanelProxy extends Disposable {
}
export interface WebviewViewDescriptor {
id: `gitlens.views.${WebviewViewTypes}`;
id: WebviewViewIds;
readonly fileName: string;
readonly title: string;
readonly contextKeyPrefix: `gitlens:webviewView:${WebviewViewTypes}`;
@ -65,7 +65,7 @@ interface WebviewViewRegistration {
}
export interface WebviewViewProxy extends Disposable {
readonly id: `gitlens.views.${WebviewViewTypes}`;
readonly id: WebviewViewIds;
readonly ready: boolean;
readonly visible: boolean;
refresh(force?: boolean): Promise<void>;

+ 3
- 0
src/webviews/welcome/protocol.ts Datei anzeigen

@ -1,8 +1,11 @@
import type { Config } from '../../config';
import type { WebviewIds, WebviewViewIds } from '../../constants';
import { IpcCommandType, IpcNotificationType } from '../protocol';
export interface State {
webviewId: WebviewIds | WebviewViewIds;
timestamp: number;
version: string;
config: {
codeLens: Config['codeLens']['enabled'];

+ 1
- 0
src/webviews/welcome/welcomeWebview.ts Datei anzeigen

@ -65,6 +65,7 @@ export class WelcomeWebviewProvider implements WebviewProvider {
}
private async getState(subscription?: Subscription): Promise<State> {
return {
webviewId: this.host.id,
timestamp: Date.now(),
version: this.container.version,
// Make sure to get the raw config so to avoid having the mode mixed in

Laden…
Abbrechen
Speichern