DejaOS SDK 2.0 App Development
Use this skill for DejaOS SDK 2.0 embedded JavaScript apps. DejaOS runs on QuickJS with native dxmodules wrappers for UI, hardware, storage, network, MQTT, HTTP, audio, face recognition, UART, watchdog, and related device features.
First Checks
- Confirm the target device model before changing project structure or
app.dxproj:DW200_V20,VF105_V12,VF203_V12,VF202_V12, orVF114_V12. - Inspect the existing
app.dxprojanddxmodules/before importing a component. - If a required
dxmodules/*.jsfile is missing, tell the user to enable the component inapp.dxprojand install modules with the DejaOS VSCode plugin. - Treat
dxmodules/as vendor code: call it, but do not modify it. - Keep app code under
src/, resources underresource/, and runtime data under/app/data. - Use absolute runtime resource paths such as
/app/code/resource/logo.png.
Project Rules
- Use
dxLoggerfor logging; do not useconsole.login app code. - Wrap hardware, network, filesystem, database, UART, timer, and worker-boundary code in
try/catch. - Keep
main.jsfocused on initialization and worker creation. Put UI, serial loops, face recognition loops, and long-running business logic in workers. - Create workers with
dxEventBus.newWorker(...)instead of native QuickJS worker APIs. - Remember that each worker is single-threaded.
dxStd.setTimeoutanddxStd.setIntervalare pseudo-async inside the same worker. - Prefer small objects and bounded loops. DejaOS devices have limited memory and CPU.
- Use imports relative to file depth, for example
../../dxmodules/dxLogger.js; there is no Node-stylenode_modulesresolution.
UI Rules
- Put UI in a dedicated UI worker.
- If UI text includes Chinese or other non-English text, ensure a TTF font exists, usually
/app/code/resource/font/font.ttf. - Prefer
UIManager.font(size, style)to avoid repeatedly creating font objects. - Use
assets/UIManager.jsas the standard single-screen, multi-page UI manager template when a project does not already have one. - A UI page should expose
init(), return its rootView, and may implementonShow(data)andonHide(). uiButtondoes not have a direct text property. Create aLabelinside the button.uiImageis not clickable by itself. Wrap it in a transparentViewand register the click on the wrapper.- For topmost overlays, use
dxui.Utils.LAYER.TOP. - For
uiView, callpadAll(0)and usuallyscroll(false)when doing exact layout. - Match image control sizes to image asset sizes because
uiImagedoes not automatically scale by default.
Common Components
- Base modules:
dxLogger,dxStd,dxOs,dxDriver,dxMap,dxEventBus,dxCommonUtils. - UI:
dxUi. - Storage:
dxSqliteDBfor relational data;dxKeyValueDBfor simple key-value data. - Network:
dxNetwork,dxHttpClient,dxHttpServer,dxMqttClient. - Hardware:
dxUart,dxGpio,dxGpioKey,dxPwm,dxNfc,dxBarcode. - System:
dxWatchdog,dxNtp,dxOta,dxConfiguration,dxAudio.
Task Guidance
When creating a new app:
- Start from the target model's
app.dxproj. - Include only base modules by default; add
dxUionly when UI is needed; add hardware/network modules only when required. - Create
src/main.js. - If UI is needed, create
src/uiWorker.js, copy or adaptassets/UIManager.js, register pages, and calldxui.handler()in a short interval. - Put resources in
resource/, especially fonts and images.
When modifying an existing app:
- Read nearby code first and follow existing worker boundaries.
- Check whether the needed component is already present in
dxmodules/. - Preserve existing page manager, event bus topics, and data directory conventions unless the user asks for a refactor.
- Verify JavaScript syntax with the available runtime when possible.
When reviewing DejaOS code, prioritize:
- Missing
try/catcharound device and worker boundary code. - Incorrect relative imports into
dxmodules. - UI code running in the main worker.
- Direct
console.log. - Missing font handling for Chinese UI.
- Resource paths that are not runtime absolute paths.
uiButtontext set directly instead of via a childLabel.- Click handlers attached directly to
uiImage. - Long loops or heavy work in UI workers.
Bundled Resources
references/dejaos-guide.md: English DejaOS SDK 2.0 development guide with module notes and code templates. Read when the task involves unfamiliar DejaOS modules or when building a new app structure.references/fitlock-patterns.md: English patterns distilled from a production-style FitLock cabinet app in this workspace. Read when designing larger apps with UI, MQTT, SQLite, face recognition, lock control, pending event queues, or multi-worker coordination.assets/UIManager.js: Reusable UIManager page-stack template.assets/DW200_V20-app.dxproj: Exampleapp.dxprojfor DW200_V20.assets/VF105_V12-app.dxproj: Exampleapp.dxprojfor VF105_V12.
Source: DejaOS/DejaOS — distributed by TomeVault.