Skip to content

Commit

Permalink
Update theme natively instead of via agent
Browse files Browse the repository at this point in the history
  • Loading branch information
abeatrix committed Aug 19, 2024
1 parent 0190ac5 commit 5f6565e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/main/kotlin/com/sourcegraph/cody/ui/CodyToolWindowFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ class WebUIProxy(private val host: WebUIHost, private val browser: JBCefBrowserB
document.addEventListener('DOMContentLoaded', () => {
${viewToHost.inject("JSON.stringify({what:'DOMContentLoaded'})")}
});
document.documentElement.dataset.ide = 'JetBrains';
"""
.trimIndent()
browser.jbCefClient.addRequestHandler(
Expand Down Expand Up @@ -493,14 +495,13 @@ class WebUIProxy(private val host: WebUIHost, private val browser: JBCefBrowserB
val code =
"""
(() => {
let e = new CustomEvent('message');
e.data = {
type: 'ui/theme',
agentIDE: 'JetBrains',
cssVariables: ${gson.toJson(theme.variables)},
isDark: ${theme.isDark}
};
window.dispatchEvent(e);
// Script to add css variables directly to the document
document.documentElement.style = ''; // Clear all existing CSS variables.
const rootStyle = document.documentElement.style
const cssVariables = ${gson.toJson(theme.variables)}
for (const [name, value] of Object.entries(cssVariables || {})) {
rootStyle.setProperty(name, value)
}
})()
"""
.trimIndent()
Expand Down

0 comments on commit 5f6565e

Please sign in to comment.