File tree Expand file tree Collapse file tree 3 files changed +62
-3
lines changed
resources/views/components Expand file tree Collapse file tree 3 files changed +62
-3
lines changed Original file line number Diff line number Diff line change 22
33namespace App \Providers ;
44
5+ use App \Support \GitHub ;
56use Illuminate \Support \Facades \View ;
67use Illuminate \Support \ServiceProvider ;
78
@@ -12,19 +13,20 @@ class AppServiceProvider extends ServiceProvider
1213 */
1314 public function register (): void
1415 {
15- $ this -> registerSharedViewVariables ();
16+ //
1617 }
1718
1819 /**
1920 * Bootstrap any application services.
2021 */
2122 public function boot (): void
2223 {
23- //
24+ $ this -> registerSharedViewVariables ();
2425 }
2526
2627 private function registerSharedViewVariables (): void
2728 {
29+ View::share ('electronGitHubVersion ' , GitHub::electron ()->latestVersion ());
2830 View::share ('discordLink ' , 'https://discord.gg/X62tWNStZK ' );
2931 View::share ('bskyLink ' , 'https://bsky.app/profile/nativephp.bsky.social ' );
3032 View::share ('openCollectiveLink ' , 'https://opencollective.com/nativephp ' );
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Support ;
4+
5+ use Illuminate \Support \Facades \Cache ;
6+ use Illuminate \Support \Facades \Http ;
7+
8+ class GitHub
9+ {
10+ public const PACKAGE_ELECTRON = 'nativephp/electron ' ;
11+ public const PACKAGE_LARAVEL = 'nativephp/laravel ' ;
12+
13+ public function __construct (
14+ private string $ package
15+ ) {}
16+
17+ public static function electron (): static
18+ {
19+ return new static (static ::PACKAGE_ELECTRON );
20+ }
21+
22+ public static function laravel (): static
23+ {
24+ return new static (static ::PACKAGE_LARAVEL );
25+ }
26+
27+ public function latestVersion ()
28+ {
29+ $ version = Cache::remember (
30+ $ this ->getCacheKey ('latest-version ' ),
31+ now ()->addHour (),
32+ function () {
33+ return $ this ->fetchLatestVersion ();
34+ }
35+ );
36+
37+ return $ version ['name ' ] ?? 'Unknown ' ;
38+ }
39+
40+ private function fetchLatestVersion ()
41+ {
42+ // Make a request to GitHub
43+ $ response = Http::get ('https://api.github.com/repos/ ' .$ this ->package .'/releases/latest ' );
44+
45+ // Check if the request was successful
46+ if ($ response ->failed ()) {
47+ return null ;
48+ }
49+
50+ return $ response ->json ();
51+ }
52+
53+ private function getCacheKey (string $ string ): string
54+ {
55+ return sprintf ('%s-%s ' , $ this ->package , $ string );
56+ }
57+ }
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ class="2xl:max-w-8xl mx-auto flex w-full max-w-5xl items-center justify-between
2424 class =" hidden rounded-full bg-gray-200/60 px-2 py-1 text-xs text-gray-600 lg:block dark:bg-[#1f2032] dark:text-white/50"
2525 aria-label =" Version information"
2626 >
27- 1.0.0-beta.2
27+ {{ $electronGitHubVersion } }
2828 </div >
2929 </div >
3030
You can’t perform that action at this time.
0 commit comments