Skip to content

Commit 47aae49

Browse files
committed
wip: done!
1 parent e958fee commit 47aae49

File tree

2 files changed

+110
-11
lines changed

2 files changed

+110
-11
lines changed

src/browser/pages/vscode.ts

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,48 @@ export function setBodyBackgroundToThemeBackgroundColor(document: Document, loca
103103
}
104104

105105
if (!localStorage) {
106-
throw new Error(`${errorMsgPrefix} Could not set body background to theme background color. localStorage is undefined.`)
106+
throw new Error(
107+
`${errorMsgPrefix} Could not set body background to theme background color. localStorage is undefined.`,
108+
)
107109
}
108110

109111
const colorThemeData = localStorage.getItem("colorThemeData")
110112

111113
if (!colorThemeData) {
112-
throw new Error(`${errorMsgPrefix} Could not set body background to theme background color. Could not find colorThemeData in localStorage.`)
114+
throw new Error(
115+
`${errorMsgPrefix} Could not set body background to theme background color. Could not find colorThemeData in localStorage.`,
116+
)
117+
}
118+
119+
let _colorThemeData
120+
try {
121+
// We wrap this JSON.parse logic in a try/catch
122+
// because it can throw if the JSON is invalid.
123+
// and instead of throwing a random error
124+
// we can throw our own error, which will be more helpful
125+
// to the end user.
126+
_colorThemeData = JSON.parse(colorThemeData)
127+
} catch {
128+
throw new Error(
129+
`${errorMsgPrefix} Could not set body background to theme background color. Could not parse colorThemeData from localStorage.`,
130+
)
131+
}
132+
133+
if (!_colorThemeData.hasOwnProperty("colorMap")) {
134+
throw new Error(
135+
`${errorMsgPrefix} Could not set body background to theme background color. colorThemeData is missing colorMap.`,
136+
)
137+
}
138+
139+
const editorBgColor = _colorThemeData.colorMap["editor.background"]
140+
141+
if (!editorBgColor) {
142+
throw new Error(
143+
`${errorMsgPrefix} Could not set body background to theme background color. colorThemeData.colorMap["editor.background"] is undefined.`,
144+
)
113145
}
114146

115-
// TODO parse colorThemeData
116-
// which may need try/catch
117-
// or not since we are catching when we call the function
118-
// TODO get editor.background
119-
// TODO set it to style.background
120-
// also read about when to set background vs backgroundColor
147+
document.body.style.background = editorBgColor
121148

122149
return null
123150
}

0 commit comments

Comments
 (0)