fix: theme persistence — error handling, backup, stale highlight

Bug 1 (critical): setTheme lacked try/catch around wx.setStorageSync.
  If storage write throws (full / permission), the theme silently
  fails to persist but UI has already changed → on next cold start
  getCurrentTheme falls back to orange.
  → Wrap in try/catch; still apply UI change even if storage fails
    (better to see the right color now than revert immediately).

Bug 2 (display): settings onShow called applyThemeToPage (updates
  'theme' object) but never refreshed 'currentThemeId'. After tab
  switching, the radio highlight showed the wrong theme.
  → Add setData({ currentThemeId }) in onShow.

Redundancy: theme now also saved as themeId in user_settings.
  getCurrentTheme falls back to user_settings.themeId if app_theme
  key is unexpectedly missing, providing a recovery path.
This commit is contained in:
2026-06-04 16:43:32 +08:00
parent 5d155e41fe
commit e2186b2502
2 changed files with 22 additions and 3 deletions
+2
View File
@@ -39,6 +39,8 @@ Page({
if (tb) tb.setData({ selected: 2 })
} catch (e) {}
themeMod.applyThemeToPage(this)
// sync highlighted theme in case it was changed elsewhere
this.setData({ currentThemeId: themeMod.getCurrentTheme().id })
},
onSelectTheme(e) {