Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: changing the theme through short cut menu. #207

Merged
merged 6 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.smallcloud.refactai.panes.sharedchat
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.processTools.getResultStdoutStr
import com.intellij.ide.BrowserUtil
import com.intellij.ide.ui.LafManager
import com.intellij.ide.ui.LafManagerListener
import com.intellij.ide.ui.UISettings
import com.intellij.ide.ui.UISettingsListener
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.invokeLater
Expand Down Expand Up @@ -64,9 +64,6 @@ class SharedChatPane(val project: Project) : JPanel(), Disposable {
private val workerScheduler =
AppExecutorUtil.createBoundedScheduledExecutorService("SMCSharedChatPaneWorkerScheduler", 1)

private val uiChangeListener = LafManagerListener { _ ->
this.setLookAndFeel()
}

init {
workerFuture = workerScheduler.scheduleWithFixedDelay({
Expand All @@ -79,6 +76,7 @@ class SharedChatPane(val project: Project) : JPanel(), Disposable {
}
}, 0, 80, java.util.concurrent.TimeUnit.MILLISECONDS)
this.addEventListeners()

}

private fun isReady(): Boolean {
Expand Down Expand Up @@ -228,8 +226,12 @@ class SharedChatPane(val project: Project) : JPanel(), Disposable {
val ef = EditorFactory.getInstance()
ef.eventMulticaster.addSelectionListener(selectionListener, this)

ApplicationManager.getApplication().messageBus.connect(this).subscribe(LafManagerListener.TOPIC, uiChangeListener)

UISettings.getInstance().addUISettingsListener(
UISettingsListener {
ApplicationManager.getApplication().invokeLater {
[email protected]()
}
}, this)
// ast and vecdb settings change
project.messageBus.connect()
.subscribe(InferenceGlobalContextChangedNotifier.TOPIC, object : InferenceGlobalContextChangedNotifier {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ChatWebView(val editor: Editor, val messageHandler: (event: Events.FromCha

fun setStyle() {
val isDarkMode = LafManager.getInstance().currentUIThemeLookAndFeel.isDark

val mode = if (isDarkMode) {
"dark"
} else {
Expand All @@ -74,10 +75,12 @@ class ChatWebView(val editor: Editor, val messageHandler: (event: Events.FromCha
val green = backgroundColour.green
val blue = backgroundColour.blue
val webView = this.webView
println("bodyClass: ${bodyClass}")
CoroutineScope(Dispatchers.Default).launch {
webView.executeJavaScript("""document.body.style.setProperty("background-color", "rgb($red, $green, $blue");""")
webView.executeJavaScript("""document.body.class = "$bodyClass";""")
webView.executeJavaScript("""document.body.className = "$bodyClass";""")
webView.executeJavaScript("""document.documentElement.className = "$mode";""")
println("updated dom")
}
}

Expand Down Expand Up @@ -299,7 +302,7 @@ class ChatWebView(val editor: Editor, val messageHandler: (event: Events.FromCha
fun postMessage(message: Events.ToChat<*>?) {
if (message != null) {
val json = Events.stringify(message)
// println("post message json: $json")
logger.info("post message json: $json")
this.postMessage(json)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/webview/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

</style>
</head>
<body>
<body class="vscode-dark">
<div id="refact-chat"></div>
</body>
</html>
Loading