Modules
Use modules to access system features and Novadesk runtime features from your script.
Table of Contents
Quick Start
Import modules with ES module syntax:
javascript
import { app, widgetWindow } from "novadesk";
import { cpu, memory, webFetch } from "system";Use this page as a map. Open each module page for full API details and examples.
Script Context
Some APIs are Main-script-only. If a method is unavailable in your script, check Script Types and the note on the module's own page.
Import Your Own Files as Modules
You can split widget logic into multiple local files and import them with relative paths.
1) Export from your custom file
javascript
// utils/format.js
export function formatBytes(bytes) {
if (bytes < 1024) return bytes + " B";
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + " KB";
return (bytes / (1024 * 1024)).toFixed(1) + " MB";
}2) Import it where you need it
javascript
// index.js
import { formatBytes } from "./utils/format.js";
import { memory } from "system";
const used = memory.getUsed();
console.log("Used RAM:", formatBytes(used));Notes
- Use relative import paths such as
./module.jsor../shared/module.js. - Keep file extensions explicit (recommended:
.js) to avoid path resolution confusion. - Relative imports are resolved from the importing file's location.
- You can mix custom modules with built-in modules (
novadesk,system,fs) in the same script.
Module Families
fs module
File-system APIs for reading/writing files and managing directories.
- fs: Read, write, copy, rename, list, and inspect files/directories.
novadesk module
Runtime and app-control APIs.
- app: App lifecycle, tray, logging, version and paths.
- widgetWindow: Create and manage widget windows.
- addon: Load and manage native C++ DLL addons.
system module
Windows/system integration APIs.
- audio: Master volume and WAV playback.
- audioLevel: Read live output/input levels.
- appVolume: Control per-app audio sessions.
- brightness: Read brightness capability status.
- clipboard: Read and write clipboard text.
- cpu: Read CPU usage metrics.
- disk: Read disk usage information.
- displayMetrics: Read monitor and desktop bounds.
- env: Read environment variables.
- execute: Launch files, apps, and URLs.
- fileIcon: Extract file icons to
.ico. - hotkey: Register global keyboard hotkeys.
- json: Parse/stringify plus JSON file helpers.
- memory: Read RAM usage metrics.
- mouse: Read cursor coordinates.
- network: Read network throughput and totals.
- nowPlaying: Read/control active media sessions.
- power: Read battery and power state.
- registry: Read and write Windows registry values.
- wallpaper: Get/set desktop wallpaper.
- webFetch: Read text from web URLs and files.
Notes and Best Practices
- Keep UI scripts focused on rendering and interaction. Put heavy system calls in Main script and pass results with IPC.
- For polling APIs (CPU, memory, network, now playing), use sensible intervals (for example
500-2000ms) to avoid unnecessary overhead. - Validate inputs before writing system state (volume, registry, wallpaper paths).
- Wrap external operations (
execute,webFetch, file/registry writes) in error handling and log failures for easier debugging. - Use stable window IDs in
widgetWindowso user position and state can persist correctly.