修复主题恢复与勋章状态
This commit is contained in:
@@ -5,6 +5,21 @@ const darkMod = require('./utils/darkMode')
|
||||
const voice = require('./utils/voice')
|
||||
const config = require('./config')
|
||||
|
||||
const refreshOpenThemeViews = () => {
|
||||
const pages = getCurrentPages()
|
||||
pages.forEach(p => {
|
||||
if (p && typeof p.applyThemeToPage === 'function') {
|
||||
p.applyThemeToPage()
|
||||
} else if (p && p.route) {
|
||||
try { themeMod.applyThemeToPage(p) } catch (e) {}
|
||||
}
|
||||
try {
|
||||
const tb = p && p.getTabBar && p.getTabBar()
|
||||
if (tb && typeof tb.updateTheme === 'function') tb.updateTheme()
|
||||
} catch (e) {}
|
||||
})
|
||||
}
|
||||
|
||||
App({
|
||||
async onLaunch() {
|
||||
// 尽早设导航栏色 + 窗口背景:原生导航栏在 JS 执行前用 app.json 写死的
|
||||
@@ -13,22 +28,7 @@ App({
|
||||
|
||||
// Init dark mode listener (refreshes all open pages when system theme changes)
|
||||
darkMod.watchDarkMode((isDark) => {
|
||||
const pages = getCurrentPages()
|
||||
pages.forEach(p => {
|
||||
if (p && typeof p.applyThemeToPage === 'function') {
|
||||
p.applyThemeToPage()
|
||||
} else if (p && p.route) {
|
||||
// index/records/leaderboard 等页面没定义 applyThemeToPage 方法,
|
||||
// 但都在 onLoad/onShow 里套用过主题,这里直接用 themeMod 兜底刷新,
|
||||
// 否则系统深/浅色切换时这些页不会实时变色。
|
||||
try { themeMod.applyThemeToPage(p) } catch (e) {}
|
||||
}
|
||||
// 自定义 tabBar 不在 pages 列表里,单独通知它切换暗黑/明亮
|
||||
try {
|
||||
const tb = p.getTabBar && p.getTabBar()
|
||||
if (tb && typeof tb.updateTheme === 'function') tb.updateTheme()
|
||||
} catch (e) {}
|
||||
})
|
||||
refreshOpenThemeViews()
|
||||
})
|
||||
|
||||
// Init cloud storage (no-op if not configured)
|
||||
@@ -158,6 +158,10 @@ App({
|
||||
}
|
||||
if (cloudData.themeId) {
|
||||
themeMod.setTheme(cloudData.themeId)
|
||||
// Cloud restore is asynchronous: pages may have already rendered
|
||||
// with their initial orange data. Reapply immediately so they don't
|
||||
// wait for a later tab switch to reflect the restored theme.
|
||||
refreshOpenThemeViews()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user