Writing a module
A module has up to three parts:
- Contract (optional but recommended) in
packages/protocol/src/index.ts: id, actions, events, types. - Hub part (if the module needs the PC): a
HubModule. - Edge part: a view shown on the XENEON EDGE.
A module is either built in (compiled into Raidtech Edge Hub and the interface) or installed (a folder in
%APPDATA%\RaidtechEdge\modules\<id>\, loaded while the hub runs). Both use the same contracts.
Hub part
import type { HubModule } from "../../module.ts";
import { ModuleError } from "../../module.ts";
import { tr } from "../../i18n.ts";
export function createHelloModule(): HubModule {
let ctx;
return {
info: { id: "hello", name: "Hello", version: "0.1.0" },
start(context) { ctx = context; }, // ctx.log, ctx.dir, ctx.broadcast(), ctx.clientCount()
onClientsChanged(count) { /* start/stop polling */ },
handle(action, payload) {
if (action === "ping") return { pong: Date.now() }; // value sent back to the widget
throw new ModuleError(tr(`unknown action "${action}"`, `action inconnue « ${action} »`)); // error sent back to the widget
},
};
}
ctx.dir is %APPDATA%\RaidtechEdge\modules-data\<id>\: keep the module’s settings and caches there. It is never
deleted when the module is updated or removed, so a reinstalled module finds its settings again.
Built in: add it to the builtins list in apps/hub/src/app.ts.
Edge part
import { hub } from "../../hub.ts";
import { useHubEvent } from "../../hooks.ts";
import { tr } from "../../i18n.ts";
export function HelloView() {
const tick = useHubEvent<number>("hello", "tick");
return <button onClick={() => hub.request("hello", "ping")}>{tr("Ping", "Ping")} ({tick})</button>;
}
Built in: add it to builtins in apps/widget/src/modules/registry.ts:
{ id: "hello", get name() { return tr("Hello", "Bonjour"); }, icon: SomeIcon, hubModule: "hello", View: HelloView }
With hubModule, the shell automatically shows a “start Raidtech Edge Hub” screen while the module is unavailable.
Every module opens from the home screen. The dock works like the Windows taskbar: Home, Edges and Apps are fixed at
the top, then up to 3 apps of the user’s (DockLayout.slots, hub 0.12+). A long press on the dock switches to edit
mode: drag an app to move it, its cross removes it, + adds one. The layout is saved by the hub and shared by every
screen.
Installed modules
An installed module is a folder:
%APPDATA%\RaidtechEdge\modules\hello\
manifest.json
hub.js PC side: CommonJS (or .mjs), default export = HubModule or a function returning one
view.js Edge side: a classic script that calls window.RaidtechEdge.register()
view.css optional
icon.svg optional
{
"id": "hello",
"name": { "en": "Hello", "fr": "Bonjour" },
"version": "1.0.0",
"description": { "en": "Says hello", "fr": "Dit bonjour" },
"author": "you",
"sdk": 1,
"minHub": "0.10.0",
"hub": "hub.js",
"view": "view.js",
"style": "view.css",
"icon": "icon.svg"
}
huborviewmay be left out (a module with only a view, or only a PC side).- The hub watches the folder: a module dropped, changed or deleted is loaded, reloaded or removed without restarting, and the Edge follows (a changed view reloads the page). The Edges app shows it; a module that cannot run says why there. Control panel → Settings → Edges folder reads the folder again or opens it on the PC.
- An installed module with the id of a built-in one (
launcher,media,system) replaces it; the built-in one comes back when it is removed.ui,store,updateandhubare reserved. - Only the files named in the manifest are served to the Edge, at
/m/store/pkg/<id>/<file>. - Modules run with the hub’s privileges: only install code you trust.
The Store
The Store module (on the home screen, and from Add Edges in the Edges app) lists the modules of the catalogue
raidtech-edge-modules: Discover, Installed and
Updates. The hub reads its catalog.json at start, then every 6 hours (and when the Store is opened after 10
minutes).
- Each catalogue entry pins its files to one commit of that repository, with the size and SHA-256 of every file. The hub
downloads them from
raw.githubusercontent.comonly, checks each one, writes them to a staging folder, then swaps the folder in. A file that does not match aborts the install and leaves the installed version alone. - A module installed from the Store carries a
.store.jsonmarker; one dropped in by hand stays “local” and is never updated or replaced by the Store. revoked.jsonin the catalogue repository disables a version on every PC at the next check.- Uninstalling keeps
modules-data\<id>: reinstall and the settings come back. Erase data in the module’s card removes them. - Discord is in the Store since 0.10. A hub that had Discord set up installs it by itself once.
To publish a module, open a pull request on the catalogue repository: the CI checks it, and once merged
catalog.json is rebuilt pinned to the merge commit.
What modules get
On the Edge, window.RaidtechEdge:
const { preact, "preact/hooks": hooks, "preact/jsx-runtime": jsx, hub, hooks: edgeHooks, i18n, icons, nav, slider } = RaidtechEdge.libs;
RaidtechEdge.register({ id: "hello", View, Island, useAlert, useGlance, icon, color: "#5865f2" }); // name and icon default to the manifest's
On screen an installed module is called an Edge (“un Edge”, “des Edges” in French); the device itself is “the Xeneon”. Every Edge is in the Edges app of the dock (as a big app icon, the Store’s other Edges after it) and on the home screen; only the ones the user puts in the dock (its + in edit mode, or ⋯ in the Edges app’s rearrange mode) get their own dock button.
color (optional, hub 0.12.4+) is the Edge’s brand color: its icon in the Edges app is a rounded square of that
color (default: the accent).
useGlance (optional, hub 0.11+) is a hook that returns one short line for the Edge’s icon: null, a string, or
{ text, live: true } while something happens right now (a call, a recording): the line turns red.
Hub 0.12.4+: add people ([{ name, avatar?, speaking? }], absolute avatar URLs) to show who is there instead of
the text, in a pill like the Edge Island: image (absolute URL, e.g. a server’s icon), label (e.g. the voice
channel’s name, 0.12.5+) and at most 4 faces, “+N” for the others; speaking draws a green ring (0.12.5+).
useAlert still drives the red dot: an Edge outside the dock lights up the Edges button instead.
hub is the interface’s own hub connection (hub.request, hub.on, HUB_HTTP), i18n its tr() and language.
Use these instead of bundling your own Preact or WebSocket.
On the PC, globalThis.RaidtechEdgeHub: { sdk, hubVersion, i18n: { tr, getLang, onLangChange }, module: { ModuleError }, runtime: { isExe } }.
Building one from this repo
modules/<id>/module.json is the manifest plus a build section; pnpm modules:build <id> bundles it into
modules/dist/<id>/, and --install copies it to the modules folder:
"build": { "hub": "hub.ts", "view": "view.ts", "files": { "icon.svg": "icon.svg" } }
The entries import the code like a built-in module does; imports of the interface’s hub.ts, hooks.ts, i18n.ts,
icons.tsx, shell/nav.ts, shell/Slider.tsx and of Preact become window.RaidtechEdge.libs, and the hub’s
i18n.ts, module.ts and runtime.ts become globalThis.RaidtechEdgeHub (resourcePath() then points next to
hub.js). Importing any other private file of the interface or the hub fails the build. modules/discord is the
example: the Discord module of the Store, built from this repo’s code. Copy modules/dist/<id> into the catalogue
repository’s modules/<id> to publish it.
To try a module without touching the installed hub, run a second hub from the repo on another port with its own data:
$env:RAIDTECH_HUB_PORT = "47822"; $env:RAIDTECH_EDGE_HOME = "$env:TEMP\edge-dev"; pnpm hub -- --no-tray
then open http://localhost:47822/m/ui/index.html (the page talks to the hub that serves it).
Good practices
- Touch targets ≥ 64 px, visual feedback on tap (
:active). - Sizes in container units (
cqh,cqw,cqmin): the widget must work from 360 px to 2560 px, horizontal and vertical. - Never let the hub run a command or a path coming from the widget: the widget sends ids, the hub decides.
- Every text shown to the user goes through
tr("English", "Français"), on the widget and on the hub (errors and messages sent to the widget).