提交 1bf88815 编写于 作者: J Joao Moreno

fixes #12982

上级 3e9dc784
......@@ -13,9 +13,16 @@ import {ipcRenderer as ipc, shell} from 'electron';
import {IMessageService} from 'vs/platform/message/common/message';
import pkg from 'vs/platform/package';
import product from 'vs/platform/product';
import URI from 'vs/base/common/uri';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ReleaseNotesInput } from 'vs/workbench/parts/update/electron-browser/releaseNotesInput';
import { IRequestService } from 'vs/platform/request/common/request';
import { asText } from 'vs/base/node/request';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { Keybinding } from 'vs/base/common/keybinding';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IOpenerService } from 'vs/platform/opener/common/opener';
interface IUpdate {
releaseNotes: string;
......@@ -39,6 +46,70 @@ const NotNowAction = new Action(
() => TPromise.as(true)
);
export function loadReleaseNotes(accessor: ServicesAccessor, version: string): TPromise<string> {
const requestService = accessor.get(IRequestService);
const keybindingService = accessor.get(IKeybindingService);
const match = /^(\d+\.\d)\./.exec(version);
if (!match) {
return TPromise.as(null);
}
const versionLabel = match[1].replace(/\./g, '_');
const baseUrl = 'https://code.visualstudio.com/raw';
const url = `${ baseUrl }/v${ versionLabel }.md`;
const patchKeybindings = (text: string): string => {
const kb = (match: string, kb: string) => {
const keybinding = keybindingService.lookupKeybindings(kb)[0];
if (!keybinding) {
return match;
}
return keybindingService.getLabelFor(keybinding);
};
const kbstyle = (match: string, kb: string) => {
const code = Keybinding.fromUserSettingsLabel(kb);
if (!code) {
return match;
}
const keybinding = new Keybinding(code);
if (!keybinding) {
return match;
}
return keybindingService.getLabelFor(keybinding);
};
return text
.replace(/kb\(([a-z.\d\-]+)\)/gi, kb)
.replace(/kbstyle\(([^\)]+)\)/gi, kbstyle);
};
return requestService.request({ url })
.then(asText)
.then(text => patchKeybindings(text));
}
export class OpenLatestReleaseNotesInBrowserAction extends Action {
constructor(
@IOpenerService private openerService: IOpenerService
) {
super('update.openLatestReleaseNotes', nls.localize('releaseNotes', "Release Notes"), null, true);
}
run(): TPromise<any> {
const uri = URI.parse(product.releaseNotesUrl);
return this.openerService.open(uri);
}
}
export abstract class AbstractShowReleaseNotesAction extends Action {
constructor(
......@@ -47,14 +118,26 @@ export abstract class AbstractShowReleaseNotesAction extends Action {
private returnValue: boolean,
private version: string,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IInstantiationService private instantiationService: IInstantiationService
@IInstantiationService private instantiationService: IInstantiationService,
@IOpenerService private openerService: IOpenerService
) {
super(id, label, null, true);
}
run(): TPromise<boolean> {
return this.editorService.openEditor(this.instantiationService.createInstance(ReleaseNotesInput, this.version))
.then(() => this.returnValue);
if (!this.enabled) {
return TPromise.as(false);
}
this.enabled = false;
return this.instantiationService.invokeFunction(loadReleaseNotes, this.version)
.then(text => this.editorService.openEditor(this.instantiationService.createInstance(ReleaseNotesInput, this.version, text)))
.then(() => true)
.then(null, () => {
const action = this.instantiationService.createInstance(OpenLatestReleaseNotesInBrowserAction);
return action.run().then(() => false);
});
}
}
......@@ -64,9 +147,10 @@ export class ShowReleaseNotesAction extends AbstractShowReleaseNotesAction {
returnValue: boolean,
version: string,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IInstantiationService instantiationService: IInstantiationService
@IInstantiationService instantiationService: IInstantiationService,
@IOpenerService openerService: IOpenerService
) {
super('update.showReleaseNotes', nls.localize('releaseNotes', "Release Notes"), returnValue, version, editorService, instantiationService);
super('update.showReleaseNotes', nls.localize('releaseNotes', "Release Notes"), returnValue, version, editorService, instantiationService, openerService);
}
}
......@@ -79,9 +163,10 @@ export class ShowCurrentReleaseNotesAction extends AbstractShowReleaseNotesActio
id = ShowCurrentReleaseNotesAction.ID,
label = ShowCurrentReleaseNotesAction.LABEL,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IInstantiationService instantiationService: IInstantiationService
@IInstantiationService instantiationService: IInstantiationService,
@IOpenerService openerService: IOpenerService
) {
super(id, label, true, pkg.version, editorService, instantiationService);
super(id, label, true, pkg.version, editorService, instantiationService, openerService);
}
}
......
......@@ -15,7 +15,8 @@ import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } f
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IMessageService, CloseAction } from 'vs/platform/message/common/message';
import Severity from 'vs/base/common/severity';
import { ShowReleaseNotesAction, ShowCurrentReleaseNotesAction } from 'vs/workbench/electron-browser/update';
import { loadReleaseNotes, OpenLatestReleaseNotesInBrowserAction, ShowCurrentReleaseNotesAction } from 'vs/workbench/electron-browser/update';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Action } from 'vs/base/common/actions';
import { shell } from 'electron';
......@@ -42,22 +43,26 @@ export class UpdateContribution implements IWorkbenchContribution {
constructor(
@IStorageService storageService: IStorageService,
@IInstantiationService private instantiationService: IInstantiationService,
@IMessageService messageService: IMessageService
@IMessageService messageService: IMessageService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService
) {
const lastVersion = storageService.get(UpdateContribution.KEY, StorageScope.GLOBAL, '');
// was there an update?
if (product.releaseNotesUrl && lastVersion && pkg.version !== lastVersion) {
setTimeout(() => {
const releaseNotesAction = this.instantiationService.createInstance(ShowReleaseNotesAction, true, pkg.version);
messageService.show(Severity.Info, {
message: nls.localize('read the release notes', "Welcome to {0} v{1}! Would you like to read the Release Notes?", product.nameLong, pkg.version),
actions: [
releaseNotesAction,
CloseAction
]
});
this.instantiationService.invokeFunction(loadReleaseNotes, pkg.version)
.then(
text => this.editorService.openEditor(this.instantiationService.createInstance(ReleaseNotesInput, pkg.version, text)),
() => {
messageService.show(Severity.Info, {
message: nls.localize('read the release notes', "Welcome to {0} v{1}! Would you like to read the Release Notes?", product.nameLong, pkg.version),
actions: [
this.instantiationService.createInstance(OpenLatestReleaseNotesInBrowserAction),
CloseAction
]
});
});
}, 0);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册