Skip to content
Open
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 @@ -2,6 +2,7 @@ package com.github.continuedev.continueintellijextension.actions

import com.github.continuedev.continueintellijextension.HighlightedCodePayload
import com.github.continuedev.continueintellijextension.RangeInFileWithContents
import com.github.continuedev.continueintellijextension.browser.ContinueBrowserService
import com.github.continuedev.continueintellijextension.browser.ContinueBrowserService.Companion.getBrowser
import com.github.continuedev.continueintellijextension.editor.DiffStreamService
import com.github.continuedev.continueintellijextension.editor.EditorUtils
Expand All @@ -12,6 +13,7 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys
import com.intellij.openapi.components.service
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindowManager
import java.io.File

class RestartContinueProcess : AnAction() {
Expand Down Expand Up @@ -89,6 +91,32 @@ class OpenConfigAction : ContinueToolbarAction() {
}
}

class ReloadBrowserAction: ContinueToolbarAction() {
override fun toolbarActionPerformed(project: Project) {
val toolWindow = ToolWindowManager.getInstance(project).getToolWindow("Continue")
?: return
val contentManager = toolWindow.contentManager
val browserService = project.service<ContinueBrowserService>()
browserService.reload()

val newBrowser = project.getBrowser() ?: return
val newBrowserComponent = newBrowser.getComponent()

contentManager.removeAllContents(true)
val newContent = contentManager.factory.createContent(
newBrowserComponent,
null,
false
)

contentManager.addContent(newContent)

contentManager.setSelectedContent(newContent)

toolWindow.activate(null)
}
}

class OpenLogsAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import javax.swing.JComponent
class ContinueBrowser(private val project: Project): Disposable {

private val log = Logger.getInstance(ContinueBrowser::class.java.simpleName)
private val browser: JBCefBrowser = JBCefBrowser.createBuilder().setOffScreenRendering(true).build()
private val myJBCefClient: JBCefClient = JBCefApp.getInstance().createClient().apply {
setProperty(JBCefClient.Properties.JS_QUERY_POOL_SIZE, 200)
}
private val browser: JBCefBrowser = JBCefBrowser.createBuilder().setOffScreenRendering(true).setClient(myJBCefClient).build()
private val myJSQueryOpenInBrowser = JBCefJSQuery.create(browser as JBCefBrowserBase)

init {
CefApp.getInstance().registerSchemeHandlerFactory("http", "continue", CustomSchemeHandlerFactory())
browser.jbCefClient.setProperty(JBCefClient.Properties.JS_QUERY_POOL_SIZE, 200)
myJSQueryOpenInBrowser.addHandler { msg: String? ->
val json = Gson().fromJson(msg, BrowserMessage::class.java)
val messageType = json.messageType
Expand Down Expand Up @@ -104,6 +106,7 @@ class ContinueBrowser(private val project: Project): Disposable {
override fun dispose() {
Disposer.dispose(myJSQueryOpenInBrowser)
Disposer.dispose(browser)
Disposer.dispose(myJBCefClient)
}

// todo: remove and use types.Message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,44 @@ import com.intellij.openapi.util.Disposer
import com.intellij.ui.jcef.JBCefApp

@Service(Service.Level.PROJECT)
class ContinueBrowserService(project: Project): Disposable {
class ContinueBrowserService(val project: Project): Disposable {

private val browser: ContinueBrowser? =
if (JBCefApp.isSupported())
ContinueBrowser(project)
else null
private var browser: ContinueBrowser? = null

init {
load()
}

override fun dispose() {
if (browser != null)
Disposer.dispose(browser)
browser?.let { Disposer.dispose(it) }
browser = null
}

private fun load(): ContinueBrowser? {
if (browser != null) {
return browser
}
if (!JBCefApp.isSupported()) {
return null
}
val newBrowser = ContinueBrowser(project)
Disposer.register(this, newBrowser)

this.browser = newBrowser
return this.browser
}

/**
* Reloads the browser by disposing the current one and creating a new one.
* This method is intended for use when browser is frozen (unresponsive).
*/
fun reload() {
browser?.let {
Disposer.dispose(it)
}
browser = null

load()
}

companion object {
Expand Down
9 changes: 9 additions & 0 deletions extensions/intellij/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@
<override-text place="GoToAction" text="Settings"/>
</action>

<action id="continue.reloadPage"
class="com.github.continuedev.continueintellijextension.actions.ReloadBrowserAction"
icon="AllIcons.Actions.Refresh"
text="Reload Continue Browser"
description="Reload Continue Browser">
<override-text place="GoToAction" text="Reload Continue Browser"/>
</action>

<action id="continue.openLogs"
class="com.github.continuedev.continueintellijextension.actions.OpenLogsAction"
icon="AllIcons.General.ShowInfos"
Expand All @@ -168,6 +176,7 @@
<reference ref="continue.newContinueSession"/>
<reference ref="continue.viewHistory"/>
<reference ref="continue.openConfigPage"/>
<reference ref="continue.reloadPage" />
</group>

<action id="continue.focusContinueInput"
Expand Down
Loading