-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathextension.ts
More file actions
96 lines (80 loc) · 2.5 KB
/
extension.ts
File metadata and controls
96 lines (80 loc) · 2.5 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
87
88
89
90
91
92
93
94
95
96
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import * as vscode from "vscode";
import { initializeApi } from "./api";
import { initializeGitApi } from "./git";
import { registerLiveShareModule } from "./liveShare";
import { registerPlayerModule } from "./player";
import { registerRecorderModule } from "./recorder";
import { store } from "./store";
import {
promptForTour,
startCodeTour,
startDefaultTour
} from "./store/actions";
import { discoverTours as _discoverTours } from "./store/provider";
/**
* In order to check whether the URI handler was called on activation,
* we must do this dance around `discoverTours`. The same call to
* `discoverTours` is shared between `activate` and the URI handler.
*/
let cachedDiscoverTours: Promise<void> | undefined;
function discoverTours(): Promise<void> {
return cachedDiscoverTours ?? (cachedDiscoverTours = _discoverTours());
}
function startTour(params: URLSearchParams) {
let tourPath = params.get("tour");
const step = params.get("step");
let stepNumber;
if (step) {
// Allow the step number to be
// provided as 1-based vs. 0-based
stepNumber = Number(step) - 1;
}
if (tourPath) {
if (!tourPath.endsWith(".tour")) {
tourPath = `${tourPath}.tour`;
}
const tour = store.tours.find(tour => tour.id.endsWith(tourPath as string));
if (tour) {
startCodeTour(tour, stepNumber);
}
} else {
startDefaultTour(undefined, undefined, stepNumber);
}
}
class URIHandler implements vscode.UriHandler {
private _didStartDefaultTour = false;
get didStartDefaultTour(): boolean {
return this._didStartDefaultTour;
}
async handleUri(uri: vscode.Uri): Promise<void> {
this._didStartDefaultTour = true;
await discoverTours();
let query = uri.query;
if (uri.path === "/startDefaultTour") {
query = vscode.Uri.parse(uri.query).query;
}
if (query) {
const params = new URLSearchParams(query);
startTour(params);
} else {
startDefaultTour();
}
}
}
export async function activate(context: vscode.ExtensionContext) {
registerPlayerModule(context);
registerRecorderModule();
registerLiveShareModule();
const uriHandler = new URIHandler();
context.subscriptions.push(vscode.window.registerUriHandler(uriHandler));
if (vscode.workspace.workspaceFolders) {
await discoverTours();
if (!uriHandler.didStartDefaultTour) {
promptForTour(context.globalState);
}
initializeGitApi();
}
return initializeApi(context);
}