Skip to content

Commit fb3903e

Browse files
committed
refactor(api): update context in rime engine lifecycle looper
1 parent fe9c39d commit fb3903e

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class Rime :
6060
lifecycleImpl.emitState(RimeLifecycle.State.READY)
6161
}
6262

63+
override fun nativeScheduleTasks() {
64+
updateContext()
65+
}
66+
6367
override fun nativeFinalize() {
6468
exitRime()
6569
}
@@ -81,25 +85,25 @@ class Rime :
8185
modifiers: UInt,
8286
): Boolean =
8387
withRimeContext {
84-
processRimeKey(value, modifiers.toInt()).also { if (it) updateContext() }
88+
processRimeKey(value, modifiers.toInt())
8589
}
8690

8791
override suspend fun processKey(
8892
value: KeyValue,
8993
modifiers: KeyModifiers,
9094
): Boolean =
9195
withRimeContext {
92-
processRimeKey(value.value, modifiers.toInt()).also { if (it) updateContext() }
96+
processRimeKey(value.value, modifiers.toInt())
9397
}
9498

9599
override suspend fun selectCandidate(idx: Int): Boolean =
96100
withRimeContext {
97-
selectRimeCandidate(idx).also { if (it) updateContext() }
101+
selectRimeCandidate(idx)
98102
}
99103

100104
override suspend fun forgetCandidate(idx: Int): Boolean =
101105
withRimeContext {
102-
forgetRimeCandidate(idx).also { if (it) updateContext() }
106+
forgetRimeCandidate(idx)
103107
}
104108

105109
override suspend fun availableSchemata(): Array<SchemaItem> = withRimeContext { getAvailableRimeSchemaList() }
@@ -120,12 +124,11 @@ class Rime :
120124
schema ?: schemaItemCached
121125
}
122126

123-
override suspend fun commitComposition(): Boolean = withRimeContext { commitRimeComposition().also { updateContext() } }
127+
override suspend fun commitComposition(): Boolean = withRimeContext { commitRimeComposition() }
124128

125129
override suspend fun clearComposition() =
126130
withRimeContext {
127131
clearRimeComposition()
128-
updateContext()
129132
}
130133

131134
override suspend fun setRuntimeOption(
@@ -154,6 +157,7 @@ class Rime :
154157
is RimeNotification.SchemaNotification -> schemaItemCached = notif.value
155158
else -> {}
156159
}
160+
updateContext()
157161
}
158162

159163
private fun handleRimeResponse(response: RimeResponse) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class RimeDispatcher(
3333
interface RimeLooper {
3434
fun nativeStartup(fullCheck: Boolean)
3535

36+
fun nativeScheduleTasks()
37+
3638
fun nativeFinalize()
3739
}
3840

@@ -92,6 +94,7 @@ class RimeDispatcher(
9294
while (isActive && isRunning.get()) {
9395
// TODO: because we have nothing to block currently,
9496
// here we use a channel to wait for a signal.
97+
looper.nativeScheduleTasks()
9598
runBlocking { channel.receive() }
9699
while (true) {
97100
val block = queue.poll() ?: break

app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package com.osfans.trime.ime.text
77
import android.text.InputType
88
import android.view.inputmethod.EditorInfo
99
import androidx.lifecycle.lifecycleScope
10-
import com.osfans.trime.core.Rime
1110
import com.osfans.trime.core.RimeNotification
1211
import com.osfans.trime.daemon.RimeSession
1312
import com.osfans.trime.data.prefs.AppPrefs
@@ -119,11 +118,9 @@ class TextInputManager(
119118
private fun handleRimeNotification(notification: RimeNotification<*>) {
120119
if (notification is RimeNotification.SchemaNotification) {
121120
SchemaManager.init(notification.value.id)
122-
Rime.updateStatus()
123121
trime.recreateInputView()
124122
trime.inputView?.switchBoard(InputView.Board.Main)
125123
} else if (notification is RimeNotification.OptionNotification) {
126-
Rime.updateContext() // 切換中英文、簡繁體時更新候選
127124
val value = notification.value.value
128125
when (val option = notification.value.option) {
129126
"ascii_mode" -> {

0 commit comments

Comments
 (0)