Skip to content

Commit

Permalink
Isolate the core of Imjoy into a stand-alone library (#211)
Browse files Browse the repository at this point in the history
* wrap imjoy as a library

* use minibus instead of Vue

* add window manager

* add deployment script for imjoy-lib

* export joy

* support url

* merge build-lib and build-libdev

* update deploy script

* Enable allow-same-origin from lib.imjoy.io

* support pwa for imjoy-lib.html

* fix format

* fix branch name

* add plugin service worker

* add dist to git ignore

* merge build command

* cache plugin requirements

* move api from imjoy.vue to pluginManager

* add plugin menu to imjoy-lib

* fix lib.imjoy url

* bump version

* fix requirements typo

* move requirements caching to iframe

* fix plugin sw

* fix scope

* support offline using service worker

* fix lib.imjoy.io strategy

* support file cache

* activate service worker immediately

* fix log

* Remove log

* add imjoy lite

* improve lite page

* set welcome plugin as default

* load welcome plugin if no plugin installed

* add docs for offline cache

* clean up allow-same-origin

* fix allow-same-origin

* set default plugin for imjoy-lite

* control permissions

* add permissions to docs

* use minified imjoy-lib in lite.html
  • Loading branch information
oeway authored Jul 26, 2019
1 parent 9610964 commit df5563b
Show file tree
Hide file tree
Showing 43 changed files with 2,005 additions and 1,064 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules
docs/.DS_Store
__websocket_relay__.js
./package-lock.json
dist/*

# local env files
.env.local
Expand Down
92 changes: 0 additions & 92 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -704,31 +704,6 @@ sigma = await api.getConfig('sigma')
```
[Try yourself in the setConfig example >>](https://imjoy.io/#/app?plugin=oeway/ImJoy-Demo-Plugins:setConfig&w=examples)

### api.getFilePath
```javascript
file_path = await api.getFilePath(config)
```

Converts an url generated by `api.getFileUrl` into an absolute file path on the file system.

**Arguments**
* **config**. Object (JavaScript) or dictionary (Python). Options for getting file path from an URL.
It contains the following fields:

- **url**: String. Specifies the url to be converted.
- **engine**: String. the url of the plugin engine.

**Returns**
* **file_path**: String. Absolute file path.

**Examples**

Obtain file path from URL

```javascript
url = await api.getFileUrl({'url': 'http://127.0.0.1:9527/file/1ba89354-ae98-457c-a53b-39a4bdd14941/output.png', 'engine': 'http://127.0.0.1:9527'})
```

### api.getFileUrl
```python
file_url = await api.getFileUrl(config)
Expand Down Expand Up @@ -973,73 +948,6 @@ Obtain url with default settings. It will return something like `http://127.0.0.
const url = await api.requestUploadUrl({'path': 'data/output.png', 'engine': 'http://127.0.0.1:9527'})
```


### api.uploadFileToUrl
```python
fileInfo = await api.uploadFileToUrl(config)
```

Upload a file to a upload url.

**Arguments**
* **config**. Object (JavaScript) or dictionary (Python).
It contains the following fields:
- **url** : String. The upload url to be uploaded (get from `api.requestUploadUrl`).
- **method** (optional): String. The request method, default value: 'POST'.

**Returns**
* **fileInfo**. Object (JavaScript) or dictionary (Python). Information about the uploaded file.
It contains the following fields:
- **path** : the path to where the file was saved
- **size** : the size (bytes) of the uploaded file

**Examples**

```javascript

const url = await api.requestUploadUrl({engine: 'http://127.0.0.1:9527', overwrite: true})

const imageFile = document.getElementById('file').files[0]

const fileInfo = await api.uploadFileToUrl({file:imageFile, url: url})

console.log(fileInfo.path)
```

### api.downloadFileFromUrl
```python
file = await api.downloadFileFromUrl(config)
```

Upload a file to a upload url.

**Arguments**
* **config**. Object (JavaScript) or dictionary (Python).
It contains the following fields:
- **url** : String. The url to the remote file (get from `api.getFileUrl`).
- **method** (optional): String. The request method, default value: 'GET'.
- **responseType** (optional): String. The default response type, default value: 'blob'.

**Returns**
* **fileInfo**. Object (JavaScript) or dictionary (Python). The downloaded file.

**Examples**

Download a file on the plugin engine
```javascript

const path = '/path/to/the/file'
const url = await api.getFileUrl({engine: 'http://127.0.0.1:9527', path: path })

const file = await api.downloadFileFromUrl({url: url})
```

You can also use it to download files from other website
```javascript
const url = 'https://raw.githubusercontent.com/oeway/ImJoy/master/README.md'
const file = await api.downloadFileFromUrl({url: url})
```

### api.run
```javascript
await api.run(plugin_name)
Expand Down
Binary file modified docs/assets/imjoy-data-accessibility.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 25 additions & 2 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ Defines the general properties of a plugin with several fields.
"inputs": null,
"outputs": null,
"env": null,
"requirements": null,
"permissions": [],
"requirements": [],
"dependencies": []
}
```
Expand Down Expand Up @@ -374,6 +375,22 @@ used to create an environment to run the plugin.

For more details see the dedicated [section](development?id=virtual-environments)

#### permissions
For `window` plugins, the following permissions can be decleared:
* same-origin
* camera
* midi
* geolocation
* microphone
* encrypted-media
* full-screen
* payment-request

For example, if your window plugin requires webcam access, add the following permission:
```
"permissions": ["camera"],
```

#### requirements
Defines the plugin requirements.

Expand Down Expand Up @@ -495,6 +512,12 @@ If the url does not end with `.js`, you need to add `js:` before it, for example
"requirements": ["js:https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]"]
```

For offline access, Javascript and CSS files will be automatically cached if added to `requirements`,
if you want add additional files to the offline cache, please use the `cache:` prefix. For example:
```json
"requirements": ["cache:https://use.fontawesome.com/releases/v5.8.2/webfonts/fa-solid-900.woff2"]
```

### Web Python
Requirements are specified as a list of strings specifying the required python modules. For instance,

Expand Down Expand Up @@ -807,7 +830,7 @@ Therefore, we provide several different ways to handle loading/saving files for
with or without the plugin engine.

* If the **Plugin Engine** is running, there are three api functions for **all** types of
plugins to access the local file system: `api.showFileDialog`, `api.getFileUrl`, `api.getFilePath`.
plugins to access the local file system: `api.showFileDialog`, `api.getFileUrl`, `api.requestUploadUrl`.
Specifically for **Python plugins** running on the plugin engine, files can be directly
loaded and written to the file system with standard python file operations.

Expand Down
Binary file removed utils/imjoy_lib_id_rsa.enc
Binary file not shown.
7 changes: 4 additions & 3 deletions utils/scripts/deploy-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ cd imjoy-lib
# Create a new empty branch if gh-pages doesn't exist yet (should only happen on first deploy).
git checkout ${LIB_TARGET_BRANCH} || { git checkout --orphan ${LIB_TARGET_BRANCH}; git rm -rf .; }

# Clean up
rm -rf ./*
# Remove all existing files
ls -A1 | xargs rm -rf

# Copy dirs and files and that we want to update.
cp -Rf ../web/dist/* ./
rm -rf ./static/*
rm -rf ./docs
rm -rf CNAME
rm -rf index.html
rm -rf service-worker.js
cp -Rf ../web/dist/static/icons ./static/icons
cp -Rf ../web/dist/static/iconfont ./static/iconfont
cp -Rf ../web/dist/static/jailed ./static/jailed
Expand All @@ -50,7 +51,7 @@ echo "lib.imjoy.io" > CNAME
# Commit the "changes", i.e. the new version.
# The delta will show diffs between new and old versions.
git add -A .
git diff-index --quiet HEAD || git commit -m "Deploy to GitHub Pages ${LIB_TARGET_BRANCH} branch: ${SHA}"
git diff-index --quiet HEAD || git commit -m "Deployed from oeway/ImJoy@${SHA}"

# Now that we're all set up, we can push.
git push $LIB_SSH_REPO ${LIB_TARGET_BRANCH}
2 changes: 1 addition & 1 deletion utils/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ git config user.name "Travis CI"
git config user.email "[email protected]"

# Remove all existing files
rm -rf ./*
ls -A1 | xargs rm -rf

# Copy dirs and files and that we want to update.
cp -Rf ../web/dist/* ./
Expand Down
Loading

0 comments on commit df5563b

Please sign in to comment.