Check if app is loaded

Answered

Hi,

I'm creating a ToolWindow which requires parsing PsiFile and looking into idicies.

This I solved by moving that logic into ReadAction:

ReadAction.nonBlocking<JComponent> { ...parsePsi }
            .finishOnUiThread(ModalityState.defaultModalityState()) {
                val content = ContentFactory.getInstance().createContent(it, null, false)
                contentManager.addContent(content)
            }
            .submit(AppExecutorUtil.getAppExecutorService())

Which works fine, problem is that at start-up I get an Exception

SEVERE - #c.i.d.LoadingState - Should be called at least in the state COMPONENTS_LOADED, the current state is: CONFIGURATION_STORE_INITIALIZED

But I don't know how to check if app is already loaded and I can run this code… LoadingState by itself is marked as ApiInternal so I cannot use that.

I tried something like

if (!ApplicationManager.getApplication().isActive) return@withContext

but that doesn't work is app is likely active before IDEA is fully loaded?

0
2 comments

Where exactly do you execute this code? Please don't do it in CTOR.

0

Not sure what CTOR is, it's initially called from ToolWindowFactory

class TscnScenePreviewWindowFactory(private val coroutineScope: CoroutineScope) : ToolWindowFactory {

    override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
        toolWindow.setIcon(TscnIcon.TOOL_WINDOW_ICON)
        TscnScenePreviewWindow(project, toolWindow, coroutineScope)
    }

}

 

TscnScenePreviewWindow Handle rendering of ToolWindow content depending on currently selected file.

Getting current virtual file I've copy-paste more or less from StructureViewWindow (but some parts are marked as InternalApi so can't do it 1:1), but initial call is inside contructor:

Disposer.register(toolWindow.contentManager, this)
coroutineScope.launch {
    rebuildRequests.debounce {
        when (it) {
            RebuildDelay.NOW -> 0L
            RebuildDelay.QUEUE -> 100
        }
    }
            .collectLatest {
                rebuildImpl()
            }
}

 

where rebuildImpl is the one calling code in initial post

0

Please sign in to leave a comment.