Skip to content

Commit a03ec12

Browse files
committed
refactor: add STOPPING state for RimeLifecycle
Notify subscribers before the engine is about to stop that the engine is about to stop instead of being in a ready state.
1 parent b1daf38 commit a03ec12

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

app/src/main/java/com/osfans/trime/core/Rime.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,13 @@ class Rime : RimeApi, RimeLifecycleOwner {
138138
Timber.w("Skip stopping rime: not at ready state!")
139139
return
140140
}
141-
dispatcher.stop()
141+
lifecycleImpl.emitState(RimeLifecycle.State.STOPPING)
142+
Timber.i("Rime finalize()")
143+
dispatcher.stop().let {
144+
if (it.isNotEmpty()) {
145+
Timber.w("${it.size} job(s) didn't get a chance to run!")
146+
}
147+
}
142148
lifecycleImpl.emitState(RimeLifecycle.State.STOPPED)
143149
unregisterRimeNotificationHandler(::handleRimeNotification)
144150
}

app/src/main/java/com/osfans/trime/core/RimeLifecycle.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ class RimeLifecycleImpl : RimeLifecycle {
3434
checkAtState(RimeLifecycle.State.STARTING)
3535
internalStateFlow.value = RimeLifecycle.State.READY
3636
}
37-
RimeLifecycle.State.STOPPED -> {
37+
RimeLifecycle.State.STOPPING -> {
3838
checkAtState(RimeLifecycle.State.READY)
39+
internalStateFlow.value = RimeLifecycle.State.STOPPING
40+
}
41+
RimeLifecycle.State.STOPPED -> {
42+
checkAtState(RimeLifecycle.State.STOPPING)
3943
internalStateFlow.value = RimeLifecycle.State.STOPPED
4044
}
4145
}
@@ -53,6 +57,7 @@ interface RimeLifecycle {
5357
enum class State {
5458
STARTING,
5559
READY,
60+
STOPPING,
5661
STOPPED,
5762
}
5863
}

0 commit comments

Comments
 (0)