Skip to content

Commit

Permalink
Added log file opening, preservation of config on re-installation.
Browse files Browse the repository at this point in the history
  • Loading branch information
acidicoala committed Feb 18, 2023
1 parent 387146b commit 93c2032
Show file tree
Hide file tree
Showing 17 changed files with 331 additions and 230 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ bin/
.vscode/

### Mac OS ###
.DS_Store
.DS_Store

## Seems to me a bug to unzip into the project root dir
/wix**

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {

val author = "acidicoala"
val projectName = "Koalageddon"
val appVersion = "2.0.0"
val appVersion = "2.0.1"

group = author
version = appVersion
Expand Down Expand Up @@ -48,7 +48,7 @@ kotlin {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")

// https://github.com/kosi-libs/Kodein
implementation("org.kodein.di:kodein-di-framework-compose:7.16.0")
implementation("org.kodein.di:kodein-di-framework-compose:7.18.0")

// https://github.com/harawata/appdirs
implementation("net.harawata:appdirs:1.2.1")
Expand All @@ -57,15 +57,15 @@ kotlin {
implementation("org.slf4j:slf4j-api:2.0.6")

// https://github.com/tinylog-org/tinylog
val tinylogVersion = "2.5.0"
val tinylogVersion = "2.6.0"
implementation("org.tinylog:tinylog-impl:$tinylogVersion")
implementation("org.tinylog:slf4j-tinylog:$tinylogVersion")

// https://github.com/dorkbox/PeParser
implementation("com.dorkbox:PeParser:3.1")

// https://github.com/ktorio/ktor
val ktorVersion = "2.2.2"
val ktorVersion = "2.2.3"
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-cio:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kotlin.code.style=official
kotlin.version=1.7.20
compose.version=1.2.2
kotlin.version=1.8.0
compose.version=1.3.0
kotlin.mpp.stability.nowarn=true
1 change: 1 addition & 0 deletions rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# Tinylog <-> SLF4J bridge
-keep class org.tinylog.** { *; }
-keep class org.slf4j.** { *; }

# Java native access
# Source: https://github.com/java-native-access/jna/issues/1187#issuecomment-626251894
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class AppPaths {

fun getUnlockerConfig(unlocker: KoalaTool) = getUnlockerDir(unlocker) / unlocker.configName

fun getUnlockerLog(unlocker: KoalaTool) = getUnlockerDir(unlocker) / unlocker.logName

fun getUnlockerDll(unlocker: KoalaTool) = getUnlockerDir(unlocker) / "${unlocker.name}.dll"

fun getCacheAsset(filename: String) = cacheDir / filename
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ sealed class KoalaTool(
val majorVersion: Int
) {
val configName = "$name.config.json"
val logName = "$name.log.log"
val homePage = "https://github.com/acidicoala/$name#readme"
val gitHubReleaseUrl = "https://api.github.com/repos/acidicoala/$name/releases"

Expand Down
34 changes: 18 additions & 16 deletions src/jvmMain/kotlin/acidicoala/koalageddon/core/model/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ data class Settings constructor(
langTag.startsWith("de", ignoreCase = true) -> Language.German
langTag.startsWith("it", ignoreCase = true) -> Language.Italian
langTag.startsWith("ru", ignoreCase = true) -> Language.Russian
langTag.startsWith("pt", ignoreCase = true) -> Language.Brazilian_Portuguese
langTag.startsWith("pt", ignoreCase = true) -> Language.BrazilianPortuguese
langTag.startsWith("zh", ignoreCase = true) -> Language.SimplifiedChinese
langTag.startsWith("tr", ignoreCase = true) -> Language.Turkish
else -> Language.English
Expand All @@ -38,39 +38,41 @@ data class Settings constructor(
}
}

// Languages are sorted according to their ISO 639-1 code

@Serializable
enum class Language(val locale: Locale) : ILangString {
English(Locale.ENGLISH) {
override fun text(strings: Strings) = strings.languageEn
},
German(Locale.GERMAN) {
German(Locale("de")) {
override fun text(strings: Strings) = strings.languageDe
},
Italian(Locale.ITALIAN) {
English(Locale("en")) {
override fun text(strings: Strings) = strings.languageEn
},
Italian(Locale("it")) {
override fun text(strings: Strings) = strings.languageIt
},
BrazilianPortuguese(Locale("pt", "BR")) {
override fun text(strings: Strings) = strings.languagePtBr
},
Russian(Locale("ru")) {
override fun text(strings: Strings) = strings.languageRu
},
Brazilian_Portuguese(Locale("pt")) {
override fun text(strings: Strings) = strings.languagePt_BR
},
SimplifiedChinese(Locale.SIMPLIFIED_CHINESE) {
override fun text(strings: Strings) = strings.languageCHS
},
Turkish(Locale("tr")) {
override fun text(strings: Strings) = strings.languageTr
}
},
SimplifiedChinese(Locale("zh", "CN")) {
override fun text(strings: Strings) = strings.languageZhCn
},
}

@Transient
val strings = when (language) {
Language.English -> Strings.English
Language.German -> Strings.German
Language.English -> Strings.English
Language.Italian -> Strings.Italian
Language.BrazilianPortuguese -> Strings.BrazilianPortuguese
Language.Russian -> Strings.Russian
Language.Brazilian_Portuguese -> Strings.Brazilian_Portuguese
Language.SimplifiedChinese -> Strings.SimplifiedChinese
Language.Turkish -> Strings.Turkish
Language.SimplifiedChinese -> Strings.SimplifiedChinese
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,40 @@ package acidicoala.koalageddon.core.ui.composable

import acidicoala.koalageddon.core.model.ILangString
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.width
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.dp

@Composable
fun <T : ILangString> DropdownButton(
selected: T,
items: Array<T>,
onSelect: (T) -> Unit,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
icon: ImageVector? = null,
) {
var dropdownExpanded by remember { mutableStateOf(false) }

Box(modifier) {
Button(
onClick = { dropdownExpanded = !dropdownExpanded },
) {
if (icon != null) {
Icon(
imageVector = icon,
contentDescription = null,
modifier = Modifier.align(Alignment.CenterVertically)
)

Spacer(Modifier.width(8.dp))
}

Text(text = selected.text)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@ package acidicoala.koalageddon.core.ui.composable

import acidicoala.koalageddon.core.model.ILangString
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.vector.ImageVector

@Composable
fun <T : ILangString> DropdownOption(label: String, items: Array<T>, selected: T, onSelect: (T) -> Unit) {
fun <T : ILangString> DropdownOption(
label: String,
items: Array<T>,
selected: T,
onSelect: (T) -> Unit,
icon: ImageVector? = null,
) {
ControlOption(label) {
DropdownButton(
selected = selected,
items = items,
onSelect = onSelect,
icon = icon,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ class ModifyInstallationStatus(override val di: DI) : DIAware {
destination = paths.getUnlockerDll(unlocker),
)

unlocker.writeConfig(path = paths.getUnlockerConfig(unlocker), unlocker.defaultConfig)
// Ensure that config file exists
try {
unlocker.parseConfig(paths.getUnlockerConfig(unlocker))
} catch (e: Exception) {
unlocker.writeConfig(path = paths.getUnlockerConfig(unlocker), unlocker.defaultConfig)
}
}

private fun uninstall(store: Store) = channelFlow<ILangString> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package acidicoala.koalageddon.core.use_case

import acidicoala.koalageddon.core.logging.AppLogger
import acidicoala.koalageddon.core.model.LangString
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import org.kodein.di.DI
import org.kodein.di.DIAware
import org.kodein.di.instance
Expand All @@ -10,16 +13,34 @@ import java.nio.file.Path

class OpenResourceLink(override val di: DI) : DIAware {
private val logger: AppLogger by instance()
private val showSnackbar: ShowSnackbar by instance()
private val scope: CoroutineScope by instance()

operator fun invoke(path: Path) {
logger.debug("Opening directory in explorer: $path")
try {
logger.debug("Opening file/directory in explorer: $path")

Desktop.getDesktop().open(path.toFile())
Desktop.getDesktop().open(path.toFile())
} catch (e: Exception) {
logger.error(e, "Error opening file/directory in explorer")

scope.launch {
showSnackbar(LangString { error })
}
}
}

operator fun invoke(uri: URI) {
logger.debug("Opening uri: $uri")
try {
logger.debug("Opening URI: $uri")

Desktop.getDesktop().browse(uri)
} catch (e: Exception) {
logger.error(e, "Error opening URI")

Desktop.getDesktop().browse(uri)
scope.launch {
showSnackbar(LangString { error })
}
}
}
}
Loading

0 comments on commit 93c2032

Please sign in to comment.