From 2d26d2e15b6d554a6417667a0097c4addbe6d8cb Mon Sep 17 00:00:00 2001 From: Boy132 Date: Fri, 4 Jul 2025 09:24:40 +0200 Subject: [PATCH] add update_url to plugin.json --- .../Commands/Plugin/CreatePluginCommand.php | 1 + .../Admin/Resources/PluginResource.php | 10 +++++--- app/Models/Plugin.php | 24 +++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/Plugin/CreatePluginCommand.php b/app/Console/Commands/Plugin/CreatePluginCommand.php index 3616690ca..dbac041bd 100644 --- a/app/Console/Commands/Plugin/CreatePluginCommand.php +++ b/app/Console/Commands/Plugin/CreatePluginCommand.php @@ -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 diff --git a/app/Filament/Admin/Resources/PluginResource.php b/app/Filament/Admin/Resources/PluginResource.php index 187ed5ef3..aa59eb7a3 100644 --- a/app/Filament/Admin/Resources/PluginResource.php +++ b/app/Filament/Admin/Resources/PluginResource.php @@ -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'); diff --git a/app/Models/Plugin.php b/app/Models/Plugin.php index 2f5160757..f68df7400 100644 --- a/app/Models/Plugin.php +++ b/app/Models/Plugin.php @@ -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 */ + $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();