Skip to content

Commit 7c4ad12

Browse files
committed
javascript-patterns(plugin-update): update caPluginUpdateCheck guidance (refs #3 + forum)
1 parent bf14508 commit 7c4ad12

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

docs/ui/javascript-patterns.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,37 @@ $(window).on('beforeunload', function() {
628628

629629
### Plugin Update UI: Use Built-In Helpers
630630

631-
For plugin update checks and status display, prefer Unraid's built-in Plugin Manager helpers instead of custom JavaScript tables and polling logic.
631+
For plugin update checks and status display, prefer Unraid's built-in helpers instead of custom JavaScript tables and polling logic.
632+
633+
#### Recommended (Unraid 6.8+ / CA 2019.03.27+)
634+
635+
Unraid 6.8.0+ includes `caPluginUpdateCheck()` in the base OS, so you can just call it directly from your `.page` file and it will handle the check and banner for you.
636+
637+
```javascript
638+
$(function() {
639+
if (typeof caPluginUpdateCheck === 'function') {
640+
caPluginUpdateCheck('yourplugin.plg', {name: 'Your Plugin'});
641+
}
642+
});
643+
```
644+
645+
You can also specify a container element for the banner or use a callback to customize how you display update info:
646+
647+
```javascript
648+
$(function() {
649+
if (typeof caPluginUpdateCheck === 'function') {
650+
caPluginUpdateCheck('yourplugin.plg', {element: '.pluginUpdate', name: 'Your Plugin'}, function(data) {
651+
if (!data) return;
652+
var result = JSON.parse(data);
653+
$('#installedVersion').text(result.installedVersion);
654+
});
655+
}
656+
});
657+
```
658+
659+
#### Legacy (pre‑6.8 / when CA is not available)
660+
661+
If `caPluginUpdateCheck` is not available, you can fall back to the core Plugin Manager API:
632662

633663
```php
634664
<?
@@ -657,6 +687,11 @@ $.post('/plugins/dynamix.plugin.manager/scripts/PluginAPI.php', {
657687

658688
This keeps behavior aligned with core Unraid update handling and avoids duplicating fragile check/update code paths.
659689

690+
> **References:**
691+
>
692+
> - Forum post: [https://forums.unraid.net/topic/79010-ca-api-for-plugin-update-checks/#findComment-733420](https://forums.unraid.net/topic/79010-ca-api-for-plugin-update-checks/#findComment-733420)
693+
> - Tracked in issue: [https://github.com/mstrhakr/plugin-docs/issues/3](https://github.com/mstrhakr/plugin-docs/issues/3)
694+
660695
### Async Loading for Expensive Operations
661696

662697
Operations like listing Docker containers or checking update status can take several seconds. If you run these synchronously during page load, the user sees a blank or frozen page. Instead, render the page shell immediately with a placeholder, then fetch expensive data via AJAX.

0 commit comments

Comments
 (0)