Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

15 changes: 4 additions & 11 deletions app/Providers/Filament/AdminPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace App\Providers\Filament;

use App\Filament\VersionProviders\SpeedtestTrackerVersionProvider;
use Awcodes\FilamentVersions\VersionsPlugin;
use App\Services\GitHub\Repository;
use Filament\FontProviders\LocalFontProvider;
use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\DisableBladeIconComponents;
Expand Down Expand Up @@ -44,13 +43,6 @@ public function panel(Panel $panel): Panel
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
->pages([])
->plugins([
VersionsPlugin::make()
->hasDefaults(false)
->items([
new SpeedtestTrackerVersionProvider,
]),
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
->widgets([])
->databaseNotifications()
Expand Down Expand Up @@ -85,9 +77,10 @@ public function panel(Panel $panel): Panel
->url('https://github.com/sponsors/alexjustesen', shouldOpenInNewTab: true)
->icon('heroicon-o-banknotes')
->group('Links'),
NavigationItem::make('GitHub')
NavigationItem::make(config('speedtest.build_version'))
->url('https://github.com/alexjustesen/speedtest-tracker', shouldOpenInNewTab: true)
->icon('heroicon-o-code-bracket')
->icon('tabler-brand-github')
->badge(fn (): string => Repository::updateAvailable() ? 'Update Available!' : 'Up to Date')
->group('Links'),
]);
}
Expand Down
82 changes: 82 additions & 0 deletions app/Services/GitHub/Repository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace App\Services\GitHub;

use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Throwable;

class Repository
{
/**
* Get the latest tagged version from the GitHub repository.
*
* @return string|false Returns the version tag (e.g., "v1.2.3") or false on failure
*/
public static function getLatestVersion(): string|false
{
return Cache::remember('github.latest_version', now()->addHour(), function () {
try {
$response = Http::retry(3, 100)
->timeout(10)
->withHeaders([
'Accept' => 'application/vnd.github.v3+json',
'User-Agent' => 'speedtest-tracker',
])
->get('https://api.github.com/repos/alexjustesen/speedtest-tracker/releases/latest');

if (! $response->successful()) {
Log::warning('Failed to fetch latest version from GitHub API', [
'status' => $response->status(),
'response' => $response->body(),
]);

return false;
}

$data = $response->json();

if (! isset($data['tag_name'])) {
Log::warning('GitHub API response missing tag_name field', ['response' => $data]);

return false;
}

return $data['tag_name'];
} catch (Throwable $e) {
Log::error('Exception occurred while fetching latest version from GitHub', [
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
]);

return false;
}
});
}

/**
* Check if a newer version is available.
*
* @return bool Returns true if a newer version is available, false if up to date or unable to determine
*/
public static function updateAvailable(): bool
{
$currentVersion = config('speedtest.build_version');
$latestVersion = self::getLatestVersion();

if ($latestVersion === false) {
return false; // Unable to determine, assume no update available
}

// Normalize versions by removing 'v' prefix for comparison
$normalizedCurrent = ltrim($currentVersion, 'v');
$normalizedLatest = ltrim($latestVersion, 'v');

// Use version_compare to properly compare semantic versions
$comparison = version_compare($normalizedLatest, $normalizedCurrent);

return $comparison > 0; // 1 = latest is newer, 0 = equal, -1 = latest is older
}
}
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"license": "MIT",
"require": {
"php": "^8.2",
"awcodes/filament-versions": "^2.0.1",
"chrisullyott/php-filesize": "^4.2.1",
"dragonmantank/cron-expression": "^3.4.0",
"filament/filament": "^3.3.31",
Expand Down
66 changes: 1 addition & 65 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.