提交 5c5a6305 编写于 作者: N Nick Olinger

add release not caching support

上级 47e2a847
......@@ -46,6 +46,8 @@ const NotNowAction = new Action(
() => TPromise.as(true)
);
let releaseNotesCache: Object = {};
export function loadReleaseNotes(accessor: ServicesAccessor, version: string): TPromise<string> {
const requestService = accessor.get(IRequestService);
const keybindingService = accessor.get(IKeybindingService);
......@@ -59,6 +61,17 @@ export function loadReleaseNotes(accessor: ServicesAccessor, version: string): T
const baseUrl = 'https://code.visualstudio.com/raw';
const url = `${baseUrl}/v${versionLabel}.md`;
const storeReleaseNotes = (text: string): TPromise<string> => {
releaseNotesCache[version] = text;
return new TPromise<string>((c, e) => c(releaseNotesCache[version]));
};
const getReleaseNotes = (): TPromise<string> => {
return new TPromise<string>((c, e) => {
c(releaseNotesCache[version]);
});
};
const patchKeybindings = (text: string): string => {
const kb = (match: string, kb: string) => {
const keybinding = keybindingService.lookupKeybindings(kb)[0];
......@@ -91,9 +104,14 @@ export function loadReleaseNotes(accessor: ServicesAccessor, version: string): T
.replace(/kbstyle\(([^\)]+)\)/gi, kbstyle);
};
return requestService.request({ url })
.then(asText)
.then(text => patchKeybindings(text));
if (releaseNotesCache[version]) {
return getReleaseNotes()
.then(text => patchKeybindings(text));
} else {
return requestService.request({ url })
.then(asText)
.then(text => storeReleaseNotes(patchKeybindings(text)));
}
}
export class OpenLatestReleaseNotesInBrowserAction extends Action {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册