mirror of
https://github.com/pelican-dev/panel.git
synced 2025-11-08 10:39:27 +01:00
add update_url to plugin.json
This commit is contained in:
parent
55b1d6e960
commit
2d26d2e15b
@ -79,6 +79,7 @@ class CreatePluginCommand extends Command
|
||||
'panel_version' => config('app.version') === 'canary' ? null : config('app.version'),
|
||||
'category' => $category,
|
||||
'load_order' => 0,
|
||||
'update_url' => null,
|
||||
], JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
|
||||
// Create src directory and create main class
|
||||
|
||||
@ -33,9 +33,9 @@ class PluginResource extends Resource
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->description(fn (Plugin $plugin) => (strlen($plugin->description) > 80) ? substr($plugin->description, 0, 80).'...' : $plugin->description)
|
||||
//->icon(fn (Plugin $plugin) => $plugin->isCompatible() ? 'tabler-versions' : 'tabler-versions-off')
|
||||
//->iconColor(fn (Plugin $plugin) => $plugin->isCompatible() ? 'success' : 'danger')
|
||||
//->tooltip(fn (Plugin $plugin) => !$plugin->isCompatible() ? 'This Plugin is only compatible with Panel version ' . $plugin->panel_version . ' but you are using version ' . config('app.version') . '!' : null)
|
||||
->icon(fn (Plugin $plugin) => $plugin->isUpdateAvailable() ? 'tabler-versions-off' : 'tabler-versions')
|
||||
->iconColor(fn (Plugin $plugin) => $plugin->isUpdateAvailable() ? 'danger' : 'success')
|
||||
->tooltip(fn (Plugin $plugin) => $plugin->isUpdateAvailable() ? 'An update for this plugin is available' : null)
|
||||
->sortable(),
|
||||
TextColumn::make('author')
|
||||
->sortable(),
|
||||
@ -78,6 +78,7 @@ class PluginResource extends Resource
|
||||
->title('Plugin installed')
|
||||
->send();
|
||||
}),
|
||||
// TODO: "update" button
|
||||
Action::make('enable')
|
||||
->authorize(fn (Plugin $plugin) => auth()->user()->can('update plugin', $plugin))
|
||||
->icon('tabler-check')
|
||||
@ -109,6 +110,9 @@ class PluginResource extends Resource
|
||||
->send();
|
||||
}),
|
||||
])
|
||||
->headerActions([
|
||||
// TODO: "import" button
|
||||
])
|
||||
->emptyStateIcon('tabler-packages')
|
||||
->emptyStateDescription('')
|
||||
->emptyStateHeading('No Plugins');
|
||||
|
||||
@ -24,6 +24,7 @@ use Sushi\Sushi;
|
||||
* @property string|null $panel_version
|
||||
* @property string $category
|
||||
* @property int $load_order
|
||||
* @property string|null $update_url
|
||||
*/
|
||||
class Plugin extends Model implements HasPluginSettings
|
||||
{
|
||||
@ -55,6 +56,7 @@ class Plugin extends Model implements HasPluginSettings
|
||||
'panel_version' => 'string',
|
||||
'category' => 'string',
|
||||
'load_order' => 'integer',
|
||||
'update_url' => 'string',
|
||||
];
|
||||
}
|
||||
|
||||
@ -74,6 +76,7 @@ class Plugin extends Model implements HasPluginSettings
|
||||
* panel_version: string,
|
||||
* category: string,
|
||||
* load_order: int
|
||||
* update_url: string,
|
||||
* }>
|
||||
*/
|
||||
public function getRows(): array
|
||||
@ -173,6 +176,27 @@ class Plugin extends Model implements HasPluginSettings
|
||||
return !str($this->panel_version)->startsWith('^');
|
||||
}
|
||||
|
||||
public function isUpdateAvailable(): bool
|
||||
{
|
||||
if ($this->update_url === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$panelVersion = config('app.version', 'canary');
|
||||
|
||||
if ($panelVersion === 'canary') {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var array<string, array{version: string, download_url: string}> */
|
||||
$updateData = file_get_contents($this->update_url);
|
||||
if ($updateData[$panelVersion]) {
|
||||
return version_compare($updateData[$panelVersion]['version'], $this->version, '>');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function hasSettings(): bool
|
||||
{
|
||||
$class = $this->fullClass();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user