Skip to content

Commit

Permalink
Praize Linter & Compiler.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unthrottled committed Dec 31, 2023
1 parent 0da0eeb commit 2f2c20b
Show file tree
Hide file tree
Showing 92 changed files with 1,636 additions and 1,453 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ intellij {
plugins.set(
properties("platformPlugins").split(',')
.map(String::trim)
.filter(String::isNotEmpty)
.filter(String::isNotEmpty),
)
}

Expand Down
2 changes: 1 addition & 1 deletion detekt-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ formatting:
active: false
autoCorrect: false
Indentation:
active: true
active: false
autoCorrect: false
indentSize: 2
ParameterListWrapping:
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/io/unthrottled/doki/TheDokiTheme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TheDokiTheme : Disposable {
.map { it.toOptional() }
.orElseGet {
PluginManagerCore.getPlugin(
PluginId.getId(ULTIMATE_PLUGIN_ID)
PluginId.getId(ULTIMATE_PLUGIN_ID),
).toOptional()
}
.map { it.version }
Expand All @@ -73,7 +73,7 @@ class TheDokiTheme : Disposable {
setSVGColorPatcher(it)
}
}
}
},
)

connection.subscribe(
Expand All @@ -89,7 +89,7 @@ class TheDokiTheme : Disposable {
IconPathReplacementComponent.removePatchers()
LookAndFeelInstaller.removeIcons()
}
}
},
)
}

Expand Down Expand Up @@ -118,7 +118,7 @@ class TheDokiTheme : Disposable {
UpdateNotification.display(
project,
version,
isNewUser
isNewUser,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import io.unthrottled.doki.config.ThemeConfig
import io.unthrottled.doki.settings.actors.BackgroundActor

class BackgroundToggleAction : BaseToggleAction() {
override fun isSelected(e: AnActionEvent): Boolean =
ThemeConfig.instance.isDokiBackground
override fun isSelected(e: AnActionEvent): Boolean = ThemeConfig.instance.isDokiBackground

override fun setSelected(e: AnActionEvent, state: Boolean) {
override fun setSelected(
e: AnActionEvent,
state: Boolean,
) {
BackgroundActor.handleBackgroundUpdate(state)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import io.unthrottled.doki.discreet.toDiscreetMode
import io.unthrottled.doki.settings.actors.DiscreetModeActor

class DiscreetModeAction : BaseToggleAction() {
override fun isSelected(e: AnActionEvent): Boolean =
ThemeConfig.instance.discreetMode
override fun isSelected(e: AnActionEvent): Boolean = ThemeConfig.instance.discreetMode

override fun setSelected(e: AnActionEvent, state: Boolean) {
override fun setSelected(
e: AnActionEvent,
state: Boolean,
) {
DiscreetModeActor.dispatchDiscreetMode(state.toDiscreetMode())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import io.unthrottled.doki.settings.actors.StickerHideActor
class HideOnHoverAction : BaseToggleAction(), DumbAware {
override fun isSelected(e: AnActionEvent): Boolean = ThemeConfig.instance.hideOnHover

override fun setSelected(e: AnActionEvent, state: Boolean) {
override fun setSelected(
e: AnActionEvent,
state: Boolean,
) {
StickerHideActor.setStickerHideStuff(
state,
ThemeConfig.instance.hideDelayMS
ThemeConfig.instance.hideDelayMS,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import io.unthrottled.doki.config.ThemeConfig
import io.unthrottled.doki.settings.actors.MoveableStickerActor

class MoveableStickerToggleAction : BaseToggleAction() {
override fun isSelected(e: AnActionEvent): Boolean =
ThemeConfig.instance.isMoveableStickers
override fun isSelected(e: AnActionEvent): Boolean = ThemeConfig.instance.isMoveableStickers

override fun setSelected(e: AnActionEvent, state: Boolean) {
override fun setSelected(
e: AnActionEvent,
state: Boolean,
) {
MoveableStickerActor.moveableStickers(state)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class ShowSettingsAction : AnAction(), DumbAware {
{
ShowSettingsUtil.getInstance().showSettingsDialog(
ProjectManager.getInstance().defaultProject,
THEME_SETTINGS_DISPLAY_NAME
THEME_SETTINGS_DISPLAY_NAME,
)
},
ModalityState.NON_MODAL
ModalityState.NON_MODAL,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import io.unthrottled.doki.TheDokiTheme
import io.unthrottled.doki.notification.UpdateNotification

class ShowUpdateNotification : AnAction(), DumbAware {

override fun actionPerformed(e: AnActionEvent) {
TheDokiTheme.getVersion()
.ifPresent {
UpdateNotification.display(
e.project!!,
it,
false
false,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import io.unthrottled.doki.settings.actors.StickerActor
import io.unthrottled.doki.stickers.StickerLevel.ON

class StickersToggleAction : BaseToggleAction() {
override fun isSelected(e: AnActionEvent): Boolean =
ThemeConfig.instance.currentStickerLevel == ON
override fun isSelected(e: AnActionEvent): Boolean = ThemeConfig.instance.currentStickerLevel == ON

override fun setSelected(e: AnActionEvent, state: Boolean) {
override fun setSelected(
e: AnActionEvent,
state: Boolean,
) {
StickerActor.enableStickers(state)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import io.unthrottled.doki.settings.actors.StickerActor
import io.unthrottled.doki.stickers.CurrentSticker

class SwapStickerAction : BaseToggleAction() {
override fun isSelected(e: AnActionEvent): Boolean =
ThemeConfig.instance.currentSticker == CurrentSticker.SECONDARY
override fun isSelected(e: AnActionEvent): Boolean = ThemeConfig.instance.currentSticker == CurrentSticker.SECONDARY

override fun setSelected(e: AnActionEvent, state: Boolean) {
override fun setSelected(
e: AnActionEvent,
state: Boolean,
) {
StickerActor.swapStickers(if (state) CurrentSticker.SECONDARY else CurrentSticker.DEFAULT)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import io.unthrottled.doki.config.ThemeConfig
import io.unthrottled.doki.settings.actors.LafAnimationActor

class ThemeAnimationToggle : BaseToggleAction() {
override fun isSelected(e: AnActionEvent): Boolean =
ThemeConfig.instance.isLafAnimation
override fun isSelected(e: AnActionEvent): Boolean = ThemeConfig.instance.isLafAnimation

override fun setSelected(e: AnActionEvent, state: Boolean) {
override fun setSelected(
e: AnActionEvent,
state: Boolean,
) {
LafAnimationActor.enableAnimation(state)
}
}
62 changes: 37 additions & 25 deletions src/main/kotlin/io/unthrottled/doki/assets/AssetManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import java.util.Optional
import java.util.concurrent.Callable

enum class AssetCategory(val category: String) {
STICKERS("stickers"), BACKGROUNDS("backgrounds"),
STICKERS("stickers"),
BACKGROUNDS("backgrounds"),
PROMOTION("promotion"),
MISC("misc")
MISC("misc"),
}

object HttpClientFactory {
Expand All @@ -41,7 +42,10 @@ object AssetManager {
* file:// url to the local asset. If it was not able to get the asset then it
* will return empty if the asset is not available locally.
*/
fun resolveAssetUrl(assetCategory: AssetCategory, assetPath: String): Optional<String> =
fun resolveAssetUrl(
assetCategory: AssetCategory,
assetPath: String,
): Optional<String> =
cachedResolve(assetCategory, assetPath, ASSET_SOURCE)
.map { it.toOptional() }
.orElseGet {
Expand All @@ -52,7 +56,10 @@ object AssetManager {
* Works just like <code>resolveAssetUrl</code> except that it will always
* download the remote asset.
*/
fun forceResolveAssetUrl(assetCategory: AssetCategory, assetPath: String): Optional<String> =
fun forceResolveAssetUrl(
assetCategory: AssetCategory,
assetPath: String,
): Optional<String> =
forceResolve(assetCategory, assetPath, ASSET_SOURCE)
.map { it.toOptional() }
.orElseGet {
Expand All @@ -62,7 +69,7 @@ object AssetManager {
private fun cachedResolve(
assetCategory: AssetCategory,
assetPath: String,
assetSource: String
assetSource: String,
): Optional<String> =
resolveAsset(assetCategory, assetPath, assetSource) { localAssetPath, remoteAssetUrl ->
resolveTheAssetUrl(localAssetPath, remoteAssetUrl)
Expand All @@ -71,7 +78,7 @@ object AssetManager {
private fun forceResolve(
assetCategory: AssetCategory,
assetPath: String,
assetSource: String
assetSource: String,
): Optional<String> =
resolveAsset(assetCategory, assetPath, assetSource) { localAssetPath, remoteAssetUrl ->
downloadAndGetAssetUrl(localAssetPath, remoteAssetUrl)
Expand All @@ -81,29 +88,34 @@ object AssetManager {
assetCategory: AssetCategory,
assetPath: String,
assetSource: String,
resolveAsset: (Path, String) -> Optional<String>
resolveAsset: (Path, String) -> Optional<String>,
): Optional<String> =
constructLocalAssetPath(assetCategory, assetPath)
.toOptional()
.flatMap {
val remoteAssetUrl = constructRemoteAssetUrl(
assetCategory,
assetPath,
assetSource
)
val remoteAssetUrl =
constructRemoteAssetUrl(
assetCategory,
assetPath,
assetSource,
)
resolveAsset(it, remoteAssetUrl)
}

private fun constructRemoteAssetUrl(
assetCategory: AssetCategory,
assetPath: String,
assetSource: String
): String = when (assetCategory) {
AssetCategory.STICKERS -> "$assetSource/${assetCategory.category}/jetbrains/v2$assetPath"
else -> "$assetSource/${assetCategory.category}/$assetPath"
}
assetSource: String,
): String =
when (assetCategory) {
AssetCategory.STICKERS -> "$assetSource/${assetCategory.category}/jetbrains/v2$assetPath"
else -> "$assetSource/${assetCategory.category}/$assetPath"
}

private fun resolveTheAssetUrl(localAssetPath: Path, remoteAssetUrl: String): Optional<String> =
private fun resolveTheAssetUrl(
localAssetPath: Path,
remoteAssetUrl: String,
): Optional<String> =
when {
hasAssetChanged(localAssetPath, remoteAssetUrl) ->
downloadAndGetAssetUrl(localAssetPath, remoteAssetUrl)
Expand All @@ -114,30 +126,30 @@ object AssetManager {

fun constructLocalAssetPath(
assetCategory: AssetCategory,
assetPath: String
assetPath: String,
): Path =
Paths.get(
getLocalAssetDirectory(),
assetCategory.category,
assetPath
assetPath,
).normalize().toAbsolutePath()

fun constructGlobalAssetPath(
assetCategory: AssetCategory,
assetPath: String
assetPath: String,
): Optional<Path> =
getGlobalAssetDirectory()
.map {
Paths.get(
it,
assetCategory.category,
assetPath
assetPath,
)
}

private fun downloadAndGetAssetUrl(
localAssetPath: Path,
remoteAssetUrl: String
remoteAssetUrl: String,
): Optional<String> {
createDirectories(localAssetPath)
return ApplicationManager.getApplication().executeOnPooledThread(
Expand All @@ -146,13 +158,13 @@ object AssetManager {
Files.newOutputStream(
localAssetPath,
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING
StandardOpenOption.TRUNCATE_EXISTING,
).use { bufferedWriter ->
IOUtils.copy(inputStream, bufferedWriter)
}
localAssetPath.toUri().toString()
}
}
},
).get()
}
}
Loading

0 comments on commit 2f2c20b

Please sign in to comment.