Quellcode durchsuchen

Add settings schema for extension manager and set default status to disabled.

Afshin Darian vor 6 Jahren
Ursprung
Commit
d7f6d5023d

+ 4 - 1
packages/extensionmanager-extension/package.json

@@ -12,6 +12,7 @@
     "lib/*.d.ts",
     "lib/*.js.map",
     "lib/*.js",
+    "schema/*.json",
     "style/*.css"
   ],
   "main": "lib/index.js",
@@ -31,6 +32,7 @@
   },
   "dependencies": {
     "@jupyterlab/application": "^0.16.2",
+    "@jupyterlab/coreutils": "^1.1.2",
     "@jupyterlab/extensionmanager": "^0.16.0"
   },
   "devDependencies": {
@@ -38,6 +40,7 @@
     "typescript": "~2.9.1"
   },
   "jupyterlab": {
-    "extension": true
+    "extension": true,
+    "schemaDir": "schema"
   }
 }

+ 16 - 0
packages/extensionmanager-extension/schema/plugin.json

@@ -0,0 +1,16 @@
+{
+  "jupyter.lab.setting-icon-class": "jp-SettingsIcon",
+  "jupyter.lab.setting-icon-label": "Extension Manager",
+  "title": "Extension Manager",
+  "description": "Extension manager settings.",
+  "properties": {
+    "enabled": {
+      "title": "Enabled Status",
+      "description": "Whether the extension manager is enabled.",
+      "default": false,
+      "type": "boolean"
+    }
+  },
+  "additionalProperties": false,
+  "type": "object"
+}

+ 25 - 10
packages/extensionmanager-extension/src/index.ts

@@ -2,9 +2,13 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  JupyterLab, JupyterLabPlugin, ILayoutRestorer
+  ILayoutRestorer, IRouter, JupyterLab, JupyterLabPlugin
 } from '@jupyterlab/application';
 
+import {
+  ISettingRegistry
+} from '@jupyterlab/coreutils';
+
 import {
   ExtensionView
 } from '@jupyterlab/extensionmanager';
@@ -13,7 +17,7 @@ import {
 /**
  * The extensionmanager-view namespace token.
  */
-const namespaceToken = 'extensionmanagerview';
+const namespace = 'extensionmanagerview';
 
 /**
  * IDs of the commands added by this extension.
@@ -31,17 +35,28 @@ namespace CommandIDs {
 
 
 /**
- * Initialization data for the extensionmanager extension.
+ * Initialization data for the extensionmanager plugin.
  */
-const extension: JupyterLabPlugin<void> = {
-  id: '@jupyterlab/javascript-extension:plugin',
+const plugin: JupyterLabPlugin<void> = {
+  id: '@jupyterlab/extensionmanager-extension:plugin',
   autoStart: true,
-  requires: [ILayoutRestorer],
-  activate: (app: JupyterLab, restorer: ILayoutRestorer) => {
+  requires: [ILayoutRestorer, ISettingRegistry, IRouter],
+  activate: async (app: JupyterLab, restorer: ILayoutRestorer, registry: ISettingRegistry, router: IRouter) => {
+    const settings = await registry.load(plugin.id);
+    const enabled = settings.composite['enabled'] as boolean;
+
+    // If the extension is enabled or disabled, refresh the page.
+    settings.changed.connect(() => { router.reload(); });
+
+    if (!enabled) {
+      return;
+    }
+
     const { commands, shell, serviceManager} = app;
     const view = new ExtensionView(serviceManager);
+
     view.id = 'extensionmanager.main-view';
-    restorer.add(view, namespaceToken);
+    restorer.add(view, namespace);
     view.title.label = 'Extensions';
     shell.addToLeftArea(view);
 
@@ -49,7 +64,7 @@ const extension: JupyterLabPlugin<void> = {
     // If the layout is a fresh session without saved data, open file view.
     app.restored.then(layout => {
       if (layout.fresh) {
-        commands.execute(CommandIDs.showExtensionManager, void 0);
+        commands.execute(CommandIDs.showExtensionManager, undefined);
       }
     });
 
@@ -91,4 +106,4 @@ function addCommands(app: JupyterLab, view: ExtensionView): void {
 }
 
 
-export default extension;
+export default plugin;