diff --git a/src/index.ts b/src/index.ts index b25c60d..4c9f80d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,13 +2,15 @@ import { JupyterFrontEndPlugin } from '@jupyterlab/application'; import { driveFileBrowser, openDriveDialogPlugin, - launcherPlugin + launcherPlugin, + sessionContextPatch } from './plugins'; const plugins: JupyterFrontEndPlugin[] = [ driveFileBrowser, openDriveDialogPlugin, - launcherPlugin + launcherPlugin, + sessionContextPatch ]; export default plugins; diff --git a/src/plugins/index.ts b/src/plugins/index.ts index c71e029..206e90d 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -1,3 +1,4 @@ export * from './driveBrowserPlugin'; export * from './launcherPlugin'; export * from './driveDialogPlugin'; +export * from './sessionContextPatch'; diff --git a/src/plugins/sessionContextPatch.ts b/src/plugins/sessionContextPatch.ts new file mode 100644 index 0000000..b9f3ad4 --- /dev/null +++ b/src/plugins/sessionContextPatch.ts @@ -0,0 +1,39 @@ +import { + JupyterFrontEndPlugin, + JupyterFrontEnd +} from '@jupyterlab/application'; +import { SessionContext } from '@jupyterlab/apputils'; +import { + IDocumentManager, + IDocumentWidgetOpener +} from '@jupyterlab/docmanager'; + +/** + * A plugin to patch the session context path so it includes the drive name. + * associated with. + */ +export const sessionContextPatch: JupyterFrontEndPlugin = { + id: '@jupyterlite/application-extension:session-context-patch', + autoStart: true, + requires: [IDocumentManager, IDocumentWidgetOpener], + activate: ( + app: JupyterFrontEnd, + docManager: IDocumentManager, + widgetOpener: IDocumentWidgetOpener + ) => { + const contents = app.serviceManager.contents; + + widgetOpener.opened.connect((_, widget) => { + const context = docManager.contextForWidget(widget); + const driveName = contents.driveName(context?.path ?? ''); + if (driveName === '') { + // do nothing if this is the default drive + return; + } + const sessionContext = widget.context.sessionContext as SessionContext; + + // Path the session context to include the drive name + sessionContext['_path'] = context?.path; + }); + } +};