From 14a3ad0d39d7e6f84aa81db9f89dd0ff3ee5bfe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Collonval?= Date: Wed, 12 Aug 2020 20:48:35 +0200 Subject: [PATCH] Sequential tours (#6) * Forbid launching tutorial simultaneously * Disable launch command if a tour is active --- src/index.tsx | 1 + src/tutorial.ts | 4 ++++ src/tutorialManager.ts | 20 +++++++++++++------- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 638aed5..8e5489e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -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 = diff --git a/src/tutorial.ts b/src/tutorial.ts index 9563c66..eeb96ee 100644 --- a/src/tutorial.ts +++ b/src/tutorial.ts @@ -113,6 +113,10 @@ export class Tutorial implements ITutorial { return menuButton; } + isRunning(): boolean { + return this._currentStepIndex >= 0; + } + removeTutorialFromMenu(menu: Menu): Menu.IItem[] { if ( !menu || diff --git a/src/tutorialManager.ts b/src/tutorialManager.ts index fce9f59..695dfff 100644 --- a/src/tutorialManager.ts +++ b/src/tutorialManager.ts @@ -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]; } /** @@ -113,7 +115,7 @@ export class TutorialManager implements ITutorialManager { tutorials: ITutorial[] | string[], force = true ): Promise { - if (!tutorials || tutorials.length === 0) { + if (!tutorials || tutorials.length === 0 || this.activeTutorial) { return Promise.resolve(); } let tutorialGroup: Array; @@ -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", @@ -210,6 +215,7 @@ export class TutorialManager implements ITutorialManager { }); }; + private _activeTutorials: Tutorial[] = new Array(); private _defaultOptions: Partial; private _menu: MainMenu | undefined; private _state: IManagerState = {