Actual way to invalidate icons in ProjectView

Hello, I’m developing a plugin, and one of the functionalities is to update the default file icon to a custom one. I want to make this feature configurable with a runtime switch.

I found some old answers, but looks like this not working.

https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000186210-Refresh-icons-in-ProjectView

https://intellij-support.jetbrains.com/hc/en-us/community/posts/206144129-Need-to-refresh-tree-in-ProjectView

Some example how it looks like.

I use IconProvider to customize icons

class ImageVectorIconProvider :
    IconProvider(),
    DumbAware {

    override fun getIcon(element: PsiElement, flags: Int): Icon? {
        val ktFile = when (element) {
            is KtFile -> element
            is PsiFile -> null
            else -> element.containingFile as? KtFile
        } ?: return null

        val showIconsInProjectView = ktFile.project.persistentSettings.state.showIconsInProjectView

        if (!showIconsInProjectView || !ktFile.hasImageVectorProperties()) {
            return null
        }

        return ktFile.getOrCreateCachedIcon()
    }
}

Some code that I tried:

val project = LocalProject.current

...
ApplicationManager.getApplication().invokeLater {
    if (!project.current.isDisposed) {
        val view = ProjectView.getInstance(project.current)
        view.refresh()

        view.currentProjectViewPane.updateFromRoot(true)
    }
}
...

It may work once, but then it does not invalidate icons at all.