handle when the user runs the app instead of clicking on systemtray

This commit is contained in:
Aria Moradi 2021-05-19 17:38:33 +04:30
parent 326da504ea
commit e2c4b4cb57
2 changed files with 13 additions and 2 deletions

View File

@ -1,7 +1,10 @@
package ir.armor.tachidesk.server.util package ir.armor.tachidesk.server.util
import mu.KotlinLogging
import kotlin.system.exitProcess import kotlin.system.exitProcess
private val logger = KotlinLogging.logger {}
enum class ExitCode(val code: Int) { enum class ExitCode(val code: Int) {
Success(0), Success(0),
MutexCheckFailedTachideskRunning(1), MutexCheckFailedTachideskRunning(1),
@ -9,5 +12,7 @@ enum class ExitCode(val code: Int) {
} }
fun shutdownApp(exitCode: ExitCode) { fun shutdownApp(exitCode: ExitCode) {
logger.info("Shutting Down Tachidesk. Goodbye!")
exitProcess(exitCode.code) exitProcess(exitCode.code)
} }

View File

@ -59,11 +59,17 @@ object AppMutex {
logger.info("Mutex status is clear, Resuming startup.") logger.info("Mutex status is clear, Resuming startup.")
} }
TachideskInstanceRunning -> { TachideskInstanceRunning -> {
logger.info("Another instance of Tachidesk is running on $appIP:${serverConfig.port}, Aborting.") 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.")
openInBrowser()
logger.info("Aborting startup.")
shutdownApp(ExitCode.MutexCheckFailedTachideskRunning) shutdownApp(ExitCode.MutexCheckFailedTachideskRunning)
} }
OtherApplicationRunning -> { OtherApplicationRunning -> {
logger.error("A non Tachidesk application is running on $appIP:${serverConfig.port}, Aborting.") logger.error("A non Tachidesk application is running on $appIP:${serverConfig.port}, aborting startup.")
shutdownApp(ExitCode.MutexCheckFailedAnotherAppRunning) shutdownApp(ExitCode.MutexCheckFailedAnotherAppRunning)
} }
} }