Skip to content

Commit a004fd4

Browse files
committed
Enhance documentation for Dynamix Framework, Event System, Introduction, and PLG File Reference with additional details on loading states, background processes, learning resources, and embedding base64 content for improved clarity and usability.
1 parent 8ffc72b commit a004fd4

4 files changed

Lines changed: 149 additions & 2 deletions

File tree

docs/core/dynamix-framework.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ function my_time($timestamp = null) {
313313

314314
## Loading States and Spinners
315315

316+
### Standard Spinner CSS
317+
316318
```html
317319
<!-- Standard Dynamix loading spinner -->
318320
<div class="spinner"></div>
@@ -333,6 +335,60 @@ function hideLoading() {
333335
</script>
334336
```
335337

338+
### showStatus() Function
339+
340+
The `showStatus()` function displays a spinning status indicator in the page header during long-running operations:
341+
342+
```javascript
343+
// Show status indicator with message
344+
showStatus('Processing...');
345+
346+
// Your long-running operation
347+
$.post('/plugins/myplugin/action.php', data, function(response) {
348+
// Hide status when done
349+
hideStatus();
350+
});
351+
```
352+
353+
### openBox() Function
354+
355+
The `openBox()` function opens a modal dialog box that typically displays command output or progress:
356+
357+
```javascript
358+
// Open a modal with content
359+
// openBox(content, title, height, width, showCloseButton)
360+
openBox(htmlContent, "Operation Title", 600, 800, true);
361+
362+
// Common pattern: Execute command and show output
363+
$.post('/plugins/myplugin/exec.php', {action: 'runCommand'}, function(data) {
364+
if (data) {
365+
openBox(data, "Command Output", 600, 800, true);
366+
}
367+
});
368+
```
369+
370+
**Parameters:**
371+
- `content` - HTML content to display in the modal
372+
- `title` - Title shown in the modal header
373+
- `height` - Modal height in pixels
374+
- `width` - Modal width in pixels
375+
- `showCloseButton` - Boolean to show/hide the close button
376+
377+
### Progress Frame Pattern
378+
379+
Many plugins use an iframe named `progressFrame` to display command output:
380+
381+
```html
382+
<form method="POST" action="/plugins/myplugin/action.php" target="progressFrame">
383+
<input type="hidden" name="csrf_token" value="<?=$var['csrf_token']?>">
384+
<input type="submit" value="Run Action">
385+
</form>
386+
387+
<!-- The progressFrame receives form submissions -->
388+
```
389+
390+
When the form targets `progressFrame`, the response is displayed in a dedicated progress area rather than replacing the current page.
391+
336392
## Page Structure Integration
337393

338394
### Standard Page Template

docs/events.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ For each event, scripts are executed in this order:
2525
1. **any_event handlers** - Scripts in `event/any_event/` or `event/any_event` receive ALL events
2626
2. **Specific event handlers** - Scripts matching the event name
2727

28-
Plugins are processed alphabetically by plugin name.
28+
Plugins are processed **alphabetically by plugin folder name** (ASCII sort order).
29+
30+
{: .note }
31+
> If your plugin depends on another plugin's event handler running first, you can prefix your plugin name with a character that sorts after the dependency. For example, `z-myplugin` would run after `compose.manager`. However, relying on execution order is fragile—design your event handlers to be independent when possible.
2932
3033
## Available Events
3134

@@ -250,10 +253,43 @@ The emhttp process waits for event scripts to complete. For long tasks:
250253
sleep 60
251254
do_long_task
252255

253-
# Good - runs in background
256+
# Good - runs in background using &
254257
do_long_task &
255258
```
256259

260+
### Using the `at` Command for Background Processes
261+
262+
For more reliable background execution (especially when the parent process may exit), use the `at` command which schedules a job to run independently:
263+
264+
```bash
265+
#!/bin/bash
266+
# Using 'at' command - most reliable for background tasks
267+
268+
# Schedule task to run immediately but independently
269+
echo "/usr/local/emhttp/plugins/myplugin/scripts/long_task.sh" | at now
270+
271+
# With logging
272+
echo "/usr/local/emhttp/plugins/myplugin/scripts/long_task.sh >> /var/log/myplugin.log 2>&1" | at now
273+
```
274+
275+
### Using `nohup` for Background Processes
276+
277+
The `nohup` command prevents the process from being killed when the parent exits:
278+
279+
```bash
280+
#!/bin/bash
281+
# Using nohup - process continues even if parent exits
282+
283+
nohup /usr/local/emhttp/plugins/myplugin/scripts/long_task.sh > /var/log/myplugin.log 2>&1 &
284+
285+
# Disown to fully detach from shell
286+
nohup /usr/local/emhttp/plugins/myplugin/scripts/long_task.sh > /var/log/myplugin.log 2>&1 &
287+
disown
288+
```
289+
290+
{: .note }
291+
> The `at` command is generally preferred over `nohup &` because it creates a completely independent process that won't be affected by signal propagation when emhttp continues execution.
292+
257293
### 2. Use Logger for Debugging
258294

259295
Log messages appear in `/var/log/syslog`:

docs/introduction.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,32 @@ The DocTest plugin validates:
172172
## Next Steps
173173

174174
Ready to build your first plugin? Continue to [Your First Plugin](getting-started.md) for a hands-on tutorial.
175+
176+
## Learning Resources
177+
178+
The best way to learn Unraid plugin development is to study existing plugins:
179+
180+
### System Scripts
181+
182+
The `/usr/local/sbin/` directory contains many Unraid system scripts that demonstrate patterns:
183+
- `emhttp_event` - How events are dispatched to plugins
184+
- `notify` - Notification system internals
185+
- Various utility scripts
186+
187+
### Reference Plugins
188+
189+
- **[Dynamix plugins](https://github.com/unraid/dynamix)** - Official Unraid plugins (the reference implementation)
190+
- **[Community Applications](https://github.com/Squidly271/community.applications)** - Complex PHP patterns
191+
- **[Compose Manager](https://github.com/dcflachs/compose_plugin)** - Docker Compose integration example
192+
193+
### Community Resources
194+
195+
- **[Unraid Forums - Plugin Support](https://forums.unraid.net/forum/index.php?board=45.0)** - Get help from the community
196+
- **[Unraid Forums - Programming](https://forums.unraid.net/forum/index.php?board=79.0)** - Technical discussions
197+
198+
### Key Forum Threads
199+
200+
These foundational posts contain detailed plugin development information:
201+
202+
- [How does the plugin system work?](https://forums.unraid.net/topic/38582-how-does-the-plugin-system-work-documentation-added/) - Comprehensive PLG structure guide
203+
- [Plugin System Documentation](https://forums.unraid.net/topic/52623-plugin-system-documentation/) - Links to essential resources

docs/plg-file.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,32 @@ The `<LOCAL>` element copies a previously downloaded file:
204204

205205
This caches files on the USB flash so they don't need to be re-downloaded on each boot.
206206

207+
### Embedding Base64 Content
208+
209+
For small files like icons, you can embed them directly in the PLG file using base64 encoding:
210+
211+
```xml
212+
<FILE Name="/usr/local/emhttp/plugins/myplugin/images/icon.png" Type="base64">
213+
<INLINE>
214+
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAA...
215+
</INLINE>
216+
</FILE>
217+
```
218+
219+
The `Type="base64"` attribute tells the plugin system to decode the content before writing the file.
220+
221+
**When to use base64 embedding:**
222+
- Small icons (< 10KB recommended)
223+
- Files that rarely change
224+
- Reducing external dependencies during install
225+
226+
**Generate base64 content:**
227+
```bash
228+
base64 -w 0 icon.png
229+
# Or with line wrapping (easier to read in PLG)
230+
base64 icon.png
231+
```
232+
207233
## Method Attribute
208234

209235
The `Method` attribute controls when a FILE element is processed:

0 commit comments

Comments
 (0)