-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4251262
commit 22566a8
Showing
2 changed files
with
61 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.mallowigi.icons | ||
|
||
import com.intellij.util.SVGLoader | ||
import java.net.URL | ||
import java.util.Optional | ||
|
||
typealias PatcherProvider = SVGLoader.SvgElementColorPatcherProvider | ||
|
||
object SvgLoaderHacker { | ||
|
||
private lateinit var collectedPatcherProvider: PatcherProvider | ||
|
||
@JvmStatic | ||
fun collectOtherPatcher(): PatcherProvider = | ||
extractPatcher() | ||
.filter { it is PatcherProvider } | ||
.filter { it !is TintedIconsComponent.TintedColorPatcher } | ||
.map { | ||
val otherPatcher = it as PatcherProvider | ||
collectedPatcherProvider = otherPatcher | ||
otherPatcher | ||
} | ||
.orElseGet { useFallBackPatcher() } | ||
|
||
private fun extractPatcher() = Optional.ofNullable( | ||
SVGLoader::class.java.declaredFields | ||
.firstOrNull { it.name == "ourColorPatcher" } | ||
) | ||
.map { ourColorPatcherField -> | ||
ourColorPatcherField.isAccessible = true | ||
ourColorPatcherField.get(null) | ||
} | ||
|
||
|
||
private val noOpPatcherProvider = | ||
object : PatcherProvider { | ||
override fun forURL(url: URL?): SVGLoader.SvgElementColorPatcher? = null | ||
} | ||
|
||
private fun useFallBackPatcher(): PatcherProvider = | ||
if (this::collectedPatcherProvider.isInitialized) collectedPatcherProvider | ||
else noOpPatcherProvider | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters