Skip to content

Commit fe9c39d

Browse files
committed
fix: couldn't smart match the keyboard corresponding to the schema id
feat(core): add inputStatusCached to new api interface
1 parent 90a7960 commit fe9c39d

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class Rime :
3838
override var schemaItemCached = SchemaItem(".default")
3939
private set
4040

41+
override var inputStatusCached = InputStatus()
42+
private set
43+
4144
private val dispatcher =
4245
RimeDispatcher(
4346
object : RimeDispatcher.RimeLooper {
@@ -153,13 +156,28 @@ class Rime :
153156
}
154157
}
155158

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+
156173
fun startup(fullCheck: Boolean) {
157174
if (lifecycle.currentStateFlow.value != RimeLifecycle.State.STOPPED) {
158175
Timber.w("Skip starting rime: not at stopped state!")
159176
return
160177
}
161178
if (appContext.isStorageAvailable()) {
162179
registerRimeNotificationHandler(::handleRimeNotification)
180+
registerRimeResponseHandler(::handleRimeResponse)
163181
lifecycleImpl.emitState(RimeLifecycle.State.STARTING)
164182
dispatcher.start(fullCheck)
165183
}
@@ -179,6 +197,7 @@ class Rime :
179197
}
180198
lifecycleImpl.emitState(RimeLifecycle.State.STOPPED)
181199
unregisterRimeNotificationHandler(::handleRimeNotification)
200+
unregisterRimeResponseHandler(::handleRimeResponse)
182201
}
183202

184203
companion object {
@@ -198,6 +217,8 @@ class Rime :
198217

199218
private val notificationHandlers = ArrayList<(RimeNotification<*>) -> Unit>()
200219

220+
private val responseHandlers = ArrayList<(RimeResponse) -> Unit>()
221+
201222
init {
202223
System.loadLibrary("rime_jni")
203224
}
@@ -492,5 +513,14 @@ class Rime :
492513
Timber.d("Got Rime response: $response")
493514
responseFlow_.tryEmit(response)
494515
}
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+
}
495525
}
496526
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ interface RimeApi {
1717

1818
val schemaItemCached: SchemaItem
1919

20+
val inputStatusCached: InputStatus
21+
2022
suspend fun isEmpty(): Boolean
2123

2224
suspend fun processKey(

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@ data class CandidateItem(
1313
val comment: String,
1414
val text: String,
1515
)
16+
17+
data class InputStatus(
18+
val isDisabled: Boolean = true,
19+
val isComposing: Boolean = false,
20+
val isAsciiMode: Boolean = true,
21+
val isFullShape: Boolean = false,
22+
val isSimplified: Boolean = false,
23+
val isTraditional: Boolean = false,
24+
val isAsciiPunch: Boolean = true,
25+
)

0 commit comments

Comments
 (0)