Widgets
Egern supports iOS Widgets, allowing users to display custom content on the Home Screen and Lock Screen. Widgets are rendered from a JSON-based DSL description generated by JavaScript scripts.
Using Widgets from Modules
The simplest way is to install a module that includes widgets — no coding required.
Steps
- Go to Tools → Modules, tap + in the top-right corner to add a module
- Enter the module URL and save
- Open the Analytics tab at the bottom, tap the top-left button to enter the Widget Gallery — widgets provided by the module will automatically appear in the "Module Widgets" section
- If the module requires parameters (e.g. API Key), go back to the module edit page and add the corresponding key-value pairs in the Env section
Adding to the iOS Home Screen
- Long-press an empty area on the Home Screen, tap + in the top-left corner
- Search for Egern and select a widget size
- After adding, long-press the widget → Edit Widget, then select the widget name to display
Building Your Own Widget
To create your own widget, you first need a generic type script, then create a widget that references it.
1. Create a Script
Go to Tools → Scripts, tap +:
| Field | Value |
|---|---|
| Name | e.g. my-widget |
| Type | Select generic |
| File Location | Select Local, enter a filename like my-widget.js |
Tap Edit File and write the following minimal script:
export default async function(ctx) {
return {
type: 'widget',
children: [
{
type: 'text',
text: 'Hello, Widget!',
font: { size: 'title2', weight: 'bold' },
textColor: '#FFFFFF',
},
],
backgroundColor: '#2D6A4F',
padding: 16,
};
}
Save the script.
2. Create a Widget
In the Analytics tab, tap the top-left button to enter the Widget Gallery, then tap +:
| Field | Value |
|---|---|
| Name | e.g. My Widget |
| Script Name | Select the my-widget script you just created |
After saving, the widget will appear in the gallery and run automatically.
Widget Configuration
Define widgets in the widgets field of the main configuration file:
-
name (string), required
The widget name, must be unique.
-
script_name (string), optional
The name of an associated generic script. Defaults to using a script with the same name as the widget.
-
env (object), optional
Environment variables (key-value pairs) passed to the script. See Environment Variables for details.
Configuration Example
scriptings:
- generic:
name: "weather-widget"
script_url: "https://example.com/scripts/weather.js"
timeout: 20
- generic:
name: "net-status-script"
script_url: "https://example.com/scripts/net-status.js"
timeout: 20
widgets:
# name matches script name, no need to set script_name
- name: "weather-widget"
env:
CITY: "Shanghai"
UNIT: "celsius"
# name differs from script name, use script_name to specify the associated script
- name: "network-monitor"
script_name: "net-status-script"
Widget DSL
A widget script is a generic type script that returns a JSON-based DSL description via return. The DSL uses a tree structure composed of nested elements.