-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlicense.ts
More file actions
46 lines (40 loc) · 1.22 KB
/
license.ts
File metadata and controls
46 lines (40 loc) · 1.22 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
import type { CancellationToken, LogOutputChannel } from "vscode";
import { execLocalStack } from "./cli.ts";
const LICENSE_VALIDITY_MARKER = "license validity: valid";
export async function checkIsLicenseValid(outputChannel: LogOutputChannel) {
try {
const licenseInfoResponse = await execLocalStack(["license", "info"], {
outputChannel,
});
return licenseInfoResponse.stdout.includes(LICENSE_VALIDITY_MARKER);
} catch (error) {
outputChannel.error(error instanceof Error ? error : String(error));
return false;
}
}
export async function activateLicense(outputChannel: LogOutputChannel) {
try {
await execLocalStack(["license", "activate"], {
outputChannel,
});
} catch (error) {
outputChannel.error(error instanceof Error ? error : String(error));
}
}
export async function activateLicenseUntilValid(
outputChannel: LogOutputChannel,
cancellationToken: CancellationToken,
): Promise<void> {
while (true) {
if (cancellationToken.isCancellationRequested) {
break;
}
const licenseIsValid = await checkIsLicenseValid(outputChannel);
if (licenseIsValid) {
break;
}
await activateLicense(outputChannel);
// Wait before trying again
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}