-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathReleaseNotes.ts
More file actions
86 lines (74 loc) · 2.43 KB
/
ReleaseNotes.ts
File metadata and controls
86 lines (74 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import * as semver from "semver";
import type { ExtensionContext } from "vscode";
import { URI } from "vscode-uri";
import type { Messages } from "@cursorless/lib-common";
import { showInfo } from "@cursorless/lib-common";
import type { VscodeApi } from "@cursorless/lib-vscode-common";
/**
* The key to use in global storage to detect when Cursorless version number has
* increased, so we can show release notes.
*/
export const VERSION_KEY = "version";
export const WHATS_NEW = "What's new?";
function roundDown(version: string) {
const { major, minor } = semver.parse(version)!;
return `${major}.${minor}.0`;
}
/**
* Responsible for showing a message to the users when Cursorless has new
* release notes available.
*/
export class ReleaseNotes {
constructor(
private vscodeApi: VscodeApi,
private extensionContext: ExtensionContext,
private messages: Messages,
) {}
/**
* Shows a message to the users if Cursorless has new release notes available
* @returns A promise that resolves when the release notes have been shown
*/
async maybeShow() {
// Round down because we just use the patch number to enforce monotone
// version numbers during CD
const currentVersion = roundDown(
getCursorlessVersion(this.extensionContext),
);
const storedVersion =
this.extensionContext.globalState.get<string>(VERSION_KEY);
if (storedVersion == null) {
// This is their initial install; note down initial install version, but
// don't show release notes
await this.extensionContext.globalState.update(
VERSION_KEY,
currentVersion,
);
return;
}
if (
// Don't show it in all the windows
!this.vscodeApi.window.state.focused ||
// Don't show it if they've seen this version before
!semver.lt(storedVersion, currentVersion)
) {
return;
}
await this.extensionContext.globalState.update(VERSION_KEY, currentVersion);
const result = await showInfo(
this.messages,
"releaseNotes",
`Cursorless version ${currentVersion} has been released!`,
WHATS_NEW,
);
if (result === WHATS_NEW) {
await this.vscodeApi.env.openExternal(
URI.parse(
`https://cursorless.org/docs/user/release-notes/${currentVersion}/`,
),
);
}
}
}
function getCursorlessVersion(extensionContext: ExtensionContext): string {
return extensionContext.extension.packageJSON.version;
}