-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(go): fix go icons when go plugin is installed (#158)
- Loading branch information
Showing
5 changed files
with
50 additions
and
1 deletion.
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
41 changes: 41 additions & 0 deletions
41
src/main/kotlin/com/github/catppuccin/jetbrains_icons/patcher/GoIconPatcher.kt
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,41 @@ | ||
package com.github.catppuccin.jetbrains_icons.patcher | ||
|
||
import com.github.catppuccin.jetbrains_icons.settings.PluginSettingsState | ||
import com.intellij.openapi.util.IconLoader | ||
import com.intellij.openapi.util.IconPathPatcher | ||
import kotlinx.coroutines.sync.Mutex | ||
import kotlinx.coroutines.sync.withLock | ||
|
||
class GoIconPatcher : IconPathPatcher() { | ||
|
||
private val settingsInstance = PluginSettingsState.instance | ||
|
||
// Only patch the path if Go support is enabled | ||
override fun patchPath(path: String, classLoader: ClassLoader?): String? = | ||
if (settingsInstance.goSupport && overrideMap.containsKey(path)) { | ||
"/jetbrains_icons/icons/${settingsInstance.variant}${overrideMap[path]}" | ||
} else { | ||
null | ||
} | ||
|
||
override fun getContextClassLoader( | ||
path: String, | ||
originalClassLoader: ClassLoader?, | ||
): ClassLoader? = javaClass.classLoader | ||
|
||
companion object { | ||
private val isInstalledMutex = Mutex() | ||
private var isInstalled = false | ||
|
||
suspend fun install() = | ||
isInstalledMutex.withLock { | ||
if (!isInstalled) { | ||
isInstalled = true | ||
IconLoader.installPathPatcher(GoIconPatcher()) | ||
} | ||
} | ||
|
||
private val overrideMap: Map<String, String> = | ||
mapOf("/icons/expui/[email protected]" to "_go.svg", "/icons/runTest.svg" to "_go.svg") | ||
} | ||
} |
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
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
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