Skip to content

Commit

Permalink
Merge pull request #2540 from digma-ai/remove-delay-in-protocol-command
Browse files Browse the repository at this point in the history
remove delay in protocol command
  • Loading branch information
shalom938 authored Sep 25, 2024
2 parents 5455de3 + c1b1c78 commit 220c55e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import com.intellij.openapi.components.Service
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.project.Project
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withTimeout
import org.digma.intellij.plugin.common.DisposableAdaptor
import org.digma.intellij.plugin.errorreporting.ErrorReporter
import org.digma.intellij.plugin.log.Log
Expand All @@ -23,14 +25,21 @@ class DigmaProtocolApi(val cs: CoroutineScope) : DisposableAdaptor {

private val logger: Logger = Logger.getInstance(this::class.java)

private var mainAppInitialized = false

fun setMainAppInitialized() {
mainAppInitialized = true
Log.log(logger::trace, "main app initialized , thread={}", Thread.currentThread().name)
}


/**
* return null on success.
* error message on failure
*/
fun performAction(project: Project, parameters: Map<String, String>, waitForJcef: Boolean): String? {
try {


val action = getActionFromParameters(parameters) ?: return "DigmaProtocolCommand no action in request"

Log.log(logger::trace, "perform action {}, thread {}", action, Thread.currentThread().name)
Expand Down Expand Up @@ -75,8 +84,9 @@ class DigmaProtocolApi(val cs: CoroutineScope) : DisposableAdaptor {
}

cs.launch {

if (waitForJcef) {
delay(5000)
waitForJcef()
}

val scope = SpanScope(codeObjectId)
Expand All @@ -90,13 +100,32 @@ class DigmaProtocolApi(val cs: CoroutineScope) : DisposableAdaptor {

private fun showAssetTab(project: Project, action: String, waitForJcef: Boolean): String? {
cs.launch {

if (waitForJcef) {
delay(5000)
waitForJcef()
}

project.messageBus.syncPublisher(ProtocolCommandEvent.PROTOCOL_COMMAND_TOPIC).protocolCommand(action)
}
return null
}


private suspend fun waitForJcef() {

try {
withTimeout(5000) {
while (!mainAppInitialized) {
delay(100)
}
}

} catch (e: TimeoutCancellationException) {
//ignore
}

//wait another second , it seems to be necessary to let jcef completely initialize
delay(1000)
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.digma.intellij.plugin.ui.mainapp

import com.fasterxml.jackson.databind.JsonNode
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import org.cef.browser.CefBrowser
import org.digma.intellij.plugin.analytics.AnalyticsServiceException
import org.digma.intellij.plugin.log.Log
import org.digma.intellij.plugin.protocol.DigmaProtocolApi
import org.digma.intellij.plugin.ui.assets.AssetsMessageRouterHandler
import org.digma.intellij.plugin.ui.errors.ErrorsMessageRouterHandler
import org.digma.intellij.plugin.ui.highlights.HighlightsMessageRouterHandler
Expand Down Expand Up @@ -66,6 +68,7 @@ class MainAppMessageRouterHandler(project: Project) : BaseMessageRouterHandler(p
} catch (e: AnalyticsServiceException) {
Log.warnWithException(logger, e, "error getting backend info")
}
project.service<DigmaProtocolApi>().setMainAppInitialized()
}

}

0 comments on commit 220c55e

Please sign in to comment.