From e589f972fb502f9d69049a9f233f1daf0f59bd70 Mon Sep 17 00:00:00 2001 From: Letter N <24603524+LetterN@users.noreply.github.com> Date: Sun, 12 Oct 2025 09:34:38 +0800 Subject: [PATCH] Add changelog preview when a new update is available (#1792) Co-authored-by: Boy132 --- app/Filament/Admin/Widgets/UpdateWidget.php | 11 +++++++++++ .../Helpers/SoftwareVersionService.php | 18 ++++++++++++++++++ lang/en/admin/dashboard.php | 1 + 3 files changed, 30 insertions(+) diff --git a/app/Filament/Admin/Widgets/UpdateWidget.php b/app/Filament/Admin/Widgets/UpdateWidget.php index 7d54b9b78..35a0b1817 100644 --- a/app/Filament/Admin/Widgets/UpdateWidget.php +++ b/app/Filament/Admin/Widgets/UpdateWidget.php @@ -43,7 +43,18 @@ class UpdateWidget extends FormWidget ->iconColor('warning') ->schema([ TextEntry::make('info') + ->hiddenLabel() ->state(trans('admin/dashboard.sections.intro-update-available.content', ['latestVersion' => $this->softwareVersionService->latestPanelVersion()])), + Section::make(trans('admin/dashboard.sections.intro-update-available.button_changelog')) + ->icon('tabler-script') + ->collapsible() + ->collapsed() + ->schema([ + TextEntry::make('changelog') + ->hiddenLabel() + ->state($this->softwareVersionService->latestPanelVersionChangelog()) + ->markdown(), + ]), ]) ->headerActions([ Action::make('update') diff --git a/app/Services/Helpers/SoftwareVersionService.php b/app/Services/Helpers/SoftwareVersionService.php index 0cfca2cfe..4db9a25d8 100644 --- a/app/Services/Helpers/SoftwareVersionService.php +++ b/app/Services/Helpers/SoftwareVersionService.php @@ -7,6 +7,24 @@ use Illuminate\Support\Facades\Http; class SoftwareVersionService { + public function latestPanelVersionChangelog(): string + { + $key = 'panel:latest_version_changelog'; + if (cache()->get($key) === 'error') { + cache()->forget($key); + } + + return cache()->remember($key, now()->addMinutes(config('panel.cdn.cache_time', 60)), function () { + try { + $response = Http::timeout(5)->connectTimeout(1)->get('https://api.github.com/repos/pelican-dev/panel/releases/latest')->throw()->json(); + + return $response['body']; + } catch (Exception) { + return 'error'; + } + }); + } + public function latestPanelVersion(): string { $key = 'panel:latest_version'; diff --git a/lang/en/admin/dashboard.php b/lang/en/admin/dashboard.php index 49ff57726..410175e9c 100644 --- a/lang/en/admin/dashboard.php +++ b/lang/en/admin/dashboard.php @@ -17,6 +17,7 @@ return [ 'intro-update-available' => [ 'heading' => 'Update available', 'content' => ':latestVersion is now available! Read our documentation to update your Panel.', + 'button_changelog' => 'What\'s New?', ], 'intro-no-update' => [ 'heading' => 'Your Panel is up to date',