2
2
3
3
namespace Niladam \FilamentAutoLogout ;
4
4
5
+ use Carbon \Carbon ;
5
6
use Closure ;
6
7
use Filament \Contracts \Plugin ;
7
8
use Filament \Panel ;
@@ -15,21 +16,21 @@ class AutoLogoutPlugin implements Plugin
15
16
{
16
17
use EvaluatesClosures;
17
18
18
- public bool | Closure $ enabled = true ;
19
+ public bool | Closure | null $ enabled = null ;
19
20
20
21
public bool | Closure $ hasWarning = true ;
21
22
22
- public bool | Closure $ showTimeLeft = true ;
23
+ public bool | Closure | null $ showTimeLeft = null ;
23
24
24
- public int | Closure $ duration = 900 ;
25
+ public int | Closure | null $ duration = null ;
25
26
26
- public int | Closure $ warnBeforeSeconds = 30 ;
27
+ public int | Closure | null $ warnBeforeSeconds = null ;
27
28
28
29
public array | Closure $ color = Color::Zinc;
29
30
30
31
public ?string $ timeleftText = null ;
31
32
32
- private string $ location = PanelsRenderHook::GLOBAL_SEARCH_BEFORE ;
33
+ public string $ location = PanelsRenderHook::GLOBAL_SEARCH_BEFORE ;
33
34
34
35
public function getId (): string
35
36
{
@@ -46,7 +47,14 @@ public function register(Panel $panel): void
46
47
47
48
public function boot (Panel $ panel ): void
48
49
{
49
- $ this ->timeleftText = $ this ->timeleftText ?? config ('filament-auto-logout.time_left_text ' );
50
+ $ this ->enabled = $ this ->enabled ?? config ('filament-auto-logout.enabled ' , true );
51
+ $ this ->duration = $ this ->duration ?? config ('filament-auto-logout.duration_in_seconds ' , Carbon::SECONDS_PER_MINUTE * 5 );
52
+ $ this ->warnBeforeSeconds = $ this ->warnBeforeSeconds ?? config ('filament-auto-logout.warn_before_in_seconds ' , 30 );
53
+ $ this ->showTimeLeft = $ this ->showTimeLeft ?? config ('filament-auto-logout.show_time_left ' , true );
54
+ $ this ->timeleftText = $ this ->timeleftText ?? config ('filament-auto-logout.time_left_text ' , 'Time left: ' );
55
+ $ this ->location = $ this ->location === PanelsRenderHook::GLOBAL_SEARCH_BEFORE
56
+ ? config ('filament-auto-logout.location ' , PanelsRenderHook::GLOBAL_SEARCH_BEFORE )
57
+ : $ this ->location ;
50
58
}
51
59
52
60
protected function renderView (string $ logoutUrl ): ?string
@@ -73,7 +81,6 @@ public static function make(): static
73
81
74
82
public static function get (): static
75
83
{
76
- /** @var static $plugin */
77
84
$ plugin = filament (app (static ::class)->getId ());
78
85
79
86
return $ plugin ;
@@ -90,7 +97,7 @@ public function enableIf(bool | Closure $enabled = true): static
90
97
91
98
public function disableIf (Closure $ callback ): static
92
99
{
93
- return $ this ->enableif ((bool ) $ this ->evaluate ($ callback ));
100
+ return $ this ->enableIf ((bool ) $ this ->evaluate ($ callback ));
94
101
}
95
102
96
103
public function withoutWarning (): static
@@ -156,7 +163,6 @@ public function location(string $location = PanelsRenderHook::GLOBAL_SEARCH_BEFO
156
163
protected function isValidPanelHook (string $ location ): bool
157
164
{
158
165
static $ validLocations = null ;
159
-
160
166
if ($ validLocations === null ) {
161
167
$ reflection = new ReflectionClass (PanelsRenderHook::class);
162
168
$ validLocations = array_values ($ reflection ->getConstants ());
0 commit comments