osfans / trime

同文安卓輸入法平臺3.x/Android-rime/Rime Input Method Engine for Android
http://osfans.github.io/trime/
GNU General Public License v3.0
3.18k stars 376 forks source link

Crash on uninitialized theme property #1290

Closed Bambooin closed 5 months ago

Bambooin commented 8 months ago

Describe the bug A clear and concise description of what the bug is.

Random crash on input pop

To Reproduce Steps to reproduce the bug:

  1. Lock the screen
  2. Unlock the sreen
  3. Trime show process with deployment
  4. Input the password
  5. The screen was unlocked and seen the crash

Expected behavior A clear and concise description of what you expected to happen.

Log If applicable, add crash log to quick focus your problem.

--------- Crash stacktrace
kotlin.UninitializedPropertyAccessException: lateinit property activeTheme has not been initialized
    at com.osfans.trime.data.theme.ThemeManager.getActiveTheme(ThemeManager.kt:52)
    at com.osfans.trime.data.theme.ColorManager.getTheme(ColorManager.kt:22)
    at com.osfans.trime.data.theme.ColorManager.getColorSchemeId(ColorManager.kt:172)
    at com.osfans.trime.data.theme.ColorManager.switchNightMode(ColorManager.kt:161)
    at com.osfans.trime.data.theme.ColorManager.onSystemNightModeChange(ColorManager.kt:107)
    at com.osfans.trime.ime.core.TrimeInputMethodService.onConfigurationChanged(TrimeInputMethodService.kt:385)
    at android.window.WindowTokenClient.onConfigurationChanged(WindowTokenClient.java:260)
    at android.window.WindowTokenClient$$ExternalSyntheticLambda1.accept(Unknown Source:16)
    at com.android.internal.util.function.pooled.PooledLambdaImpl.doInvoke(PooledLambdaImpl.java:295)
    at com.android.internal.util.function.pooled.PooledLambdaImpl.invoke(PooledLambdaImpl.java:204)
    at com.android.internal.util.function.pooled.OmniFunction.run(OmniFunction.java:97)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7924)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Screenshots If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

lidawei97688 commented 8 months ago

悬浮候选窗即将显示出来的时候也会崩溃

WhiredPlanck commented 8 months ago

Trime just init the theme managed by ThemeManager on the input method service created. I think it's not a good place to do that, since the service can be created once and run a long time. Initializing in TrimeApplication may be a good idea, but due to our usage of the storage requiring user to grant the permissions, it may be hacky to do so.

goofyz commented 8 months ago

現在有很多地方直接使用 ThemeManager.activeTheme,但 Theme 依賴於 rime 的「部置」,而「部置」有時很快有時卻很慢。要徹底改善的話只能在代碼建立一個預設的 theme,然後在部置完成後再載入選擇的 theme

WhiredPlanck commented 8 months ago

現在有很多地方直接使用 ThemeManager.activeTheme,但 Theme 依賴於 rime 的「部置」,而「部置」有時很快有時卻很慢。要徹底改善的話只能在代碼建立一個預設的 theme,然後在部置完成後再載入選擇的 theme

主题的部署和方案的部署是分开的,RimeWrapper 考虑的是方案的部署,主题不需要和方案一同进行部署。

goofyz commented 8 months ago

Theme 要等 Rime.startupRime() 完成後才能部署吧? 我記得有試過同步部署 Rime 和 Theme,結果Theme 會報錯目錄不正確。(因為 rime 設定目錄和部署是同一 function) 如果將目錄設定等相關抽出來成獨立 function,應該可以實現同時部署。

WhiredPlanck commented 8 months ago

Theme 要等 Rime.startupRime() 完成後才能部署吧? 我記得有試過同步部署 Rime 和 Theme,結果Theme 會報錯目錄不正確。(因為 rime 設定目錄和部署是同一 function) 如果將目錄設定等相關抽出來成獨立 function,應該可以實現同時部署。

是的,Theme 只要启动完 Rime 就能部署,它初始化时调用了一个用于编译单个配置文件的 API,和方案的部署流程互不影响。