Skip to content

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, tray, widgetWindow } from "novadesk";
import { cpu, memory, recycleBin, time, 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.js or ../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, managing directories, and working with zip archives.

  • fs: Read, write, copy, rename, list, inspect files/directories, and zip/unzip operations.

novadesk module ​

Runtime and app-control APIs.

  • app: App lifecycle, logging, version and paths.
  • tray: System tray constructor, menu control, and events.
  • widgetWindow: Create and manage widget windows.
  • addon: Load and manage native C++ DLL addons.
  • toast: Show Windows toast notifications.
  • dialog: Show message boxes and file dialogs.

system module ​

Windows/system integration APIs.

  • audio: Master volume and WAV playback.
  • clipboard: Read and write clipboard text.
  • colors: Read system colors, dark mode, and accent color.
  • 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.
  • json: Parse/stringify plus JSON file helpers.
  • memory: Read RAM usage metrics.
  • network: Read network throughput and totals.
  • power: Read battery and power state.
  • recycleBin: Open, empty, and inspect Recycle Bin.
  • registry: Read and write Windows registry values.
  • time: Format time and work with timestamps.
  • wallpaper: Get/set desktop wallpaper.
  • webFetch: Fetch text from web URLs and files (Promise-based).

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 widgetWindow so user position and state can persist correctly.