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
59 changes: 59 additions & 0 deletions app/Console/Commands/VersionChecker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace App\Console\Commands;

use App\Models\User;
use App\Services\SystemChecker;
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;
use Illuminate\Console\Command;

class VersionChecker extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:version';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Sends a notification to the admin users when Speedtest Tracker is outdated.';

/**
* Execute the console command.
*/
public function handle()
{
$system = new SystemChecker;

if (! $system->isOutOfDate()) {
return Command::SUCCESS;
}

$admins = User::select(['id', 'name', 'email', 'role'])
->where('role', 'admin')
->get();

foreach ($admins as $user) {
Notification::make()
->title('Update Available')
->body("There's a new version of Speedtest Tracker available: {$system->getRemoteVersion()}")
->info()
->actions([
Action::make('view releases')
->button()
->color('gray')
->url('https://github.com/alexjustesen/speedtest-tracker/releases')
->openUrlInNewTab(),
])
->sendToDatabase($user);
}

return Command::SUCCESS;
}
}
8 changes: 8 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console;

use App\Console\Commands\VersionChecker;
use App\Jobs\ExecSpeedtest;
use App\Settings\GeneralSettings;
use Cron\CronExpression;
Expand All @@ -17,6 +18,13 @@ protected function schedule(Schedule $schedule): void
{
$settings = new GeneralSettings();

/**
* Checked for new versions weekly on Thursday because
* I usually do releases on Thursday or Friday.
*/
$schedule->command(VersionChecker::class)->weeklyOn(5)
->timezone($settings->timezone ?? 'UTC');

/**
* Check for speedtests that need to run.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Services\SystemChecker;
use Awcodes\FilamentVersions\Providers\Contracts\VersionProvider;

class SpeedtestTrackerVersionProvider implements VersionProvider
Expand All @@ -12,7 +13,7 @@ public function getName(): string
public function getVersion(): string
{
return app()->isProduction()
? config('speedtest.build_version')
? app(new SystemChecker)->getLocalVersion()
: config('app.env');
}
}
9 changes: 9 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Providers;

use App\Services\SystemChecker;
use Illuminate\Foundation\Console\AboutCommand;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;

Expand All @@ -28,5 +30,12 @@ public function boot(): void
if (config('app.force_https')) {
URL::forceScheme('https');
}

$system = new SystemChecker;

AboutCommand::add('Speedtest Tracker', fn () => [
'Version' => $system->getLocalVersion(),
'Out of date' => $system->isOutOfDate() ? 'Yes' : 'No',
]);
}
}
6 changes: 2 additions & 4 deletions app/Services/SystemChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace App\Services;

use Illuminate\Support\Facades\Cache;

/**
* 🤔 inspired by: https://github.com/ploi/roadmap/blob/main/app/Services/SystemChecker.php
*/
Expand Down Expand Up @@ -50,9 +48,9 @@ public function isOutOfDate()
public function flushVersionData()
{
try {
Cache::forget($this->cacheKeyLocal);
cache()->forget($this->cacheKeyLocal);

Cache::forget($this->cacheKeyRemote);
cache()->forget($this->cacheKeyRemote);
} catch (\Exception $exception) {
// fail silently, it's ok
}
Expand Down
7 changes: 0 additions & 7 deletions config/speedtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
use Carbon\Carbon;

return [
/**
* Build information
*/
'build_date' => Carbon::parse('2023-12-20'),

'build_version' => '0.14.1',

/**
* General
*/
Expand Down