Skip to content

Commit 58088ac

Browse files
committed
docs(js): recommend built-in plugin manager helpers for updates
Add section pointing developers to PluginHelpers.php make_link() and the PluginAPI.php checkPlugin endpoint instead of rolling custom update-check JavaScript. Thanks @Squidly271 in issue #2
1 parent 7591baf commit 58088ac

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

docs/ui/javascript-patterns.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,37 @@ $(window).on('beforeunload', function() {
674674
});
675675
```
676676

677+
### Plugin Update UI: Use Built-In Helpers
678+
679+
For plugin update checks and status display, prefer Unraid's built-in Plugin Manager helpers instead of custom JavaScript tables and polling logic.
680+
681+
```php
682+
<?
683+
$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
684+
require_once "$docroot/plugins/dynamix.plugin.manager/include/PluginHelpers.php";
685+
686+
// Renders the same style of install/update/remove controls used by core pages.
687+
echo make_link('update', 'yourplugin.plg');
688+
?>
689+
```
690+
691+
```javascript
692+
// Built-in API used by core plugin manager pages for update checks.
693+
$.post('/plugins/dynamix.plugin.manager/scripts/PluginAPI.php', {
694+
action: 'checkPlugin',
695+
options: {
696+
plugin: 'yourplugin.plg',
697+
name: 'Your Plugin'
698+
}
699+
}, function(response) {
700+
if (response.updateAvailable) {
701+
// Show your preferred indicator or enable update action.
702+
}
703+
}, 'json');
704+
```
705+
706+
This keeps behavior aligned with core Unraid update handling and avoids duplicating fragile check/update code paths.
707+
677708
### Async Loading for Expensive Operations
678709

679710
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.
@@ -688,7 +719,6 @@ function loadList() {
688719
myPluginTimers.load = setTimeout(function(){
689720
$('div.spinner.fixed').show('slow');
690721
}, 500);
691-
692722
$.get('/plugins/myplugin/php/list.php', function(data) {
693723
clearTimeout(myPluginTimers.load);
694724
$('#list-container').html(data);

0 commit comments

Comments
 (0)