|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace JeroenNoten\LaravelAdminLte\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use JeroenNoten\LaravelAdminLte\Events\DarkModeWasToggled; |
|
6
|
|
|
|
|
7
|
|
|
class DarkModeController extends Controller |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* The key to use for save dark mode status on the session. |
|
11
|
|
|
* |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $sessionKey = 'adminlte_dark_mode'; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Toggle the dark mode status. |
|
18
|
|
|
* |
|
19
|
|
|
* @return void |
|
20
|
|
|
*/ |
|
21
|
|
|
public function toggle() |
|
22
|
|
|
{ |
|
23
|
|
|
// Store the new darkmode status on the session. This way, we can keep |
|
24
|
|
|
// the dark mode preference over multiple requests. |
|
25
|
|
|
|
|
26
|
|
|
session([$this->sessionKey => ! $this->isEnabled()]); |
|
27
|
|
|
|
|
28
|
|
|
// Trigger an event to notify this situation. This way, an user may |
|
29
|
|
|
// catch the new dark mode status and update the preference on a |
|
30
|
|
|
// database or another tool to persist data. |
|
31
|
|
|
|
|
32
|
|
|
event(new DarkModeWasToggled($this)); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Check if the dark mode is currently enabled or not. |
|
37
|
|
|
* |
|
38
|
|
|
* @return bool |
|
39
|
|
|
*/ |
|
40
|
12 |
|
public function isEnabled() |
|
41
|
|
|
{ |
|
42
|
|
|
// First, check if dark mode status was previously saved on the session. |
|
43
|
|
|
|
|
44
|
12 |
|
if (! is_null(session($this->sessionKey, null))) { |
|
45
|
|
|
return session($this->sessionKey); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
// Otherwise, fallback to the default package configuration value. |
|
49
|
|
|
|
|
50
|
12 |
|
return (bool) config('adminlte.layout_dark_mode', false); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Enables the dark mode. |
|
55
|
|
|
* |
|
56
|
|
|
* @return void |
|
57
|
|
|
*/ |
|
58
|
|
|
public function enable() |
|
59
|
|
|
{ |
|
60
|
|
|
session([$this->sessionKey => true]); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Disables the dark mode. |
|
65
|
|
|
* |
|
66
|
|
|
* @return void |
|
67
|
|
|
*/ |
|
68
|
|
|
public function disable() |
|
69
|
|
|
{ |
|
70
|
|
|
session([$this->sessionKey => false]); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|