correct spelling

This commit is contained in:
Aria Moradi 2021-06-04 16:34:19 +04:30
parent b7fe56687c
commit 37eeef06e2

View File

@ -13,9 +13,6 @@ import okhttp3.OkHttpClient
import okhttp3.Request.Builder
import suwayomi.tachidesk.server.impl.AboutDataClass
import suwayomi.tachidesk.server.serverConfig
import suwayomi.tachidesk.server.util.AppMutex.AppMutexStat.Clear
import suwayomi.tachidesk.server.util.AppMutex.AppMutexStat.OtherApplicationRunning
import suwayomi.tachidesk.server.util.AppMutex.AppMutexStat.TachideskInstanceRunning
import suwayomi.tachidesk.server.util.Browser.openInBrowser
import suwayomi.tachidesk.server.util.ExitCode.MutexCheckFailedAnotherAppRunning
import suwayomi.tachidesk.server.util.ExitCode.MutexCheckFailedTachideskRunning
@ -25,7 +22,7 @@ import java.util.concurrent.TimeUnit
object AppMutex {
private val logger = KotlinLogging.logger {}
private enum class AppMutexStat(val stat: Int) {
private enum class AppMutexState(val stat: Int) {
Clear(0),
TachideskInstanceRunning(1),
OtherApplicationRunning(2)
@ -33,7 +30,7 @@ object AppMutex {
private val appIP = if (serverConfig.ip == "0.0.0.0") "127.0.0.1" else serverConfig.ip
private fun checkAppMutex(): AppMutexStat {
private fun checkAppMutex(): AppMutexState {
val client = OkHttpClient.Builder()
.connectTimeout(200, TimeUnit.MILLISECONDS)
.build()
@ -45,23 +42,23 @@ object AppMutex {
val response = try {
client.newCall(request).execute().use { response -> response.body!!.string() }
} catch (e: IOException) {
return AppMutexStat.Clear
return AppMutexState.Clear
}
return try {
JavalinJackson.fromJson(response, AboutDataClass::class.java)
AppMutexStat.TachideskInstanceRunning
AppMutexState.TachideskInstanceRunning
} catch (e: IOException) {
AppMutexStat.OtherApplicationRunning
AppMutexState.OtherApplicationRunning
}
}
fun handleAppMutex() {
when (checkAppMutex()) {
Clear -> {
AppMutexState.Clear -> {
logger.info("Mutex status is clear, Resuming startup.")
}
TachideskInstanceRunning -> {
AppMutexState.TachideskInstanceRunning -> {
logger.info("Another instance of Tachidesk is running on $appIP:${serverConfig.port}")
logger.info("Probably user thought tachidesk is closed so, opening webUI in browser again.")
@ -71,7 +68,7 @@ object AppMutex {
shutdownApp(MutexCheckFailedTachideskRunning)
}
OtherApplicationRunning -> {
AppMutexState.OtherApplicationRunning -> {
logger.error("A non Tachidesk application is running on $appIP:${serverConfig.port}, aborting startup.")
shutdownApp(MutexCheckFailedAnotherAppRunning)
}