Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed Aug 12, 2020
2 parents 7c7a8e7 + 14a3ad0 commit 0c4c018
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function activate(
},
usage:
'Launch a tour.\nIf no id provided, prompt the user.\nArguments {id: Tour ID}',
isEnabled: () => !manager.activeTutorial,
execute: async args => {
let id = args['id'] as string;
const force =
Expand Down
4 changes: 4 additions & 0 deletions src/tutorial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ export class Tutorial implements ITutorial {
return menuButton;
}

isRunning(): boolean {
return this._currentStepIndex >= 0;
}

removeTutorialFromMenu(menu: Menu): Menu.IItem[] {
if (
!menu ||
Expand Down
20 changes: 13 additions & 7 deletions src/tutorialManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ export class TutorialManager implements ITutorialManager {
}

get activeTutorial(): ITutorial {
console.warn('activeTutorial is deprecated');
return null;
const activeTutorial = this._activeTutorials.filter(tutorial =>
tutorial.isRunning()
);
return activeTutorial[0];
}

/**
Expand Down Expand Up @@ -113,7 +115,7 @@ export class TutorialManager implements ITutorialManager {
tutorials: ITutorial[] | string[],
force = true
): Promise<void> {
if (!tutorials || tutorials.length === 0) {
if (!tutorials || tutorials.length === 0 || this.activeTutorial) {
return Promise.resolve();
}
let tutorialGroup: Array<ITutorial | undefined>;
Expand All @@ -136,18 +138,21 @@ export class TutorialManager implements ITutorialManager {
);
}

const startTours = (): void => {
this._activeTutorials = tutorialList;
this._tutorialLaunched.emit(tutorialList);
};

if (tutorialList.length > 0) {
if (force) {
this._tutorialLaunched.emit(tutorialList);
startTours();
} else {
INotification.info(`Try the ${tutorialList[0].label}.`, {
autoClose: 10000,
buttons: [
{
label: 'Start now',
callback: (): void => {
this._tutorialLaunched.emit(tutorialList);
}
callback: startTours
},
{
label: "Don't show me again",
Expand Down Expand Up @@ -210,6 +215,7 @@ export class TutorialManager implements ITutorialManager {
});
};

private _activeTutorials: Tutorial[] = new Array<Tutorial>();
private _defaultOptions: Partial<TutorialOptions>;
private _menu: MainMenu | undefined;
private _state: IManagerState = {
Expand Down

0 comments on commit 0c4c018

Please sign in to comment.