1
1
import { getOptions , Options } from "../../common/util"
2
2
import "../register"
3
3
4
- const options = getOptions ( )
5
-
6
- // TODO: Add proper types.
7
- /* eslint-disable @typescript-eslint/no-explicit-any */
4
+ // TODO@jsjoeio : Add proper types.
5
+ type FixMeLater = any
8
6
9
7
// NOTE@jsjoeio
10
8
// This lives here ../../../lib/vscode/src/vs/base/common/platform.ts#L106
@@ -19,7 +17,7 @@ type NlsConfiguration = {
19
17
_resolvedLanguagePackCoreLocation ?: string
20
18
_corruptedFile ?: string
21
19
_languagePackSupport ?: boolean
22
- loadBundle ?: any
20
+ loadBundle ?: FixMeLater
23
21
}
24
22
25
23
/**
@@ -114,40 +112,9 @@ export function getLoader({ origin, nlsConfig, options }: GetLoaderParams) {
114
112
return loader
115
113
}
116
114
117
- try {
118
- const nlsConfig = getNlsConfiguration ( document )
119
- if ( nlsConfig . _resolvedLanguagePackCoreLocation ) {
120
- const bundles = Object . create ( null )
121
- nlsConfig . loadBundle = ( bundle : any , _language : any , cb : any ) : void => {
122
- const result = bundles [ bundle ]
123
- if ( result ) {
124
- return cb ( undefined , result )
125
- }
126
- // FIXME: Only works if path separators are /.
127
- const path = nlsConfig . _resolvedLanguagePackCoreLocation + "/" + bundle . replace ( / \/ / g, "!" ) + ".nls.json"
128
- fetch ( `${ options . base } /vscode/resource/?path=${ encodeURIComponent ( path ) } ` )
129
- . then ( ( response ) => response . json ( ) )
130
- . then ( ( json ) => {
131
- bundles [ bundle ] = json
132
- cb ( undefined , json )
133
- } )
134
- . catch ( cb )
135
- }
136
- }
137
- // TODO@jsjoeio
138
- // I'm not sure how to properly type cast this
139
- // This might be our best bet
140
- // Source: https://stackoverflow.com/a/30740935
141
- type FixMeLater = any
142
- ; ( self . require as FixMeLater ) = getLoader ( {
143
- nlsConfig,
144
- options,
145
- origin : window . location . origin ,
146
- } )
147
- } catch ( error ) {
148
- console . error ( error )
149
- }
150
-
115
+ /**
116
+ * Sets the body background color to match the theme.
117
+ */
151
118
export function setBodyBackgroundToThemeBackgroundColor ( document : Document , localStorage : Storage ) {
152
119
const errorMsgPrefix = "[vscode]"
153
120
@@ -204,8 +171,44 @@ export function setBodyBackgroundToThemeBackgroundColor(document: Document, loca
204
171
}
205
172
206
173
try {
174
+ const options = getOptions ( )
175
+ const nlsConfig = getNlsConfiguration ( document )
176
+
177
+ if ( nlsConfig . _resolvedLanguagePackCoreLocation ) {
178
+ const bundles = Object . create ( null )
179
+
180
+ nlsConfig . loadBundle = ( bundle : FixMeLater , _language : FixMeLater , cb : FixMeLater ) : void => {
181
+ const result = bundles [ bundle ]
182
+ if ( result ) {
183
+ return cb ( undefined , result )
184
+ }
185
+ // FIXME: Only works if path separators are /.
186
+ const path = nlsConfig . _resolvedLanguagePackCoreLocation + "/" + bundle . replace ( / \/ / g, "!" ) + ".nls.json"
187
+ fetch ( `${ options . base } /vscode/resource/?path=${ encodeURIComponent ( path ) } ` )
188
+ . then ( ( response ) => response . json ( ) )
189
+ . then ( ( json ) => {
190
+ bundles [ bundle ] = json
191
+ cb ( undefined , json )
192
+ } )
193
+ . catch ( cb )
194
+ }
195
+ }
196
+
197
+ const loader = getLoader ( {
198
+ nlsConfig,
199
+ options,
200
+ origin : window . location . origin ,
201
+ } )
202
+
203
+ // TODO@jsjoeio
204
+ // I'm not sure how to properly type cast this
205
+ // This might be our best bet
206
+ // Source: https://stackoverflow.com/a/30740935
207
+ // This object on self.require is what configures the loader
208
+ // and tells it how to load files that get imported.
209
+ ; ( self . require as FixMeLater ) = loader
210
+
207
211
setBodyBackgroundToThemeBackgroundColor ( document , localStorage )
208
212
} catch ( error ) {
209
- console . error ( "Something went wrong setting the body background to the theme background color." )
210
213
console . error ( error )
211
214
}
0 commit comments