index.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. /**
  4. * @packageDocumentation
  5. * @module running-extension
  6. */
  7. import {
  8. ILabShell,
  9. ILayoutRestorer,
  10. JupyterFrontEnd,
  11. JupyterFrontEndPlugin
  12. } from '@jupyterlab/application';
  13. import {
  14. IRunningSessionManagers,
  15. RunningSessionManagers,
  16. RunningSessions
  17. } from '@jupyterlab/running';
  18. import { ITranslator } from '@jupyterlab/translation';
  19. import { runningIcon } from '@jupyterlab/ui-components';
  20. import { addKernelRunningSessionManager } from './kernels';
  21. import { addOpenTabsSessionManager } from './opentabs';
  22. /**
  23. * The default running sessions extension.
  24. */
  25. const plugin: JupyterFrontEndPlugin<IRunningSessionManagers> = {
  26. activate,
  27. id: '@jupyterlab/running-extension:plugin',
  28. provides: IRunningSessionManagers,
  29. requires: [ITranslator],
  30. optional: [ILayoutRestorer, ILabShell],
  31. autoStart: true
  32. };
  33. /**
  34. * Export the plugin as default.
  35. */
  36. export default plugin;
  37. /**
  38. * Activate the running plugin.
  39. */
  40. function activate(
  41. app: JupyterFrontEnd,
  42. translator: ITranslator,
  43. restorer: ILayoutRestorer | null,
  44. labShell: ILabShell | null
  45. ): IRunningSessionManagers {
  46. const trans = translator.load('jupyterlab');
  47. const runningSessionManagers = new RunningSessionManagers();
  48. const running = new RunningSessions(runningSessionManagers, translator);
  49. running.id = 'jp-running-sessions';
  50. running.title.caption = trans.__('Running Terminals and Kernels');
  51. running.title.icon = runningIcon;
  52. running.node.setAttribute('role', 'region');
  53. running.node.setAttribute('aria-label', trans.__('Running Sessions section'));
  54. // Let the application restorer track the running panel for restoration of
  55. // application state (e.g. setting the running panel as the current side bar
  56. // widget).
  57. if (restorer) {
  58. restorer.add(running, 'running-sessions');
  59. }
  60. if (labShell) {
  61. addOpenTabsSessionManager(runningSessionManagers, translator, labShell);
  62. }
  63. addKernelRunningSessionManager(runningSessionManagers, translator, app);
  64. // Rank has been chosen somewhat arbitrarily to give priority to the running
  65. // sessions widget in the sidebar.
  66. app.shell.add(running, 'left', { rank: 200 });
  67. return runningSessionManagers;
  68. }