index.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import {
  4. utils
  5. } from '@jupyterlab/services';
  6. import {
  7. Application
  8. } from 'phosphor/lib/ui/application';
  9. import {
  10. ModuleLoader
  11. } from './loader';
  12. import {
  13. ApplicationShell
  14. } from './shell';
  15. export { ModuleLoader } from './loader';
  16. /**
  17. * The type for all JupyterLab plugins.
  18. */
  19. export
  20. type JupyterLabPlugin<T> = Application.IPlugin<JupyterLab, T>;
  21. /**
  22. * JupyterLab is the main application class. It is instantiated once and shared.
  23. */
  24. export
  25. class JupyterLab extends Application<ApplicationShell> {
  26. /**
  27. * Construct a new JupyterLab object.
  28. */
  29. constructor(options: JupyterLab.IOptions = {}) {
  30. super();
  31. this._info = {
  32. version: options.version || 'unknown',
  33. gitDescription: options.gitDescription || 'unknown'
  34. };
  35. this._loader = options.loader || null;
  36. }
  37. /**
  38. * A promise that resolves when the JupyterLab application is started.
  39. */
  40. get started(): Promise<void> {
  41. return this._startedDelegate.promise;
  42. }
  43. /**
  44. * The information about the application.
  45. */
  46. get info(): JupyterLab.IInfo {
  47. return this._info;
  48. }
  49. /**
  50. * The module loader used by the application.
  51. */
  52. get loader(): ModuleLoader | null {
  53. return this._loader;
  54. }
  55. /**
  56. * Start the JupyterLab application.
  57. */
  58. start(options: Application.IStartOptions = {}): Promise<void> {
  59. if (this._startedFlag) {
  60. return Promise.resolve(void 0);
  61. }
  62. this._startedFlag = true;
  63. return super.start(options).then(() => {
  64. this._startedDelegate.resolve(void 0);
  65. });
  66. }
  67. /**
  68. * Create the application shell for the JupyterLab application.
  69. */
  70. protected createShell(): ApplicationShell {
  71. return new ApplicationShell();
  72. }
  73. private _startedDelegate = new utils.PromiseDelegate<void>();
  74. private _startedFlag = false;
  75. private _info: JupyterLab.IInfo;
  76. private _loader: ModuleLoader | null;
  77. }
  78. /**
  79. * The namespace for `JupyterLab` class statics.
  80. */
  81. export
  82. namespace JupyterLab {
  83. /**
  84. * The options used to initialize a JupyterLab object.
  85. */
  86. export
  87. interface IOptions {
  88. /**
  89. * The version of the JupyterLab application.
  90. */
  91. version?: string;
  92. /**
  93. * The git description of the JupyterLab application.
  94. */
  95. gitDescription?: string;
  96. /**
  97. * The module loader used by the application.
  98. */
  99. loader?: ModuleLoader;
  100. }
  101. /**
  102. * The information about a JupyterLab application.
  103. */
  104. export
  105. interface IInfo {
  106. /**
  107. * The version of the JupyterLab application.
  108. */
  109. readonly version: string;
  110. /**
  111. * The git description of the JupyterLab application.
  112. */
  113. readonly gitDescription: string;
  114. }
  115. }