Skip to content

Commit

Permalink
Adding URI handler
Browse files Browse the repository at this point in the history
  • Loading branch information
lostintangent authored May 29, 2021
1 parent f3a5ae1 commit 2379829
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
- Automatically set the "pattern" record mode when you create a new tour, and select `None` for the git ref
- Added support for opening a `*.tour` file in the VS Code notebook editor (Insiders only)

## v0.0.54

- Added a URI handler, with support for launching a specific tour and step

## v0.0.53

- Exposed a new `onDidStartTour` event and `startTourByUri` method to the extension API
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "CodeTour",
"description": "VS Code extension that allows you to record and playback guided tours of codebases, directly within the editor",
"publisher": "vsls-contrib",
"version": "0.0.53",
"version": "0.0.54",
"author": {
"name": "Microsoft Corporation"
},
Expand Down
45 changes: 40 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { URLSearchParams } from "url";
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 { promptForTour, startDefaultTour } from "./store/actions";
import { store } from "./store";
import {
promptForTour,
startCodeTour,
startDefaultTour
} from "./store/actions";
import { discoverTours as _discoverTours } from "./store/provider";

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

class URIHandler implements vscode.UriHandler {

private _didStartDefaultTour = false;
get didStartDefaultTour(): boolean { return this._didStartDefaultTour; }
get didStartDefaultTour(): boolean {
return this._didStartDefaultTour;
}

async handleUri(uri: vscode.Uri): Promise<void> {
if (uri.path === '/startDefaultTour') {
if (uri.path === "/startDefaultTour") {
this._didStartDefaultTour = true;

await discoverTours();
startDefaultTour();

let tourPath: string | null | undefined, stepNumber;
if (uri.query) {
const origin = vscode.Uri.parse(uri.query);
if (origin.query) {
const params = new URLSearchParams(origin.query);
tourPath = params.get("tour");

const step = params.get("step");
if (step) {
stepNumber = Number(step);
}
}
}

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);
}
}

return;
Expand Down
5 changes: 3 additions & 2 deletions src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ export async function promptForTour(

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

if (primaryTour) {
startCodeTour(primaryTour, 0, workspaceRoot, false, undefined, tours);
startCodeTour(primaryTour, step, workspaceRoot, false, undefined, tours);
return true;
} else {
return selectTour(tours, workspaceRoot);
Expand Down

0 comments on commit 2379829

Please sign in to comment.