Skip to content
This repository was archived by the owner on Feb 14, 2024. It is now read-only.

Commit 64c8286

Browse files
authored
Make the service worker optional (#92)
* Make the service worker optional * Linter
1 parent d6f0f45 commit 64c8286

File tree

6 files changed

+802
-1249
lines changed

6 files changed

+802
-1249
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The [xeus-python](https://github.com/jupyter-xeus/xeus-python) Python kernel for
1313

1414
## Requirements
1515

16-
- JupyterLite >= 0.1.0b12
16+
- JupyterLite >= 0.1.0b16
1717

1818
## Install
1919

@@ -31,22 +31,22 @@ jupyter lite build
3131

3232
## Pre-installed packages
3333

34-
xeus-python allows you to pre-install packages in the Python runtime. You can pre-install packages by passing the ``XeusPythonEnv.packages`` CLI option to ``jupyter lite build``.
34+
xeus-python allows you to pre-install packages in the Python runtime. You can pre-install packages by passing the `XeusPythonEnv.packages` CLI option to `jupyter lite build`.
3535
This will automatically install any labextension that it founds, for example installing ipyleaflet will make ipyleaflet work without the need to manually install the jupyter-leaflet labextension.
3636

37-
For example, say you want to install ``NumPy``, ``Matplotlib`` and ``ipyleaflet``, it can be done with the following command:
37+
For example, say you want to install `NumPy`, `Matplotlib` and `ipyleaflet`, it can be done with the following command:
3838

3939
```bash
4040
jupyter lite build --XeusPythonEnv.packages=numpy,matplotlib,ipyleaflet
4141
```
4242

43-
The same can be achieved through a ``jupyterlite_config.json`` file:
43+
The same can be achieved through a `jupyterlite_config.json` file:
4444

4545
```json
4646
{
47-
"XeusPythonEnv": {
48-
"packages": ["numpy", "matplotlib", "ipyleaflet"]
49-
}
47+
"XeusPythonEnv": {
48+
"packages": ["numpy", "matplotlib", "ipyleaflet"]
49+
}
5050
}
5151
```
5252

docs/environment.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ dependencies:
77
- mamba
88
- pydata-sphinx-theme
99
- pip
10-
1110
- pip:
12-
- jupyterlite
11+
- jupyterlite>=0.1.0b16
1312
- jupyterlite-sphinx
1413
- jupyterlite-xeus-python>=0.5.0

docs/jupyter-lite.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"jupyter-lite-schema-version": 0,
3-
"jupyter-config-data": {
4-
"disabledExtensions": [
5-
"@jupyterlite/javascript-kernel-extension",
6-
"@jupyterlite/pyolite-kernel-extension"
7-
]
8-
}
2+
"jupyter-lite-schema-version": 0,
3+
"jupyter-config-data": {
4+
"disabledExtensions": [
5+
"@jupyterlite/javascript-kernel-extension",
6+
"@jupyterlite/pyolite-kernel-extension"
7+
]
8+
}
99
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
"watch:labextension": "jupyter labextension watch ."
5656
},
5757
"dependencies": {
58-
"@jupyterlite/contents": "^0.1.0-beta.12",
59-
"@jupyterlite/server": "^0.1.0-beta.12",
58+
"@jupyterlite/contents": "^0.1.0-beta.16",
59+
"@jupyterlite/server": "^0.1.0-beta.16",
6060
"comlink": "^4.3.1"
6161
},
6262
"devDependencies": {

src/index.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
// Distributed under the terms of the Modified BSD License.
44

55
import {
6-
IServiceWorkerRegistrationWrapper,
6+
IServiceWorkerManager,
77
JupyterLiteServer,
88
JupyterLiteServerPlugin
99
} from '@jupyterlite/server';
10-
10+
import { IBroadcastChannelWrapper } from '@jupyterlite/contents';
1111
import { IKernel, IKernelSpecs } from '@jupyterlite/kernel';
1212

1313
import { WebWorkerKernel } from './web_worker_kernel';
@@ -18,11 +18,13 @@ import logo64 from '!!file-loader?context=.!../style/logos/python-logo-64x64.png
1818
const server_kernel: JupyterLiteServerPlugin<void> = {
1919
id: '@jupyterlite/xeus-python-kernel-extension:kernel',
2020
autoStart: true,
21-
requires: [IKernelSpecs, IServiceWorkerRegistrationWrapper],
21+
requires: [IKernelSpecs],
22+
optional: [IServiceWorkerManager, IBroadcastChannelWrapper],
2223
activate: (
2324
app: JupyterLiteServer,
2425
kernelspecs: IKernelSpecs,
25-
serviceWorkerRegistrationWrapper: IServiceWorkerRegistrationWrapper
26+
serviceWorker?: IServiceWorkerManager,
27+
broadcastChannel?: IBroadcastChannelWrapper
2628
) => {
2729
kernelspecs.register({
2830
spec: {
@@ -36,9 +38,23 @@ const server_kernel: JupyterLiteServerPlugin<void> = {
3638
}
3739
},
3840
create: async (options: IKernel.IOptions): Promise<IKernel> => {
41+
const mountDrive = !!(
42+
serviceWorker?.enabled && broadcastChannel?.enabled
43+
);
44+
45+
if (mountDrive) {
46+
console.info(
47+
'xeus-python contents will be synced with Jupyter Contents'
48+
);
49+
} else {
50+
console.warn(
51+
'xeus-python contents will NOT be synced with Jupyter Contents'
52+
);
53+
}
54+
3955
return new WebWorkerKernel({
4056
...options,
41-
mountDrive: serviceWorkerRegistrationWrapper.enabled
57+
mountDrive
4258
});
4359
}
4460
});

0 commit comments

Comments
 (0)