Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show "show release notes" checkbox #168616

Merged
merged 1 commit into from Dec 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 66 additions & 5 deletions src/vs/workbench/contrib/update/browser/releaseNotesEditor.ts
Expand Up @@ -28,15 +28,17 @@ import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editor
import { ACTIVE_GROUP, IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { getTelemetryLevel, supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IConfigurationChangeEvent, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
import { DisposableStore } from 'vs/base/common/lifecycle';

export class ReleaseNotesManager {

private readonly _releaseNotesCache = new Map<string, Promise<string>>();

private _currentReleaseNotes: WebviewInput | undefined = undefined;
private _lastText: string | undefined;
private disposables = new DisposableStore();

public constructor(
@IEnvironmentService private readonly _environmentService: IEnvironmentService,
Expand All @@ -60,6 +62,9 @@ export class ReleaseNotesManager {
this._currentReleaseNotes.webview.html = html;
}
});

_configurationService.onDidChangeConfiguration(this.onDidChangeConfiguration, this, this.disposables);
_webviewWorkbenchService.onDidChangeActiveWebviewEditor(this.onDidChangeActiveWebviewEditor, this, this.disposables);
}

public async show(version: string): Promise<boolean> {
Expand All @@ -81,7 +86,8 @@ export class ReleaseNotesManager {
enableFindWidget: true,
},
contentOptions: {
localResourceRoots: []
localResourceRoots: [],
allowScripts: true
},
extension: undefined
},
Expand All @@ -90,7 +96,18 @@ export class ReleaseNotesManager {
{ group: ACTIVE_GROUP, preserveFocus: false });

this._currentReleaseNotes.webview.onDidClickLink(uri => this.onDidClickLink(URI.parse(uri)));
this._currentReleaseNotes.onWillDispose(() => { this._currentReleaseNotes = undefined; });

const disposables = new DisposableStore();
disposables.add(this._currentReleaseNotes.webview.onMessage(e => {
if (e.message.type === 'showReleaseNotes') {
this._configurationService.updateValue('update.showReleaseNotes', e.message.value);
}
}));

disposables.add(this._currentReleaseNotes.onWillDispose(() => {
disposables.dispose();
this._currentReleaseNotes = undefined;
}));

this._currentReleaseNotes.webview.html = html;
}
Expand Down Expand Up @@ -206,18 +223,62 @@ export class ReleaseNotesManager {
const content = await renderMarkdownDocument(text, this._extensionService, this._languageService, false);
const colorMap = TokenizationRegistry.getColorMap();
const css = colorMap ? generateTokensCSSForColorMap(colorMap) : '';
const showReleaseNotes = this._configurationService.getValue<boolean>('update.showReleaseNotes');

return `<!DOCTYPE html>
<html>
<head>
<base href="https://code.visualstudio.com/raw/">
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src https: data:; media-src https:; style-src 'nonce-${nonce}' https://code.visualstudio.com;">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src https: data:; media-src https:; style-src 'nonce-${nonce}' https://code.visualstudio.com; script-src 'nonce-${nonce}';">
<style nonce="${nonce}">
${DEFAULT_MARKDOWN_STYLES}
${css}
header { display: flex; align-items: center; padding-top: 1em; }
</style>
</head>
<body>${content}</body>
<body>
<header>
<input type="checkbox" id="showReleaseNotes" ${showReleaseNotes ? 'checked' : ''}>
<label for="showReleaseNotes">${nls.localize('showOnUpdate', "Show release notes after an update")}</label>
</header>
${content}
<script nonce="${nonce}">
const vscode = acquireVsCodeApi();
const checkbox = document.getElementById('showReleaseNotes');

window.addEventListener('message', event => {
if (event.data.type === 'showReleaseNotes') {
checkbox.checked = event.data.value;
}
});

checkbox.addEventListener('change', event => {
vscode.postMessage({ type: 'showReleaseNotes', value: checkbox.checked }, '*');
});
</script>
</body>
</html>`;
}

private onDidChangeConfiguration(e: IConfigurationChangeEvent): void {
if (e.affectsConfiguration('update.showReleaseNotes')) {
this.updateWebview();
}
}

private onDidChangeActiveWebviewEditor(input: WebviewInput | undefined): void {
if (input && input === this._currentReleaseNotes) {
this.updateWebview();
}
}

private updateWebview() {
if (this._currentReleaseNotes) {
this._currentReleaseNotes.webview.postMessage({
type: 'showReleaseNotes',
value: this._configurationService.getValue<boolean>('update.showReleaseNotes')
});
}
}
}