Skip to content

Commit

Permalink
fix: random NPE when loading config in TrimeInputMethodService
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Mar 20, 2024
1 parent 69e8b3a commit 9e295ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
private var mCompositionPopupWindow: CompositionPopupWindow? = null
var candidateExPage = false

var shouldUpdateRimeOption = false
var shouldResetAsciiMode = false

private val cursorCapsMode: Int
get() =
currentInputEditorInfo.run {
Expand Down Expand Up @@ -175,17 +178,17 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {

fun loadConfig() {
val theme = ThemeManager.activeTheme
textInputManager!!.shouldResetAsciiMode = theme.style.getBoolean("reset_ascii_mode")
shouldResetAsciiMode = theme.style.getBoolean("reset_ascii_mode")
isAutoCaps = theme.style.getBoolean("auto_caps")
textInputManager!!.shouldUpdateRimeOption = true
shouldUpdateRimeOption = true
}

private fun updateRimeOption(): Boolean {
try {
if (textInputManager!!.shouldUpdateRimeOption) {
if (shouldUpdateRimeOption) {
Rime.setOption("soft_cursor", prefs.keyboard.softCursorEnabled) // 軟光標
Rime.setOption("_horizontal", ThemeManager.activeTheme.style.getBoolean("horizontal")) // 水平模式
textInputManager!!.shouldUpdateRimeOption = false
shouldUpdateRimeOption = false
}
} catch (e: Exception) {
e.printStackTrace()
Expand Down Expand Up @@ -326,11 +329,9 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {

loadConfig()
KeyboardSwitcher.newOrReset()
if (textInputManager != null) {
textInputManager!!.shouldUpdateRimeOption = true // 不能在Rime.onMessage中調用set_option,會卡死
bindKeyboardToInputView()
updateComposing() // 切換主題時刷新候選
}
shouldUpdateRimeOption = true // 不能在Rime.onMessage中調用set_option,會卡死
bindKeyboardToInputView()
updateComposing() // 切換主題時刷新候選
setInputView(inputView!!)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,14 @@ class TextInputManager private constructor() :
val locales = Array(2) { Locale.getDefault() }

var needSendUpRimeKey: Boolean = false
var shouldUpdateRimeOption: Boolean = true
var isComposable: Boolean = false
var shouldResetAsciiMode: Boolean = false

private var shouldUpdateRimeOption
get() = trime.shouldUpdateRimeOption
set(value) {
trime.shouldUpdateRimeOption = value
}
private val shouldResetAsciiMode get() = trime.shouldResetAsciiMode

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

0 comments on commit 9e295ca

Please sign in to comment.