@@ -4,68 +4,6 @@ import { service } from "@ember/service";
4
4
import { tracked } from "@glimmer/tracking" ;
5
5
import { keyResponder , onKey } from "ember-keyboard" ;
6
6
7
- const getHtml = ( ) => document . querySelector ( "html" ) ;
8
-
9
- const COLOR_SCHEME_KEY = "color-scheme" ;
10
- const THEME_KEY = "theme" ;
11
-
12
- /**
13
- * Sets dark or light mode
14
- * @param {"light" | "dark" } colorScheme
15
- * @param {ReturnType<getHtml> } html
16
- **/
17
- const setColorScheme = ( colorScheme , html = null ) => {
18
- const _html = html ?? getHtml ( ) ;
19
- localStorage . setItem ( COLOR_SCHEME_KEY , colorScheme ) ;
20
-
21
- if ( colorScheme === "light" ) {
22
- _html . classList . remove ( "dark" ) ;
23
- return ;
24
- }
25
- _html . classList . add ( "dark" ) ;
26
- } ;
27
-
28
- const THEMES = /** @type {const } */ ( [ "old" , "regular" ] ) ;
29
-
30
- /**
31
- * Sets regular or old color scheme
32
- * @param {typeof THEMES[number] } theme
33
- * @param {ReturnType<getHtml> } html
34
- **/
35
- const setTheme = ( theme , html = null ) => {
36
- const _html = html ?? getHtml ( ) ;
37
- localStorage . setItem ( THEME_KEY , theme ) ;
38
-
39
- if ( _html . classList . contains ( theme ) ) {
40
- return ;
41
- }
42
- _html . classList . remove ( ...THEMES . filter ( ( t ) => t !== theme ) ) ;
43
- _html . classList . add ( theme ) ;
44
- } ;
45
-
46
- const loadConfiguration = ( ) => {
47
- const colorScheme =
48
- localStorage . getItem ( COLOR_SCHEME_KEY ) ??
49
- ( window . matchMedia ( "(prefers-color-scheme:dark)" ) . matches
50
- ? "dark"
51
- : "light" ) ;
52
- const theme = localStorage . getItem ( THEME_KEY ) ?? THEMES [ 0 ] ;
53
- const html = getHtml ( ) ;
54
- setTheme ( theme , html ) ;
55
- setColorScheme ( colorScheme , html ) ;
56
- } ;
57
-
58
- const toggleColorScheme = ( ) =>
59
- setColorScheme (
60
- localStorage . getItem ( COLOR_SCHEME_KEY ) === "dark" ? "light" : "dark" ,
61
- ) ;
62
-
63
- const cycleTheme = ( ) => {
64
- const currentTheme = localStorage . getItem ( THEME_KEY ) ;
65
- const newTheme = THEMES [ THEMES . indexOf ( currentTheme ) + 1 ] ?? THEMES [ 0 ] ;
66
- setTheme ( newTheme ) ;
67
- } ;
68
-
69
7
@keyResponder
70
8
export default class ProtectedController extends Controller {
71
9
@service notify ;
@@ -74,6 +12,7 @@ export default class ProtectedController extends Controller {
74
12
@service currentUser ;
75
13
@service ( "autostart-tour" ) autostartTour ;
76
14
@service tour ;
15
+ @service appearance ;
77
16
78
17
@tracked visible ;
79
18
@tracked loading ;
@@ -141,18 +80,18 @@ export default class ProtectedController extends Controller {
141
80
142
81
constructor ( ...args ) {
143
82
super ( ...args ) ;
144
- loadConfiguration ( ) ;
83
+ this . appearance . loadConfiguration ( ) ;
145
84
}
146
85
147
86
@onKey ( "ctrl+," )
148
87
_toggleColorScheme ( e ) {
149
88
e . preventDefault ( ) ;
150
- toggleColorScheme ( ) ;
89
+ this . appearance . toggleColorScheme ( ) ;
151
90
}
152
91
153
92
@onKey ( "ctrl+." )
154
93
_cycleTheme ( e ) {
155
94
e . preventDefault ( ) ;
156
- cycleTheme ( ) ;
95
+ this . appearance . cycleTheme ( ) ;
157
96
}
158
97
}
0 commit comments