Skip to content

Commit 2379829

Browse files
Adding URI handler
1 parent f3a5ae1 commit 2379829

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
- Automatically set the "pattern" record mode when you create a new tour, and select `None` for the git ref
55
- Added support for opening a `*.tour` file in the VS Code notebook editor (Insiders only)
66

7+
## v0.0.54
8+
9+
- Added a URI handler, with support for launching a specific tour and step
10+
711
## v0.0.53
812

913
- Exposed a new `onDidStartTour` event and `startTourByUri` method to the extension API

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "CodeTour",
44
"description": "VS Code extension that allows you to record and playback guided tours of codebases, directly within the editor",
55
"publisher": "vsls-contrib",
6-
"version": "0.0.53",
6+
"version": "0.0.54",
77
"author": {
88
"name": "Microsoft Corporation"
99
},

src/extension.ts

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
import { URLSearchParams } from "url";
45
import * as vscode from "vscode";
56
import { initializeApi } from "./api";
67
import { initializeGitApi } from "./git";
78
import { registerLiveShareModule } from "./liveShare";
89
import { registerPlayerModule } from "./player";
910
import { registerRecorderModule } from "./recorder";
10-
import { promptForTour, startDefaultTour } from "./store/actions";
11+
import { store } from "./store";
12+
import {
13+
promptForTour,
14+
startCodeTour,
15+
startDefaultTour
16+
} from "./store/actions";
1117
import { discoverTours as _discoverTours } from "./store/provider";
1218

1319
/**
@@ -21,16 +27,45 @@ function discoverTours(): Promise<void> {
2127
}
2228

2329
class URIHandler implements vscode.UriHandler {
24-
2530
private _didStartDefaultTour = false;
26-
get didStartDefaultTour(): boolean { return this._didStartDefaultTour; }
31+
get didStartDefaultTour(): boolean {
32+
return this._didStartDefaultTour;
33+
}
2734

2835
async handleUri(uri: vscode.Uri): Promise<void> {
29-
if (uri.path === '/startDefaultTour') {
36+
if (uri.path === "/startDefaultTour") {
3037
this._didStartDefaultTour = true;
3138

3239
await discoverTours();
33-
startDefaultTour();
40+
41+
let tourPath: string | null | undefined, stepNumber;
42+
if (uri.query) {
43+
const origin = vscode.Uri.parse(uri.query);
44+
if (origin.query) {
45+
const params = new URLSearchParams(origin.query);
46+
tourPath = params.get("tour");
47+
48+
const step = params.get("step");
49+
if (step) {
50+
stepNumber = Number(step);
51+
}
52+
}
53+
}
54+
55+
if (tourPath) {
56+
if (!tourPath.endsWith(".tour")) {
57+
tourPath = `${tourPath}.tour`;
58+
}
59+
60+
const tour = store.tours.find(tour =>
61+
tour.id.endsWith(tourPath as string)
62+
);
63+
if (tour) {
64+
startCodeTour(tour, stepNumber);
65+
}
66+
} else {
67+
startDefaultTour(undefined, undefined, stepNumber);
68+
}
3469
}
3570

3671
return;

src/store/actions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ export async function promptForTour(
180180

181181
export async function startDefaultTour(
182182
workspaceRoot: Uri = getWorkspaceKey(),
183-
tours: CodeTour[] = store.tours
183+
tours: CodeTour[] = store.tours,
184+
step: number = 0
184185
): Promise<boolean> {
185186
if (tours.length === 0) {
186187
return false;
@@ -191,7 +192,7 @@ export async function startDefaultTour(
191192
tours.find(tour => tour.title.match(/^#?1\s+-/));
192193

193194
if (primaryTour) {
194-
startCodeTour(primaryTour, 0, workspaceRoot, false, undefined, tours);
195+
startCodeTour(primaryTour, step, workspaceRoot, false, undefined, tours);
195196
return true;
196197
} else {
197198
return selectTour(tours, workspaceRoot);

0 commit comments

Comments
 (0)