File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -88,7 +88,10 @@ class AppStateManager(private val kodein: DKodein) {
8888 private var state: AppState = SETTINGS
8989
9090 fun startChat (): Unit = lock.withLock {
91- if (state != SETTINGS ) throw IllegalStateException (" Expected: $SETTINGS , actual: $state " )
91+ if (state != SETTINGS ) {
92+ throw IllegalStateException (" Expected: $SETTINGS , actual: $state " )
93+ }
94+ state = CHAT
9295
9396 val viewersCountLoaders: MutableList <ViewersCountLoader > = ArrayList ()
9497 val initializedChatClients: MutableMap <Origin , ChatClient > = enumMap()
@@ -206,7 +209,11 @@ class AppStateManager(private val kodein: DKodein) {
206209 }
207210
208211 fun stopChat (): Unit = lock.withLock {
209- if (state != CHAT ) throw IllegalStateException (" Expected: $CHAT , actual: $state " )
212+ if (state != CHAT ) {
213+ throw IllegalStateException (" Expected: $CHAT , actual: $state " )
214+ }
215+ state = SETTINGS
216+
210217 reset()
211218
212219 // Save config
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import failchat.chat.ChatMessageSender
66import failchat.util.LateinitVal
77import failchat.util.completedFuture
88import failchat.util.executeWithCatch
9+ import failchat.util.logException
910import javafx.application.Platform
1011import org.apache.commons.configuration2.Configuration
1112import java.util.concurrent.CompletableFuture
@@ -29,9 +30,11 @@ class FullGuiEventHandler(
2930 it.chatFrame.show()
3031 }
3132
32- guiTransitionFuture.whenCompleteAsync(BiConsumer { _, _ ->
33- appStateManager.startChat()
34- }, executor)
33+ guiTransitionFuture
34+ .whenCompleteAsync(BiConsumer { _, _ ->
35+ appStateManager.startChat()
36+ }, executor)
37+ .logException()
3538 }
3639
3740 override fun handleStopChat () {
@@ -40,9 +43,11 @@ class FullGuiEventHandler(
4043 it.settingsFrame.show()
4144 }
4245
43- guiTransitionFuture.whenCompleteAsync(BiConsumer { _, _ ->
44- appStateManager.stopChat()
45- }, executor)
46+ guiTransitionFuture
47+ .whenCompleteAsync(BiConsumer { _, _ ->
48+ appStateManager.stopChat()
49+ }, executor)
50+ .logException()
4651 }
4752
4853 override fun handleShutDown () {
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import mu.KotlinLogging
44import java.time.Duration
55import java.util.concurrent.CompletableFuture
66import java.util.concurrent.CompletionException
7+ import java.util.concurrent.CompletionStage
78import java.util.concurrent.ExecutionException
89import java.util.concurrent.TimeUnit
910
@@ -36,9 +37,9 @@ fun Throwable.completionCause(): Throwable {
3637
3738private class NullCompletionCauseException (e : CompletionException ) : Exception(e)
3839
39- fun <T > CompletableFuture <T>.logException () {
40+ fun <T > CompletionStage <T>.logException () {
4041 whenComplete { _, t ->
41- if (t != = null ) logger.error(" Unhandled exception from CompletableFuture " , t)
42+ if (t != = null ) logger.error(" Unhandled exception from CompletionStage " , t)
4243 }
4344}
4445
Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ class YoutubeChatClient(
6262 if (! statusChanged) {
6363 error(" Chat client status: ${atomicStatus.value} " )
6464 }
65+ logger.info { " Starting youtube client" }
6566
6667 val job = launch {
6768 val initialParameters = youtubeClient.getNewLiveChatSessionData(videoId)
@@ -109,6 +110,7 @@ class YoutubeChatClient(
109110 }
110111
111112 override fun stop () {
113+ logger.info { " Stopping youtube client" }
112114 cancel()
113115 atomicStatus.value = ChatClientStatus .OFFLINE
114116 }
You can’t perform that action at this time.
0 commit comments