Skip to content

Commit

Permalink
refactor: add STOPPING state for RimeLifecycle
Browse files Browse the repository at this point in the history
Notify subscribers before the engine is about to stop that the engine is about to stop instead of being in a ready state.
  • Loading branch information
WhiredPlanck committed Aug 19, 2024
1 parent b1daf38 commit a03ec12
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion app/src/main/java/com/osfans/trime/core/Rime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ class Rime : RimeApi, RimeLifecycleOwner {
Timber.w("Skip stopping rime: not at ready state!")
return
}
dispatcher.stop()
lifecycleImpl.emitState(RimeLifecycle.State.STOPPING)
Timber.i("Rime finalize()")
dispatcher.stop().let {
if (it.isNotEmpty()) {
Timber.w("${it.size} job(s) didn't get a chance to run!")
}
}
lifecycleImpl.emitState(RimeLifecycle.State.STOPPED)
unregisterRimeNotificationHandler(::handleRimeNotification)
}
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/com/osfans/trime/core/RimeLifecycle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ class RimeLifecycleImpl : RimeLifecycle {
checkAtState(RimeLifecycle.State.STARTING)
internalStateFlow.value = RimeLifecycle.State.READY
}
RimeLifecycle.State.STOPPED -> {
RimeLifecycle.State.STOPPING -> {
checkAtState(RimeLifecycle.State.READY)
internalStateFlow.value = RimeLifecycle.State.STOPPING
}
RimeLifecycle.State.STOPPED -> {
checkAtState(RimeLifecycle.State.STOPPING)
internalStateFlow.value = RimeLifecycle.State.STOPPED
}
}
Expand All @@ -53,6 +57,7 @@ interface RimeLifecycle {
enum class State {
STARTING,
READY,
STOPPING,
STOPPED,
}
}
Expand Down

0 comments on commit a03ec12

Please sign in to comment.