diff --git a/src/main/kotlin/com/smallcloud/refactai/panes/sharedchat/SharedChatPane.kt b/src/main/kotlin/com/smallcloud/refactai/panes/sharedchat/SharedChatPane.kt index 5b648fc0..ae79d41e 100644 --- a/src/main/kotlin/com/smallcloud/refactai/panes/sharedchat/SharedChatPane.kt +++ b/src/main/kotlin/com/smallcloud/refactai/panes/sharedchat/SharedChatPane.kt @@ -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 @@ -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({ @@ -79,6 +76,7 @@ class SharedChatPane(val project: Project) : JPanel(), Disposable { } }, 0, 80, java.util.concurrent.TimeUnit.MILLISECONDS) this.addEventListeners() + } private fun isReady(): Boolean { @@ -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 { + this@SharedChatPane.setLookAndFeel() + } + }, this) // ast and vecdb settings change project.messageBus.connect() .subscribe(InferenceGlobalContextChangedNotifier.TOPIC, object : InferenceGlobalContextChangedNotifier { diff --git a/src/main/kotlin/com/smallcloud/refactai/panes/sharedchat/browser/ChatWebView.kt b/src/main/kotlin/com/smallcloud/refactai/panes/sharedchat/browser/ChatWebView.kt index f935fa62..740ce46e 100644 --- a/src/main/kotlin/com/smallcloud/refactai/panes/sharedchat/browser/ChatWebView.kt +++ b/src/main/kotlin/com/smallcloud/refactai/panes/sharedchat/browser/ChatWebView.kt @@ -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 { @@ -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") } } @@ -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) } } diff --git a/src/main/resources/webview/index.html b/src/main/resources/webview/index.html index 7873190c..6f3b9871 100644 --- a/src/main/resources/webview/index.html +++ b/src/main/resources/webview/index.html @@ -25,7 +25,7 @@ - +
\ No newline at end of file