| title | Plugin Development Guide |
|---|---|
| parent | Development |
| nav_order | 5 |
This guide is for plugin authors. For installation and everyday use, see the Plugins user guide.
CrossInk can load plugin interfaces in its web portal and browse declarative
plugin catalogs on the reader. JavaScript runs in the connected browser;
device.json describes requests and lists that the firmware understands.
No JavaScript engine runs on the reader.
This integration supports browser interfaces and action jobs, JSON/XML catalogs, authentication, book downloads, bundle installation, catalog details, firmware events, and protected EPUB books with device-wrapped AES-128 or AES-256 keys.
| Plugin part | Runs in | Use it for |
|---|---|---|
plugin.js |
The phone/computer browser hosting CrossInk's web page | Interactive setup, account linking, custom controls, and browser action jobs |
device.json with browse |
The reader's built-in catalog screens | Browsing/searching a service and downloading books or plugin bundles |
device.json with events |
The reader's event delivery system | Sending reading activity or fetching content in response to supported events |
manifest.json |
Read by the plugin host and distribution tools | Name, title, browser placement, version, and packaging metadata |
A plugin can combine these parts. Arbitrary JavaScript does not run on the reader, and a browser job requires an open browser host. Device events use the fixed request/download vocabulary described below.
No firmware rebuild is required to try a plugin on a reader that supports plugins.
Create /plugins/hello-reader/ on the SD card with these two files.
manifest.json:
{
"name": "hello-reader",
"title": "Hello Reader",
"description": "A small browser plugin example",
"author": "Your name",
"version": "1.0.0",
"mount": "settings",
"files": ["manifest.json", "plugin.js"]
}plugin.js:
CrossPoint.registerPlugin((container, api) => {
const heading = document.createElement('h2');
heading.textContent = 'Hello Reader';
const button = document.createElement('button');
button.textContent = 'Check connection';
const message = document.createElement('p');
container.append(heading, button, message);
button.addEventListener('click', async () => {
button.disabled = true;
try {
const response = await fetch('/api/status');
if (!response.ok) throw new Error('Reader is unavailable');
await response.json();
message.textContent = `Connected to ${api.name}`;
} catch (error) {
message.textContent = error.message || 'Connection failed';
} finally {
button.disabled = false;
}
});
});Enable Settings > System > Plugins, start File Transfer > Join a Network,
and open the displayed address in a browser on that network. Open Settings
and choose Check connection in the new card. Reload after editing the files.
Use mount: "files" to put the card on File Manager instead.
Use textContent for remote text; do not insert untrusted service responses as
HTML. Keep secrets out of published files. Plugin scripts share the web portal's
origin and privileges, so they are not isolated from other portal functionality.
The device catalog example below expects a service
returning a books array. A matching response could be:
{
"books": [
{
"id": "sample-book",
"title": "Sample Book",
"author": "Example Author",
"url": "https://library.example/books/sample-book/file"
}
]
}Replace the example URLs with your own service. For a public catalog, omit
token and the Authorization headers. Add device.json to the plugin folder
and to manifest.json's files list when packaging it. Open Home > Plugins
and select it to test the reader flow. plugin.js is optional for a catalog
that does not need browser setup.
For services needing credentials, implement the sign-in contract. Keep local account files separate from packaged defaults, and store downloaded books outside the plugin folder so uninstalling it does not delete them.
CrossInk uses the CrossPoint plugin ecosystem. Its catalog requests identify
as crosspoint, API 1, with the capabilities listed under
Dynamic catalogs and compatibility.
Do not assume newer upstream theme or wallpaper capabilities exist here.
For automatic Hub discovery:
- Use a public GitHub repository with one direct-child payload folder named
hello-reader.crosspoint-plugin/. Its stem must match the manifestname. - Include
manifest.jsonandplugin.js,device.json, or both. List runtime assets infiles; keep tests and build tools outside the payload. - Add the
crosspoint-plugintopic and publish a stable GitHub Release matching the manifest'sMAJOR.MINOR.PATCHversion (an optionalvtag prefix is allowed). - Check the Hub after its catalog refresh. Discovery is not a security review.
Read the upstream Plugin Hub publishing contract for eligibility, compatibility metadata, validation, and exceptional layouts. These distribution rules are separate from local SD-card installation.
For manual testing, copy the payload's contents into /plugins/hello-reader/.
Enable Settings → System → Plugins, then open Home → Plugins. Clean installations start disabled. Upgrading with existing plugin folders enables plugins automatically; disabling leaves their files intact.
The optional Plugin Hub entry offers Download, Hide, and Cancel. Download installs the current Hub using the same recoverable bundle transaction as other plugin installs. Hide removes only this entry; enabling Plugins again restores it. Sideloaded plugins do not require the Hub. Manual downloads are available from Plugin Hub releases.
Copy a plugin folder onto the SD card under one of these roots, in priority order:
/.crosspoint/plugins/<name>/plugins/<name>/.plugins/<name>
An earlier root wins when folders have the same name. Use simple folder names
such as my-library; names cannot contain separators, parent references, FAT
short aliases, or leading/trailing spaces. Folder names are limited to 80 bytes.
The picker discovers up to 16 plugins while inspecting at most 128 entries.
A browser plugin contains plugin.js. Optional manifest.json supplies its
title and mount (settings by default, or files). Open Home → File Transfer
on the reader, join a network, and visit the reader's web portal from a browser.
The plugin appears on the matching Settings or Files page.
A device catalog contains device.json. Open Plugins on Home in any theme
(shown whenever Plugins is enabled) to select it. OPDS Browser is available under Home → File Transfer. Browser-only
and background-only manifests can appear in this list, but do not open a device
catalog. Read their setup instructions in the browser or on your computer.
Install plugins you trust: their browser scripts run with the web portal's permissions. Plugin file operations cannot access CrossInk's Wi-Fi, OPDS, or KOReader credential stores, including backups and legacy Wi-Fi credentials. Showing hidden files does not expose those stores. Other plugin tokens and configuration are ordinary files on the SD card.
Register a renderer in plugin.js:
CrossPoint.registerPlugin(async (container, api) => {
const title = document.createElement('h2');
title.textContent = 'My library';
container.append(title);
// api.name and api.dir identify this installation.
});| API | Purpose |
|---|---|
api.relay(method, url, headers, body) |
Request HTTP(S) through the device; returns {status, headers, body}. |
api.fetchToSd(url, dest, headers) |
Download to SD in resumable segments, publishing only a complete file. |
api.writeFile(path, base64) |
Write a binary or text file through multipart upload. |
api.crypto(op, fields) |
Call a supported cryptographic operation; see the endpoint reference. |
api.pluginFile(filename) |
URL for a file in this plugin's folder. |
api.registerAction(name, fn) |
Register a browser action callable through the job queue. |
Relay bodies are limited to 32 KiB; larger downloads use fetchToSd. File uploads
are limited to 256 KiB. Plugin requests reject HTTP framing headers and control
characters. Credentials are not forwarded to another origin on redirects or
through remote catalog links. Network requests use the existing SecureNet TLS
configuration; no new certificate trust policy is introduced by this feature.
Replacing a book clears its cached content. Reading preferences and progress continue to use CrossInk's existing stores. Existing file-manager rename and move operations keep their reader-state migration behavior.
{
"title": "My library",
"description": "Download books",
"config": { "file": "config.json" },
"token": { "file": "token.json", "path": "access_token" },
"browse": {
"url": "https://library.example/books?page={page}&limit={limit}",
"headers": { "Authorization": "Bearer {token}" },
"items": "books",
"fields": { "title": "title", "author": "author", "id": "id", "url": "url" },
"page_size": 8
},
"download": {
"url": "https://library.example/books/{id}/file",
"headers": { "Authorization": "Bearer {token}" },
"dest_dir": "/Books",
"filename": "{title}.epub"
}
}Omit token for a public catalog. Token and configuration filenames relative to
the manifest live inside the plugin folder. Absolute paths must pass the same
credential protection as browser file operations.
Field selectors use dotted JSON paths, including array indexes such as
authors.0.name. browse.items is empty for a root array. Requests support
method, headers, and body. Templates support {token}, {cfg.KEY}, {page},
{offset}, {limit}, {query} (URL encoded), and {query_raw}. Download and
item-details templates also support {id}, {title}, {author}, and {url}.
The _enc forms ({id_enc}, {title_enc}, {author_enc}, {url_enc}) encode
those values for a URL query value or path segment. This is advertised as
catalog.encoded_item_fields; existing raw forms remain unchanged.
Outgoing plugin URLs escape spaces, control bytes, and non-ASCII bytes, while
preserving URL separators and existing percent escapes. Use _enc when a field
contains separators such as &, ?, #, or / that belong to the value itself.
Request-size, header, and destination protections still apply.
JSON pagination is selected from the URL, body, and header templates:
{page}with{limit}: limit equalspage_size; a full page enables Next. An exactly full final page can lead to one empty page.{offset}: offset equals(page - 1) * page_size, and limit equalspage_size + 1for lookahead. Offset takes precedence over page.{page}without{limit}: each page needs an extra row to advertise Next.- Neither: the firmware pages through the static response locally, counting compatible entries rather than letting incompatible entries consume slots.
Optional browse.lists contains named {title, url, body} views.
browse.search overrides url and/or body for search. A download.url_path
selects a URL from an API response; credentials used for that API request are
not sent to the returned file URL. download.username and download.password
provide Basic authentication for a direct file request. If a feed item supplies
the lookup server, its origin must match the installed manifest's browse URL. A
manifest can also configure a separate, fixed lookup server.
For XML catalogs set browse.format to xml, browse.item to the repeated
element's local name, and field selectors to an element, element@attribute,
or @attribute. Optional container_element, skip_self, resolve_urls, and
extensions support directory listings. Directory links must keep the manifest's
origin, including HTTPS and port.
A flat config file can override the destination with {"dest_dir":"/Books"}.
/ selects the SD root. Filenames retain CrossInk's normal sanitation.
Plugins can save their token through the browser interface, or declare an auth
object. type: "password" uses request and token_path to mint a token from
configuration values. type: "device_code" uses request to obtain a code and
verification URL, then poll to await authorization. Response selectors include
code_path, verify_url_path, device_code_path, interval_path, expires_path,
token_path, and error_path. The reader shows the code and QR during sign-in.
Expired password tokens receive one refresh attempt. Failed token writes retain
the previous token.
A download may declare bundle: {"base":"base", "files":"files", "subdir":"{id}"}.
The named item fields supply a base URL and array of relative file paths. The
subdirectory must be one valid folder name. A bundle can contain up to 64 files.
Updates are assembled in a hidden sibling folder, preserving existing local configuration. After all files arrive, a journal records the folder swap. Boot recovery retains either the prior installation or the completed replacement. Copying the prior folder is limited to 128 entries and eight nested levels. Keep downloaded books outside the plugin installation folder.
Manifests are limited to 8 KiB; picker titles and descriptions accept at most 128 and 256 bytes respectively. Oversized picker fields use the folder name or no description. Token and configuration files are limited to 2 KiB. JSON pages contain at most 16 visible rows; XML lists use the SDK's 200-row limit. A list requires enough free heap for its row array plus 64 KiB of parser and UI headroom; otherwise it shows a memory error. Captured row text is limited to 24 KiB per response. Catalog responses stream through an SD temporary file and are limited to 1 MiB; oversized or malformed responses show a feed error. HTTP response headers are limited to 64 fields and 8 KiB. These bounds keep catalog input from growing memory without limit on button devices without PSRAM.
An external client may POST {plugin, action, args} to /api/plugin-jobs, then
poll /api/plugin-jobs/status?id=<id>. Jobs run only while a browser hosts the
plugin on Files, Settings, or /plugins-run. The device has six job slots.
Running claims have leases; a lost browser may cause an action to run again, so
actions should tolerate retries. Jobs are not persisted across firmware restart.
browse.lists_url can return an object containing a lists array with title, url, and optional body. List URLs must use the browse URL's scheme, host, and port. Put credentials in the installed manifest. Remote list URL and body templates can use pagination placeholders and must omit {token} and {cfg.*}. The response is limited to 16 KiB and the first 16 usable lists. Each list can include a notice with title, message, confirm, and cancel; the notice must be accepted before browsing.
Catalog requests support {firmware_family}, {firmware_version}, {plugin_api}, and {plugin_capabilities}. This integration advertises the crosspoint catalog family, the CrossInk version, API 1, and catalog.lists, catalog.notices, catalog.bundle_install, catalog.version_tracking, and catalog.compatibility. It also advertises catalog.item_details: catalogs may map description, detail_author, repository, details_url, and details_format in browse.fields. Version-tracked catalogs default to description, author, repository, and details.url/details.format. Text or HTML details are limited to 8 KiB; HTML is displayed as readable text with paragraph breaks. Details page before downloading, and Back cancels without downloading. Only the current page is wrapped in memory.
browse.compatibility can map firmware_family, plugin_api_min, and requires to JSON row fields. Missing restrictions allow a row; supplied family/API/capability restrictions must match. Filtering keeps the server's original pagination lookahead. Completed book downloads through catalogs or browser plugin APIs mark the Library for refresh. Bundles updating an existing plugin reuse its original root and preserve its configuration.
A plugin's device.json can subscribe through an events object to reader.open,
reader.exit, reader.session, book.downloaded, and sleep.enter. The Plugins
list displays the subscribed events. Disabling Plugins stops collection and delivery.
Handlers use request or download objects with {event.*}, {cfg.*}, {meta.*},
and {token} substitutions. Downloads use the same protected-path checks as catalog downloads.
Events are queued in each plugin's events.jsonl (4 KiB plus one bounded line).
Ordinary delivery is ordered and at least once: services should deduplicate {event.id}.
Failed requests retain the queue; successful delivery publishes the remaining tail
through a recoverable file swap. An overfull outbox drops old events to bound SD use.
Normal online delivery is throttled to one event every 30 seconds. Sleep subscriptions
imply a saved-network connection attempt, limited to 10 seconds, and a separate 10-second delivery budget for the newest sleep event of each subscribed plugin (up to eight plugins), before power-down. All sleep screens acknowledge sleep before plugin preparation or network delivery. When sleeping from a book page or Home, Quick Resume, Reading Stats, Dark, Light, and Blank display before network delivery. Sleep modes that use downloaded artwork still wait for delivery before rendering it. After the newest sleep events, the same deadline allows up to four queued non-sleep connect: true deliveries total, in queue order within each plugin. A failed request leaves that event and later events for that plugin queued. Other events remain queued. Low-battery sleep leaves events queued. The delivery deadline is a soft limit on hardware: Arduino DNS resolution can block outside the TCP timeout.
Reader sessions count completed forward-page reading intervals (2–1800 seconds), emit after at least 10 active seconds, and exclude idle exit time. EPUB, TXT and XTC report progress on a 0–10000 scale. Timestamps use a persisted device clock floor; RTC adoption and network time synchronization prevent ordinary clock rollback.
Plugins can use /api/crypto for the upstream crypto operations and post
{path, key, expires} to /api/book-key. key is a base64-encoded 16- or
32-byte content key; expires is UTC epoch seconds, or zero for no expiry.
The destination must be an EPUB path outside protected firmware stores.
/api/status?plugin=<name> returns a stable, per-plugin device ID.
Keys are authenticated and wrapped using a device secret stored in internal NVS,
then saved beside the book as <book>.key. Copying the SD card to another reader
does not transfer access. Erasing NVS requires fulfilling the books again. Key
replacement preserves the prior file through interrupted publication.
Encrypted resources are decrypted as the reader requests them. Access is checked before loading existing book caches. Expired loans are rejected; loans with no trusted clock require a Wi-Fi time sync. The persisted clock cannot move backwards, but time spent powered off without a working RTC can delay expiry enforcement. Expiry is checked when opening a book, not continuously during an open session.
The source EPUB remains encrypted. Existing page, CSS, image, cover, and reading caches can contain decoded content; this integration does not encrypt all SD data. Service enrollment and account credentials remain the plugin's responsibility; real service enrollment requires that service's supported plugin and credentials.
Native simulator builds require wolfssl and openssl discoverable by
pkg-config. The simulator stores its device secret in .crossink-device-secret
outside fs_, or at CROSSINK_DEVICE_SECRET_PATH, with owner-only permissions.
Never copy that file when testing access from a second simulated device.
GET /plugin?name=<plugin>&file=<file> returns a quoted content-MD5 ETag and
Cache-Control: no-cache. Matching If-None-Match requests receive 304 with
no body. Same-size file changes produce a new tag; read failures return 500.
The digest is a cache validator, not an authenticity check.
Test on a reader with a disposable SD-card copy before distributing a release:
- Install manually, enable/disable Plugins, and open both browser and reader interfaces your plugin provides. Confirm the documented menu placement.
- Try first sign-in, expired credentials, a cancelled code, a failed request, and a retry. Check that failed sign-in does not destroy working credentials.
- Download a small book, cancel a download, and repeat with a full card or lost connection. Existing files and local configuration should survive failure.
- Update an existing installation and uninstall it. Verify that account files are not included in release assets and books stay outside the install folder.
- If subscribing to events, test offline queueing, retries, duplicate delivery,
and disabling Plugins. Treat
{event.id}as an idempotency key at the service. - Try an X3/X4 for a broadly compatible plugin; a successful S3 test alone does not prove that catalog size or memory use is suitable for those readers.
Firmware contributors can run the browser host tests without building firmware:
node --test test/plugin_host/PluginHostTest.mjsFor the firmware integration smoke suite, initialize dependencies, build one simulator environment, then run the fixture script against that binary:
git submodule update --init --recursive
pio run -e x4-pro-simulator -j1
python3 scripts/run_plugin_smoke_test.py --env x4-pro-simulator --output /tmp/crossink-plugin-smokeThis suite tests the firmware contract with its own fixture plugins; it does
not automatically test your plugin. Native builds need wolfssl and openssl
via pkg-config. Test actual service sign-in, hardware storage behavior, and
sleep-triggered requests on a physical device too.
web/assets/plugin-host.js: browser API and action-job host.src/util/PluginLocations.{h,cpp}: discovery, name validation, root priority, plugin classification, and version comparisons.src/activities/plugins/PluginCatalogActivity.cpp: catalog fields, sign-in, details, compatibility, downloads, and uninstall.src/util/PluginBundle.cpp: staged bundle installation and recovery.src/util/PluginEvents.cppandsrc/activities/reader/PluginReaderEvents.cpp: subscriptions, queueing, request delivery, and reading-session data.src/network/CrossPointPluginServer.cpp: plugin HTTP endpoints.- Web server endpoint reference: request contracts.