Skip to content

Commit 1fa18ed

Browse files
authored
feat: add JCEF reload action (#8711)
* fix bug: set the property JS_QUERY_POOL_SIZE to use JBCefJSQuery after the browser has been created * feat: add JCEF reload action * fix: update reload action * Revert "fix bug: set the property JS_QUERY_POOL_SIZE to use JBCefJSQuery after the browser has been created" This reverts commit e998ae8.
1 parent c3cab90 commit 1fa18ed

File tree

3 files changed

+88
-7
lines changed

3 files changed

+88
-7
lines changed

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/actions/ContinuePluginActions.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ package com.github.continuedev.continueintellijextension.actions
22

33
import com.github.continuedev.continueintellijextension.HighlightedCodePayload
44
import com.github.continuedev.continueintellijextension.RangeInFileWithContents
5+
import com.github.continuedev.continueintellijextension.browser.ContinueBrowserService
56
import com.github.continuedev.continueintellijextension.browser.ContinueBrowserService.Companion.getBrowser
67
import com.github.continuedev.continueintellijextension.editor.DiffStreamService
78
import com.github.continuedev.continueintellijextension.editor.EditorUtils
89
import com.github.continuedev.continueintellijextension.services.ContinuePluginService
910
import com.intellij.openapi.actionSystem.AnAction
1011
import com.intellij.openapi.actionSystem.AnActionEvent
1112
import com.intellij.openapi.actionSystem.PlatformDataKeys
13+
import com.intellij.openapi.application.ApplicationManager
1214
import com.intellij.openapi.components.service
1315
import com.intellij.openapi.fileEditor.FileEditorManager
1416
import com.intellij.openapi.project.Project
17+
import com.intellij.openapi.wm.ToolWindowManager
1518
import java.io.File
1619

1720
class RestartContinueProcess : AnAction() {
@@ -89,6 +92,39 @@ class OpenConfigAction : ContinueToolbarAction() {
8992
}
9093
}
9194

95+
class ReloadBrowserAction: ContinueToolbarAction() {
96+
override fun toolbarActionPerformed(project: Project) {
97+
val toolWindow = ToolWindowManager.getInstance(project).getToolWindow("Continue")
98+
?: return
99+
val browserService = project.service<ContinueBrowserService>()
100+
101+
// Perform the reload and UI update on the Event Dispatch Thread
102+
ApplicationManager.getApplication().invokeLater {
103+
// Reload the browser service to get a new browser instance
104+
browserService.reload()
105+
106+
val newBrowser = project.getBrowser() ?: return@invokeLater
107+
val newBrowserComponent = newBrowser.getComponent()
108+
109+
val contentManager = toolWindow.contentManager
110+
contentManager.removeAllContents(true)
111+
112+
val newContent = contentManager.factory.createContent(
113+
newBrowserComponent,
114+
null,
115+
false
116+
)
117+
contentManager.addContent(newContent)
118+
contentManager.setSelectedContent(newContent, true) // Request focus
119+
120+
toolWindow.activate({
121+
// After activation, ensure the browser's input field gets focus
122+
newBrowser.focusOnInput()
123+
}, true)
124+
}
125+
}
126+
}
127+
92128
class OpenLogsAction : AnAction() {
93129
override fun actionPerformed(e: AnActionEvent) {
94130
val project = e.project ?: return

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/browser/ContinueBrowserService.kt

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,59 @@
11
package com.github.continuedev.continueintellijextension.browser
22

33
import com.intellij.openapi.Disposable
4+
import com.intellij.openapi.application.ApplicationManager
45
import com.intellij.openapi.components.Service
56
import com.intellij.openapi.components.service
67
import com.intellij.openapi.project.Project
78
import com.intellij.openapi.util.Disposer
89
import com.intellij.ui.jcef.JBCefApp
910

1011
@Service(Service.Level.PROJECT)
11-
class ContinueBrowserService(project: Project): Disposable {
12+
class ContinueBrowserService(val project: Project): Disposable {
1213

13-
private val browser: ContinueBrowser? =
14-
if (JBCefApp.isSupported())
15-
ContinueBrowser(project)
16-
else null
14+
private var browser: ContinueBrowser? = null
15+
16+
init {
17+
load()
18+
}
1719

1820
override fun dispose() {
19-
if (browser != null)
20-
Disposer.dispose(browser)
21+
browser?.let { Disposer.dispose(it) }
22+
browser = null
23+
}
24+
25+
private fun load(): ContinueBrowser? {
26+
if (browser != null) {
27+
return browser
28+
}
29+
if (!JBCefApp.isSupported()) {
30+
return null
31+
}
32+
val newBrowser = ContinueBrowser(project)
33+
Disposer.register(this, newBrowser)
34+
35+
this.browser = newBrowser
36+
return this.browser
37+
}
38+
39+
/**
40+
* Reloads the browser by disposing the current one and creating a new one.
41+
* This method is intended for use when browser is frozen (unresponsive).
42+
*/
43+
fun reload() {
44+
// Store the old browser instance to be disposed later
45+
val oldBrowser = browser
46+
browser = null
47+
48+
// Dispose the old browser after the new one is loaded and UI is updated.
49+
// This avoids race conditions. We can do this on a background thread.
50+
oldBrowser?.let {
51+
ApplicationManager.getApplication().invokeLater {
52+
Disposer.dispose(it)
53+
}
54+
}
55+
56+
load()
2157
}
2258

2359
companion object {

extensions/intellij/src/main/resources/META-INF/plugin.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@
155155
<override-text place="GoToAction" text="Settings"/>
156156
</action>
157157

158+
<action id="continue.reloadPage"
159+
class="com.github.continuedev.continueintellijextension.actions.ReloadBrowserAction"
160+
icon="AllIcons.Actions.Refresh"
161+
text="Reload Continue Browser"
162+
description="Reload Continue Browser">
163+
<override-text place="GoToAction" text="Reload Continue Browser"/>
164+
</action>
165+
158166
<action id="continue.openLogs"
159167
class="com.github.continuedev.continueintellijextension.actions.OpenLogsAction"
160168
icon="AllIcons.General.ShowInfos"
@@ -167,6 +175,7 @@
167175
<reference ref="continue.newContinueSession"/>
168176
<reference ref="continue.viewHistory"/>
169177
<reference ref="continue.openConfigPage"/>
178+
<reference ref="continue.reloadPage" />
170179
</group>
171180

172181
<action id="continue.focusContinueInput"

0 commit comments

Comments
 (0)