Skip to content

Commit

Permalink
Add a "License" tab to local extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
frobinsonj committed Oct 21, 2019
1 parent 62ea960 commit 284b257
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export interface ILocalExtension extends IExtension {
metadata: IGalleryMetadata;
readmeUrl: URI | null;
changelogUrl: URI | null;
licenseUrl: URI | null;
}

export const IExtensionManagementService = createDecorator<IExtensionManagementService>('extensionManagementService');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,10 @@ export class ExtensionManagementService extends Disposable implements IExtension
const readmeUrl = readme ? URI.file(path.join(extensionPath, readme)) : null;
const changelog = children.filter(child => /^changelog(\.txt|\.md|)$/i.test(child))[0];
const changelogUrl = changelog ? URI.file(path.join(extensionPath, changelog)) : null;
const license = children.filter(child => /^license(\.txt|\.md|)$/i.test(child))[0];
const licenseUrl = license ? URI.file(path.join(extensionPath, license)) : null;
const identifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
const local = <ILocalExtension>{ type, identifier, manifest, metadata, location: URI.file(extensionPath), readmeUrl, changelogUrl };
const local = <ILocalExtension>{ type, identifier, manifest, metadata, location: URI.file(extensionPath), readmeUrl, changelogUrl, licenseUrl };
if (metadata) {
this.setMetadata(local, metadata);
}
Expand Down
14 changes: 13 additions & 1 deletion src/vs/workbench/contrib/extensions/browser/extensionEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const NavbarSection = {
Readme: 'readme',
Contributions: 'contributions',
Changelog: 'changelog',
License: 'license',
Dependencies: 'dependencies',
ExtensionPack: 'extensionPack'
};
Expand Down Expand Up @@ -169,6 +170,7 @@ export class ExtensionEditor extends BaseEditor {

private extensionReadme: Cache<string> | null;
private extensionChangelog: Cache<string> | null;
private extensionLicense: Cache<string> | null;
private extensionManifest: Cache<IExtensionManifest | null> | null;

private layoutParticipants: ILayoutParticipant[] = [];
Expand Down Expand Up @@ -196,6 +198,7 @@ export class ExtensionEditor extends BaseEditor {
super(ExtensionEditor.ID, telemetryService, themeService, storageService);
this.extensionReadme = null;
this.extensionChangelog = null;
this.extensionLicense = null;
this.extensionManifest = null;
}

Expand Down Expand Up @@ -232,7 +235,7 @@ export class ExtensionEditor extends BaseEditor {
repository.tabIndex = 0;

const license = append(subtitle, $('span.license.clickable'));
license.textContent = localize('license', 'License');
license.textContent = localize('license', "License");
license.style.display = 'none';
license.tabIndex = 0;

Expand Down Expand Up @@ -325,6 +328,7 @@ export class ExtensionEditor extends BaseEditor {

this.extensionReadme = new Cache(() => createCancelablePromise(token => extension.getReadme(token)));
this.extensionChangelog = new Cache(() => createCancelablePromise(token => extension.getChangelog(token)));
this.extensionLicense = new Cache(() => createCancelablePromise(token => extension.getLocalLicense(token)));
this.extensionManifest = new Cache(() => createCancelablePromise(token => extension.getManifest(token)));

const remoteBadge = this.instantiationService.createInstance(RemoteBadgeWidget, template.iconContainer, true);
Expand Down Expand Up @@ -442,6 +446,9 @@ export class ExtensionEditor extends BaseEditor {
if (extension.hasChangelog()) {
template.navbar.push(NavbarSection.Changelog, localize('changelog', "Changelog"), localize('changelogtooltip', "Extension update history, rendered from the extension's 'CHANGELOG.md' file"));
}
if (!extension.url && extension.hasLocalLicense()) {
template.navbar.push(NavbarSection.License, localize('license', "License"), localize('licensetooltip', "Extension license, rendered from the extension's 'LICENSE.md' file"));
}
if (extension.dependencies.length) {
template.navbar.push(NavbarSection.Dependencies, localize('dependencies', "Dependencies"), localize('dependenciestooltip', "Lists extensions this extension depends on"));
}
Expand Down Expand Up @@ -568,6 +575,7 @@ export class ExtensionEditor extends BaseEditor {
case NavbarSection.Readme: return this.openReadme(template);
case NavbarSection.Contributions: return this.openContributions(template);
case NavbarSection.Changelog: return this.openChangelog(template);
case NavbarSection.License: return this.openLicense(template);
case NavbarSection.Dependencies: return this.openDependencies(extension, template);
case NavbarSection.ExtensionPack: return this.openExtensionPack(extension, template);
}
Expand Down Expand Up @@ -829,6 +837,10 @@ export class ExtensionEditor extends BaseEditor {
return this.openMarkdown(this.extensionChangelog!.get(), localize('noChangelog', "No Changelog available."), template);
}

private openLicense(template: IExtensionEditorTemplate): Promise<IActiveElement> {
return this.openMarkdown(this.extensionLicense!.get(), localize('noLicense', "No License available."), template);
}

private openContributions(template: IExtensionEditorTemplate): Promise<IActiveElement> {
const content = $('div', { class: 'subcontent', tabindex: '0' });
return this.loadContents(() => this.extensionManifest!.get(), template)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,20 @@ ${this.description}
return this.fileService.readFile(changelogUrl).then(content => content.value.toString());
}

hasLocalLicense(): boolean {
return !!(this.local && this.local.licenseUrl);
}

getLocalLicense(token: CancellationToken): Promise<string> {
const licenseUrl = this.local && this.local.licenseUrl;

if (!licenseUrl) {
return Promise.reject(new Error('not available'));
}

return this.fileService.readFile(licenseUrl).then(content => content.value.toString());
}

get dependencies(): string[] {
const { local, gallery } = this;
if (gallery && !this.isGalleryOutdated()) {
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/contrib/extensions/common/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export interface IExtension {
hasReadme(): boolean;
getChangelog(token: CancellationToken): Promise<string>;
hasChangelog(): boolean;
getLocalLicense(token: CancellationToken): Promise<string>;
hasLocalLicense(): boolean;
readonly server?: IExtensionManagementServer;
readonly local?: ILocalExtension;
gallery?: IGalleryExtension;
Expand Down

0 comments on commit 284b257

Please sign in to comment.