Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions schema/user-tours.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
},
"type": "object",
"properties": {
"autoLaunchDefaultTours": {
"type": "boolean",
"title": "Auto-Launch Default Tours",
"description": "Whether to automatically launch default tours (Welcome Tour, Notebook Tour) on first use. Tours can still be launched manually from the Help menu.",
"default": true
},
"tours": {
"type": "array",
"description": "An array of a tours. Each requires an `id`, `label` and `steps[]`, and may have `options`, see https://docs.react-joyride.com",
Expand Down
62 changes: 43 additions & 19 deletions src/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,38 +222,62 @@ const defaultsPlugin: JupyterFrontEndPlugin<void> = {
autoStart: true,
activate: activateDefaults,
requires: [ITourManager],
optional: [INotebookTracker]
optional: [ISettingRegistry, INotebookTracker]
};

function activateDefaults(
app: JupyterFrontEnd,
tourManager: ITourManager,
settings?: ISettingRegistry | null,
nbTracker?: INotebookTracker
): void {
addTours(tourManager, app, nbTracker);

if (
nbTracker &&
(app.name !== 'Jupyter Notebook' ||
window.location.pathname.match(/\/notebooks\/.+$/))
) {
nbTracker.widgetAdded.connect(() => {
if (tourManager.tours.has(NOTEBOOK_ID)) {
tourManager.launch([NOTEBOOK_ID], false);
}
});
}

Promise.all([app.restored, tourManager.ready]).then(() => {
const setupTours = () => {
if (
tourManager.tours.has(WELCOME_ID) &&
nbTracker &&
(app.name !== 'Jupyter Notebook' ||
window.location.pathname.match(/\/tree(\/.+)?$/))
window.location.pathname.match(/\/notebooks\/.+$/))
) {
// Wait 3s before launching the first tour - to be sure element are loaded
setTimeout(() => tourManager.launch([WELCOME_ID], false), 3000);
nbTracker.widgetAdded.connect(() => {
if (tourManager.tours.has(NOTEBOOK_ID)) {
tourManager.launch([NOTEBOOK_ID], false);
}
});
}
});

Promise.all([app.restored, tourManager.ready]).then(() => {
if (
tourManager.tours.has(WELCOME_ID) &&
(app.name !== 'Jupyter Notebook' ||
window.location.pathname.match(/\/tree(\/.+)?$/))
) {
// Wait 3s before launching the first tour - to be sure element are loaded
setTimeout(() => tourManager.launch([WELCOME_ID], false), 3000);
}
});
};

// Load settings to check if auto-launch is enabled
if (settings) {
settings
.load(USER_PLUGIN_ID)
.then(userSettings => {
const autoLaunch = userSettings.get('autoLaunchDefaultTours')
.composite as boolean;

if (autoLaunch) {
setupTours();
}
})
.catch(() => {
// If settings fail to load, default to showing tours
setupTours();
});
} else {
// If no settings registry, default to showing tours
setupTours();
}
}

export default [corePlugin, userPlugin, notebookPlugin, defaultsPlugin];
Loading