@@ -38,6 +38,9 @@ class Rime :
38
38
override var schemaItemCached = SchemaItem (" .default" )
39
39
private set
40
40
41
+ override var inputStatusCached = InputStatus ()
42
+ private set
43
+
41
44
private val dispatcher =
42
45
RimeDispatcher (
43
46
object : RimeDispatcher .RimeLooper {
@@ -153,13 +156,28 @@ class Rime :
153
156
}
154
157
}
155
158
159
+ private fun handleRimeResponse (response : RimeResponse ) {
160
+ if (response.status != null ) {
161
+ val (item, status) =
162
+ response.status.run {
163
+ SchemaItem (schemaId, schemaName) to
164
+ InputStatus (isDisabled, isComposing, isAsciiMode, isFullShape, isSimplified, isTraditional, isAsciiPunch)
165
+ }
166
+ inputStatusCached = status
167
+ if (item != schemaItemCached) {
168
+ schemaItemCached = item
169
+ }
170
+ }
171
+ }
172
+
156
173
fun startup (fullCheck : Boolean ) {
157
174
if (lifecycle.currentStateFlow.value != RimeLifecycle .State .STOPPED ) {
158
175
Timber .w(" Skip starting rime: not at stopped state!" )
159
176
return
160
177
}
161
178
if (appContext.isStorageAvailable()) {
162
179
registerRimeNotificationHandler(::handleRimeNotification)
180
+ registerRimeResponseHandler(::handleRimeResponse)
163
181
lifecycleImpl.emitState(RimeLifecycle .State .STARTING )
164
182
dispatcher.start(fullCheck)
165
183
}
@@ -179,6 +197,7 @@ class Rime :
179
197
}
180
198
lifecycleImpl.emitState(RimeLifecycle .State .STOPPED )
181
199
unregisterRimeNotificationHandler(::handleRimeNotification)
200
+ unregisterRimeResponseHandler(::handleRimeResponse)
182
201
}
183
202
184
203
companion object {
@@ -198,6 +217,8 @@ class Rime :
198
217
199
218
private val notificationHandlers = ArrayList < (RimeNotification <* >) -> Unit > ()
200
219
220
+ private val responseHandlers = ArrayList < (RimeResponse ) -> Unit > ()
221
+
201
222
init {
202
223
System .loadLibrary(" rime_jni" )
203
224
}
@@ -492,5 +513,14 @@ class Rime :
492
513
Timber .d(" Got Rime response: $response " )
493
514
responseFlow_.tryEmit(response)
494
515
}
516
+
517
+ private fun registerRimeResponseHandler (handler : (RimeResponse ) -> Unit ) {
518
+ if (responseHandlers.contains(handler)) return
519
+ responseHandlers.add(handler)
520
+ }
521
+
522
+ private fun unregisterRimeResponseHandler (handler : (RimeResponse ) -> Unit ) {
523
+ responseHandlers.remove(handler)
524
+ }
495
525
}
496
526
}
0 commit comments