File tree 3 files changed +62
-3
lines changed
resources/views/components
3 files changed +62
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace App \Providers ;
4
4
5
+ use App \Support \GitHub ;
5
6
use Illuminate \Support \Facades \View ;
6
7
use Illuminate \Support \ServiceProvider ;
7
8
@@ -12,19 +13,20 @@ class AppServiceProvider extends ServiceProvider
12
13
*/
13
14
public function register (): void
14
15
{
15
- $ this -> registerSharedViewVariables ();
16
+ //
16
17
}
17
18
18
19
/**
19
20
* Bootstrap any application services.
20
21
*/
21
22
public function boot (): void
22
23
{
23
- //
24
+ $ this -> registerSharedViewVariables ();
24
25
}
25
26
26
27
private function registerSharedViewVariables (): void
27
28
{
29
+ View::share ('electronGitHubVersion ' , GitHub::electron ()->latestVersion ());
28
30
View::share ('discordLink ' , 'https://discord.gg/X62tWNStZK ' );
29
31
View::share ('bskyLink ' , 'https://bsky.app/profile/nativephp.bsky.social ' );
30
32
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 @@ -21,7 +21,7 @@ class="2xl:max-w-8xl mx-auto flex w-full max-w-5xl items-center justify-between
21
21
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"
22
22
aria-label =" Version information"
23
23
>
24
- 1.0.0-beta.2
24
+ {{ $electronGitHubVersion } }
25
25
</div >
26
26
</div >
27
27
You can’t perform that action at this time.
0 commit comments