Skip to content

Commit

Permalink
mitigate white screen flashes for JB
Browse files Browse the repository at this point in the history
 Please enter the commit message for your changes. Lines starting
 with '#' will be ignored, and an empty message aborts the commit.

 interactive rebase in progress; onto 4ae0a41
 Last commands done (8 commands done):
    pick 659a2c4 ci(chat): get the chat assets from the main branch
    pick 781ea1c mitigate white screen flashes for JB
 Next command to do (1 remaining command):
    pick 22dab5b ci(chat): switch to alpha build
 You are currently rebasing branch 'chat-functions' on '4ae0a41'.

 Changes to be committed:
	modified:   src/main/kotlin/com/smallcloud/refactai/panes/sharedchat/ChatPanes.kt
	modified:   src/main/kotlin/com/smallcloud/refactai/panes/sharedchat/SharedChatPane.kt
	modified:   src/main/kotlin/com/smallcloud/refactai/panes/sharedchat/browser/ChatWebView.kt
  • Loading branch information
MarcMcIntosh committed Jul 4, 2024
1 parent 931c812 commit c5cf592
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ChatPanes(val project: Project, private val parent: Disposable) {

private fun restoreTab(item: ChatHistoryItem) {
val newPane = SharedChatPane(project)

val component: JComponent = newPane.webView.component
val info = TabInfo(component)
info.text = item.title ?: "Chat"
Expand Down Expand Up @@ -133,6 +134,7 @@ class ChatPanes(val project: Project, private val parent: Disposable) {
panes.select(info, true)



// val devToolsBrowser = JBCefBrowser.createBuilder()
// .setCefBrowser(newPane.webView.cefBrowser.devTools)
// .setClient(newPane.webView.jbCefClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.intellij.openapi.util.TextRange
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiDocumentManager
import com.intellij.testFramework.LightVirtualFile
import com.intellij.ui.components.JBLayeredPane
import com.intellij.util.concurrency.AppExecutorUtil
import com.intellij.util.ui.UIUtil
import com.smallcloud.refactai.io.InferenceGlobalContextChangedNotifier
Expand All @@ -30,10 +31,13 @@ import com.smallcloud.refactai.panes.sharedchat.Events.Editor
import com.smallcloud.refactai.panes.sharedchat.browser.ChatWebView
import com.smallcloud.refactai.settings.AppSettingsState
import org.jetbrains.annotations.NotNull
import java.awt.GridLayout
import java.beans.PropertyChangeListener
import java.util.concurrent.CompletableFuture
import java.util.concurrent.Future
import javax.swing.JComponent
import javax.swing.JPanel
import javax.swing.JTextPane
import javax.swing.UIManager


Expand Down Expand Up @@ -413,6 +417,7 @@ class SharedChatPane(val project: Project) : JPanel(), Disposable {
}
}


val webView by lazy {
browser.webView
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import javax.swing.JComponent
class ChatWebView(val messageHandler: (event: Events.FromChat) -> Unit): Disposable {
private val jsPoolSize = "200"

init {
System.setProperty("ide.browser.jcef.jsQueryPoolSize", jsPoolSize)
}
// init {
// System.setProperty("ide.browser.jcef.jsQueryPoolSize", jsPoolSize)
// }

fun setStyle() {
val isDarkMode = UIUtil.isUnderDarcula()
Expand All @@ -32,7 +32,20 @@ class ChatWebView(val messageHandler: (event: Events.FromChat) -> Unit): Dispos
}

val webView by lazy {
val browser = JBCefBrowser.createBuilder().setOffScreenRendering(false).build()
val osName = System.getProperty("os.name").lowercase()
val useOsr = when {
osName.contains("mac") || osName.contains("darwin") -> false
osName.contains("win") -> false
osName.contains("nix") || osName.contains("nux") || osName.contains("aix") -> true
else -> true
}

val browser = JBCefBrowser
.createBuilder()
.setUrl("http://refactai/index.html")
.setOffScreenRendering(useOsr)
.build()

browser.jbCefClient.setProperty(
JBCefClient.Properties.JS_QUERY_POOL_SIZE,
jsPoolSize,
Expand All @@ -41,7 +54,7 @@ class ChatWebView(val messageHandler: (event: Events.FromChat) -> Unit): Dispos

CefApp.getInstance().registerSchemeHandlerFactory("http", "refactai", RequestHandlerFactory())

browser.loadURL("http://refactai/index.html")


val myJSQueryOpenInBrowser = JBCefJSQuery.create((browser as JBCefBrowserBase?)!!)
myJSQueryOpenInBrowser.addHandler { msg ->
Expand Down Expand Up @@ -78,6 +91,8 @@ class ChatWebView(val messageHandler: (event: Events.FromChat) -> Unit): Dispos

}, browser.cefBrowser)

browser.createImmediately()

browser
}

Expand Down

0 comments on commit c5cf592

Please sign in to comment.