settingsplugin.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*-----------------------------------------------------------------------------
  2. | Copyright (c) Jupyter Development Team.
  3. | Distributed under the terms of the Modified BSD License.
  4. |----------------------------------------------------------------------------*/
  5. import {
  6. JupyterFrontEnd,
  7. JupyterFrontEndPlugin
  8. } from '@jupyterlab/application';
  9. import { PageConfig } from '@jupyterlab/coreutils';
  10. import { SettingRegistry, ISettingRegistry } from '@jupyterlab/settingregistry';
  11. import { SettingConnector } from './settingconnector';
  12. /**
  13. * The default setting registry provider.
  14. */
  15. export const settingsPlugin: JupyterFrontEndPlugin<ISettingRegistry> = {
  16. id: '@jupyterlab/apputils-extension:settings',
  17. activate: async (app: JupyterFrontEnd): Promise<ISettingRegistry> => {
  18. const { isDisabled } = PageConfig.Extension;
  19. const connector = new SettingConnector(app.serviceManager.settings);
  20. const registry = new SettingRegistry({
  21. connector,
  22. plugins: (await connector.list('active')).values
  23. });
  24. // If there are plugins that have schemas that are not in the setting
  25. // registry after the application has restored, try to load them manually
  26. // because otherwise, its settings will never become available in the
  27. // setting registry.
  28. void app.restored.then(async () => {
  29. const plugins = await connector.list('all');
  30. plugins.ids.forEach(async (id, index) => {
  31. if (isDisabled(id) || id in registry.plugins) {
  32. return;
  33. }
  34. try {
  35. await registry.load(id);
  36. } catch (error) {
  37. console.warn(`Settings failed to load for (${id})`, error);
  38. if (plugins.values[index].schema['jupyter.lab.transform']) {
  39. console.warn(
  40. `This may happen if {autoStart: false} in (${id}) ` +
  41. `or if it is one of the deferredExtensions in page config.`
  42. );
  43. }
  44. }
  45. });
  46. });
  47. return registry;
  48. },
  49. autoStart: true,
  50. provides: ISettingRegistry
  51. };