Skip to content

Commit 9e295ca

Browse files
committed
fix: random NPE when loading config in TrimeInputMethodService
1 parent 69e8b3a commit 9e295ca

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

app/src/main/java/com/osfans/trime/ime/core/TrimeInputMethodService.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
9999
private var mCompositionPopupWindow: CompositionPopupWindow? = null
100100
var candidateExPage = false
101101

102+
var shouldUpdateRimeOption = false
103+
var shouldResetAsciiMode = false
104+
102105
private val cursorCapsMode: Int
103106
get() =
104107
currentInputEditorInfo.run {
@@ -175,17 +178,17 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
175178

176179
fun loadConfig() {
177180
val theme = ThemeManager.activeTheme
178-
textInputManager!!.shouldResetAsciiMode = theme.style.getBoolean("reset_ascii_mode")
181+
shouldResetAsciiMode = theme.style.getBoolean("reset_ascii_mode")
179182
isAutoCaps = theme.style.getBoolean("auto_caps")
180-
textInputManager!!.shouldUpdateRimeOption = true
183+
shouldUpdateRimeOption = true
181184
}
182185

183186
private fun updateRimeOption(): Boolean {
184187
try {
185-
if (textInputManager!!.shouldUpdateRimeOption) {
188+
if (shouldUpdateRimeOption) {
186189
Rime.setOption("soft_cursor", prefs.keyboard.softCursorEnabled) // 軟光標
187190
Rime.setOption("_horizontal", ThemeManager.activeTheme.style.getBoolean("horizontal")) // 水平模式
188-
textInputManager!!.shouldUpdateRimeOption = false
191+
shouldUpdateRimeOption = false
189192
}
190193
} catch (e: Exception) {
191194
e.printStackTrace()
@@ -326,11 +329,9 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
326329

327330
loadConfig()
328331
KeyboardSwitcher.newOrReset()
329-
if (textInputManager != null) {
330-
textInputManager!!.shouldUpdateRimeOption = true // 不能在Rime.onMessage中調用set_option,會卡死
331-
bindKeyboardToInputView()
332-
updateComposing() // 切換主題時刷新候選
333-
}
332+
shouldUpdateRimeOption = true // 不能在Rime.onMessage中調用set_option,會卡死
333+
bindKeyboardToInputView()
334+
updateComposing() // 切換主題時刷新候選
334335
setInputView(inputView!!)
335336
}
336337

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,14 @@ class TextInputManager private constructor() :
6363
val locales = Array(2) { Locale.getDefault() }
6464

6565
var needSendUpRimeKey: Boolean = false
66-
var shouldUpdateRimeOption: Boolean = true
6766
var isComposable: Boolean = false
68-
var shouldResetAsciiMode: Boolean = false
67+
68+
private var shouldUpdateRimeOption
69+
get() = trime.shouldUpdateRimeOption
70+
set(value) {
71+
trime.shouldUpdateRimeOption = value
72+
}
73+
private val shouldResetAsciiMode get() = trime.shouldResetAsciiMode
6974

7075
companion object {
7176
/** Delimiter regex for key property group, their format like `{property_1: value_1, property_2: value_2}` */

0 commit comments

Comments
 (0)