Ver código fonte

Adds `webviewId` to all webview state

Adds `data-vscode-context` w/ a webview id property for context menus
main
Eric Amodio 1 ano atrás
pai
commit
b2408d05c5
30 arquivos alterados com 76 adições e 18 exclusões
  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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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 Ver arquivo

@ -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

Carregando…
Cancelar
Salvar