diff --git a/src/main/kotlin/io/unthrottled/doki/icon/ColorPatcher.kt b/src/main/kotlin/io/unthrottled/doki/icon/ColorPatcher.kt index 133cb94aa..3ba5f091e 100644 --- a/src/main/kotlin/io/unthrottled/doki/icon/ColorPatcher.kt +++ b/src/main/kotlin/io/unthrottled/doki/icon/ColorPatcher.kt @@ -3,7 +3,7 @@ package io.unthrottled.doki.icon import com.google.common.cache.Cache import com.google.common.cache.CacheBuilder import com.intellij.ide.ui.LafManager -import com.intellij.ide.ui.UITheme +import com.intellij.ide.ui.laf.UIThemeLookAndFeelInfo import com.intellij.ui.ColorUtil import com.intellij.ui.JBColor import com.intellij.ui.JBColor.namedColor @@ -21,6 +21,47 @@ import io.unthrottled.doki.util.toOptional import java.awt.Color import java.time.Duration +private fun buildThemeColorPatcher(themeLookAndFeel: UIThemeLookAndFeelInfo): SvgElementColorPatcherProvider? { + val themeLookAndFeelMethods = themeLookAndFeel.javaClass.methods + val themeGetter = themeLookAndFeelMethods.firstOrNull { method -> method.name == "getTheme" } + val theme = themeGetter?.invoke(themeLookAndFeel) + val themeClassMethods = theme?.javaClass?.methods ?: return null + val colorPatcherGetter = themeClassMethods.firstOrNull { method -> method.name == "getColorPatcher" } + val colorPatcherProvider = colorPatcherGetter?.invoke(theme) + val colorPatcherMethods = colorPatcherProvider?.javaClass?.methods ?: return null + val attr = colorPatcherMethods.firstOrNull { method -> method.name == "attributeForPath" } + val digest = colorPatcherMethods.firstOrNull { method -> method.name == "digest" } + return object : SvgElementColorPatcherProvider, Logging { + override fun attributeForPath(path: String): SvgAttributePatcher? = + runSafelyWithResult({ + val patcherForPath = attr?.invoke(colorPatcherProvider, path) ?: return@runSafelyWithResult null + val patchColorsMethod = + patcherForPath.javaClass + .methods.firstOrNull { method -> method.name == "patchColors" } ?: return@runSafelyWithResult null + object : SvgAttributePatcher { + override fun patchColors(attributes: MutableMap) { + runSafelyWithResult({ + patchColorsMethod.invoke(patcherForPath, attributes) + }) { patchingError -> + logger().warn("unable to patch colors", patchingError) + } + } + } + }) { + logger().warn("Unable to patch path for raisins", it) + null + } + + override fun digest(): LongArray = + runSafelyWithResult({ + digest?.invoke(colorPatcherProvider) as LongArray + }) { digestError -> + logger().warn("Unable to get digest", digestError) + longArrayOf() + } + } +} + object NoOptPatcher : SvgAttributePatcher { override fun patchColors(attributes: MutableMap) { } @@ -48,49 +89,10 @@ object ColorPatcher : SvgElementColorPatcherProvider { LafManager.getInstance() ?.currentUIThemeLookAndFeel.toOptional() .map { - it to it.javaClass.methods.firstOrNull { method -> method.name == "getTheme" } + buildThemeColorPatcher(it) } - .filter { it.second != null } .ifPresent { - val theme = ((it.second?.invoke(it.first)) as UITheme) - // todo fix - val themeClass = UITheme::class.java - val themeClassMethods = themeClass.methods - val attr = themeClassMethods.firstOrNull { method -> method.name == "attributeForPath" } - val digest = themeClassMethods.firstOrNull { method -> method.name == "digest" } - this.uiColorPatcherProvider = - object : SvgElementColorPatcherProvider, Logging { - override fun attributeForPath(path: String): SvgAttributePatcher? { - return runSafelyWithResult({ - val patcherForPath = attr?.invoke(digest, path) - val patchColorsMethod = - patcherForPath?.javaClass - ?.methods?.firstOrNull { method -> method.name == "patchColors" } - object : SvgAttributePatcher { - override fun patchColors(attributes: MutableMap) { - runSafelyWithResult({ - patchColorsMethod - ?.invoke(patcherForPath, attributes) - }) { patchingError -> - logger().warn("unable to patch colors", patchingError) - } - } - } - }) { - logger().warn("Unable to patch path for raisins", it) - null - } - } - - override fun digest(): LongArray { - return runSafelyWithResult({ - digest?.invoke(theme) as LongArray - }) { digestError -> - logger().warn("Unable to get digest", digestError) - longArrayOf() - } - } - } + this.uiColorPatcherProvider = it } clearCaches() } diff --git a/src/main/kotlin/io/unthrottled/doki/notification/UpdateNotification.kt b/src/main/kotlin/io/unthrottled/doki/notification/UpdateNotification.kt index 3dae12166..219ca0309 100644 --- a/src/main/kotlin/io/unthrottled/doki/notification/UpdateNotification.kt +++ b/src/main/kotlin/io/unthrottled/doki/notification/UpdateNotification.kt @@ -417,14 +417,6 @@ object UpdateNotification : Logging { } } - private val lastWorkingBuild = BuildNumber.fromString("212.5712.43") - - private fun needsToFixUpdateNotification(): Boolean { - val build = ApplicationInfoEx.getInstanceEx().build - return (lastWorkingBuild?.compareTo(build) ?: 0) < 0 && - WeebService.isBackgroundOn() - } - private fun buildUrl( isNewUser: Boolean, newVersion: String,