From 7056781c9f5ba742441aa97d2c4016303c303e26 Mon Sep 17 00:00:00 2001
From: Wei Ouyang <oeway007@gmail.com>
Date: Wed, 29 Nov 2023 14:53:31 +0100
Subject: [PATCH] Small fix

---
 README.md                              |  2 +-
 imjoy_jupyterlab_extension/__init__.py | 16 ----------------
 lib/index.js                           | 26 +++++++++++++++++++++++---
 publish.sh                             |  4 +---
 4 files changed, 25 insertions(+), 23 deletions(-)
 delete mode 100644 imjoy_jupyterlab_extension/__init__.py

diff --git a/README.md b/README.md
index 9cb473c..2f24bbd 100644
--- a/README.md
+++ b/README.md
@@ -59,7 +59,7 @@ By default, the `jlpm build` command generates the source maps for this extensio
 ```bash
 nvm use 16
 npm i -d @types/node # required to solve https://github.com/microsoft/TypeScript/issues/51567
-jupyter lab build --minimize=False
+jupyter lab build
 ```
 
 ### Development uninstall
diff --git a/imjoy_jupyterlab_extension/__init__.py b/imjoy_jupyterlab_extension/__init__.py
deleted file mode 100644
index 53dfc96..0000000
--- a/imjoy_jupyterlab_extension/__init__.py
+++ /dev/null
@@ -1,16 +0,0 @@
-try:
-    from ._version import __version__
-except ImportError:
-    # Fallback when using the package in dev mode without installing
-    # in editable mode with pip. It is highly recommended to install
-    # the package from a stable release or in editable mode: https://pip.pypa.io/en/stable/topics/local-project-installs/#editable-installs
-    import warnings
-    warnings.warn("Importing 'imjoy_jupyterlab_extension' outside a proper installation.")
-    __version__ = "dev"
-
-
-def _jupyter_labextension_paths():
-    return [{
-        "src": "labextension",
-        "dest": "imjoy-jupyterlab-extension"
-    }]
diff --git a/lib/index.js b/lib/index.js
index ca8228f..a6811b7 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,12 +1,32 @@
+import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
+import { ITranslator } from '@jupyterlab/translation';
+import { ImjoyExtension, parseURL } from './imjoy-extension.js';
 /**
  * Initialization data for the imjoy-jupyterlab-extension extension.
  */
 const plugin = {
-    id: 'imjoy-jupyterlab-extension:plugin',
-    description: 'Run ImJoy plugins in JupyterLab',
+    id: 'imjoy-jupyterlab-extension',
+    requires: [IFileBrowserFactory, ITranslator],
     autoStart: true,
-    activate: (app) => {
+    activate: async function (app, factory, translator) {
+        const trans = translator.load('jupyterlab');
+        // const { defaultBrowser: browser } = factory;
+        // Manually restore and load the default file browser.
+        const browser = factory.createFileBrowser('filebrowser', {
+            auto: false,
+            restore: false
+        });
+        const jupyterBaseUrl = app.serviceManager.settings.serverSettings.baseUrl;
+        app.docRegistry.addWidgetExtension('Notebook', new ImjoyExtension(jupyterBaseUrl, app, browser));
         console.log('JupyterLab extension imjoy-jupyterlab-extension is activated!');
+        const currentLocation = new URL(window.location.href);
+        app.started.then(() => {
+            parseURL(currentLocation.search, app, browser, trans).finally(() => {
+                // restore location, since jupyterlab will force double slashes into single
+                window.history.pushState(null, '', currentLocation.href);
+            });
+        });
     }
 };
 export default plugin;
+//# sourceMappingURL=index.js.map
\ No newline at end of file
diff --git a/publish.sh b/publish.sh
index deff204..9394bb6 100644
--- a/publish.sh
+++ b/publish.sh
@@ -1,6 +1,4 @@
-pip install -U twine
-pip install -U wheel
-python3 -m pip install --upgrade build
+pip install -U build twine hatch
 rm -rf ./build
 rm ./dist/*
 python3 -m build