1
1
package com.github.continuedev.continueintellijextension.toolWindow
2
2
3
3
import com.github.continuedev.continueintellijextension.activities.ContinuePluginDisposable
4
- import com.github.continuedev.continueintellijextension.constants.MessageTypes
5
4
import com.github.continuedev.continueintellijextension.constants.MessageTypes.Companion.PASS_THROUGH_TO_CORE
6
5
import com.github.continuedev.continueintellijextension.factories.CustomSchemeHandlerFactory
7
6
import com.github.continuedev.continueintellijextension.services.ContinueExtensionSettings
@@ -10,11 +9,11 @@ import com.github.continuedev.continueintellijextension.utils.uuid
10
9
import com.google.gson.Gson
11
10
import com.google.gson.JsonObject
12
11
import com.google.gson.JsonParser
13
- import com.intellij.openapi.components.ServiceManager
14
12
import com.intellij.openapi.project.Project
15
13
import com.intellij.openapi.util.Disposer
16
14
import com.intellij.ui.jcef.*
17
15
import com.intellij.ui.jcef.JBCefClient.Properties
16
+ import com.intellij.util.application
18
17
import org.cef.CefApp
19
18
import org.cef.browser.CefBrowser
20
19
import org.cef.handler.CefLoadHandlerAdapter
@@ -30,8 +29,10 @@ class ContinueBrowser(val project: Project, url: String) {
30
29
31
30
val browser: JBCefBrowser
32
31
32
+ val continuePluginService: ContinuePluginService = project.getService(ContinuePluginService ::class .java)
33
+
33
34
init {
34
- val isOSREnabled = ServiceManager .getService(ContinueExtensionSettings ::class .java).continueState.enableOSR
35
+ val isOSREnabled = application .getService(ContinueExtensionSettings ::class .java).continueState.enableOSR
35
36
36
37
this .browser = JBCefBrowser .createBuilder().setOffScreenRendering(isOSREnabled).build().apply {
37
38
// To avoid using System.setProperty to affect other plugins,
@@ -42,7 +43,6 @@ class ContinueBrowser(val project: Project, url: String) {
42
43
}
43
44
44
45
registerAppSchemeHandler()
45
- browser.loadURL(url)
46
46
Disposer .register(ContinuePluginDisposable .getInstance(project), browser)
47
47
48
48
// Listen for events sent from browser
@@ -55,11 +55,6 @@ class ContinueBrowser(val project: Project, url: String) {
55
55
val data = json.get(" data" )
56
56
val messageId = json.get(" messageId" )?.asString
57
57
58
- val continuePluginService = ServiceManager .getService(
59
- project,
60
- ContinuePluginService ::class .java
61
- )
62
-
63
58
val respond = fun (data : Any? ) {
64
59
sendToWebview(messageType, data, messageId ? : uuid())
65
60
}
@@ -101,6 +96,13 @@ class ContinueBrowser(val project: Project, url: String) {
101
96
}
102
97
}, browser.cefBrowser)
103
98
99
+ // Load the url only after the protocolClient is initialized,
100
+ // otherwise some messages will be lost, which are some configurations when the page is loaded.
101
+ // Moreover, we should add LoadHandler before loading the url.
102
+ continuePluginService.onProtocolClientInitialized {
103
+ browser.loadURL(url)
104
+ }
105
+
104
106
}
105
107
106
108
fun executeJavaScript (browser : CefBrowser ? , myJSQueryOpenInBrowser : JBCefJSQuery ) {
0 commit comments