Changesets · Branches · Tags · Compare
| Changeset | a8496f39d35876df9821fc07c2167d94a5767614e1545d9653be3cfeab12e07d |
|---|---|
| Author | Jakub Blach <jakubblach@gmail.com> · 2025-09-04 17:21 +02:00 |
| Committer | Jakub Blach <jakubblach@gmail.com> · 2025-09-05 21:07 +02:00 |
| Parents | 80ec3503f561 |
2 files changed
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/browser/ContinueBrowser.kt +9 −3
| @@ -1,28 +1,29 @@ | ||
| 1 | 1 | package com.github.continuedev.continueintellijextension.browser |
| 2 | 2 | |
| 3 | 3 | import com.github.continuedev.continueintellijextension.constants.MessageTypes |
| 4 | -import com.github.continuedev.continueintellijextension.services.ContinueExtensionSettings | |
| 5 | 4 | import com.github.continuedev.continueintellijextension.services.ContinuePluginService |
| 6 | 5 | import com.github.continuedev.continueintellijextension.utils.uuid |
| 7 | 6 | import com.google.gson.Gson |
| 7 | +import com.intellij.openapi.Disposable | |
| 8 | 8 | import com.intellij.openapi.components.service |
| 9 | 9 | import com.intellij.openapi.diagnostic.Logger |
| 10 | 10 | import com.intellij.openapi.project.Project |
| 11 | +import com.intellij.openapi.util.Disposer | |
| 11 | 12 | import com.intellij.ui.jcef.* |
| 12 | 13 | import org.cef.CefApp |
| 13 | 14 | import org.cef.browser.CefBrowser |
| 14 | 15 | import org.cef.handler.CefLoadHandlerAdapter |
| 15 | 16 | import javax.swing.JComponent |
| 16 | 17 | |
| 17 | -class ContinueBrowser(private val project: Project) { | |
| 18 | +class ContinueBrowser(private val project: Project): Disposable { | |
| 18 | 19 | |
| 19 | 20 | private val log = Logger.getInstance(ContinueBrowser::class.java.simpleName) |
| 20 | 21 | private val browser: JBCefBrowser = JBCefBrowser.createBuilder().setOffScreenRendering(true).build() |
| 22 | + private val myJSQueryOpenInBrowser = JBCefJSQuery.create(browser as JBCefBrowserBase) | |
| 21 | 23 | |
| 22 | 24 | init { |
| 23 | 25 | CefApp.getInstance().registerSchemeHandlerFactory("http", "continue", CustomSchemeHandlerFactory()) |
| 24 | 26 | browser.jbCefClient.setProperty(JBCefClient.Properties.JS_QUERY_POOL_SIZE, 200) |
| 25 | - val myJSQueryOpenInBrowser = JBCefJSQuery.create(browser as JBCefBrowserBase) | |
| 26 | 27 | myJSQueryOpenInBrowser.addHandler { msg: String? -> |
| 27 | 28 | val json = Gson().fromJson(msg, BrowserMessage::class.java) |
| 28 | 29 | val messageType = json.messageType |
| @@ -100,6 +101,11 @@ | ||
| 100 | 101 | browser.cefBrowser.executeJavaScript(script, getGuiUrl(), 0) |
| 101 | 102 | } |
| 102 | 103 | |
| 104 | + override fun dispose() { | |
| 105 | + Disposer.dispose(myJSQueryOpenInBrowser) | |
| 106 | + Disposer.dispose(browser) | |
| 107 | + } | |
| 108 | + | |
| 103 | 109 | // todo: remove and use types.Message |
| 104 | 110 | private data class BrowserMessage( |
| 105 | 111 | val messageType: String, |
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/browser/ContinueBrowserService.kt +13 −3
| @@ -1,22 +1,32 @@ | ||
| 1 | 1 | package com.github.continuedev.continueintellijextension.browser |
| 2 | 2 | |
| 3 | +import com.intellij.openapi.Disposable | |
| 3 | 4 | import com.intellij.openapi.components.Service |
| 4 | 5 | import com.intellij.openapi.components.service |
| 5 | 6 | import com.intellij.openapi.project.Project |
| 7 | +import com.intellij.openapi.util.Disposer | |
| 6 | 8 | import com.intellij.ui.jcef.JBCefApp |
| 7 | 9 | |
| 8 | 10 | @Service(Service.Level.PROJECT) |
| 9 | -class ContinueBrowserService(project: Project) { | |
| 11 | +class ContinueBrowserService(project: Project): Disposable { | |
| 10 | 12 | |
| 11 | 13 | private val browser: ContinueBrowser? = |
| 12 | 14 | if (JBCefApp.isSupported()) |
| 13 | 15 | ContinueBrowser(project) |
| 14 | 16 | else null |
| 15 | 17 | |
| 18 | + override fun dispose() { | |
| 19 | + if (browser != null) | |
| 20 | + Disposer.dispose(browser) | |
| 21 | + } | |
| 22 | + | |
| 16 | 23 | companion object { |
| 17 | 24 | |
| 18 | - fun Project.getBrowser() = | |
| 19 | - service<ContinueBrowserService>().browser | |
| 25 | + fun Project.getBrowser(): ContinueBrowser? { | |
| 26 | + if (isDisposed) | |
| 27 | + return null | |
| 28 | + return service<ContinueBrowserService>().browser | |
| 29 | + } | |
| 20 | 30 | |
| 21 | 31 | } |
| 22 | 32 | } |