修复自动切换主题问题

This commit is contained in:
lyswhut 2022-04-09 23:55:09 +08:00
parent 23a7795743
commit c7ee043ba2
2 changed files with 15 additions and 6 deletions

View File

@ -19,7 +19,7 @@ import { init as initMusicTools } from '@/utils/music'
import { init as initLyric, toggleTranslation } from '@/utils/lyric'
import { showLyric, onPositionChange } from '@/utils/lyricDesktop'
import { init as initI18n, supportedLngs } from '@/plugins/i18n'
import { deviceLanguage, getPlayInfo, toast, onAppearanceChange, getIsSupportedAutoTheme } from '@/utils/tools'
import { deviceLanguage, getPlayInfo, toast, onAppearanceChange, getIsSupportedAutoTheme, getAppearance } from '@/utils/tools'
import { LIST_ID_PLAY_TEMP } from '@/config/constant'
import { connect, SYNC_CODE } from '@/plugins/sync'
@ -127,6 +127,8 @@ const init = () => {
initNavigation(() => {
init().then(() => {
if (getIsSupportedAutoTheme()) store.dispatch(commonAction.setSystemColor(getAppearance()))
return navigations.pushHomeScreen().then(() => {
SplashScreen.hide()
if (store.getState().common.setting.isAgreePact) {

View File

@ -377,18 +377,25 @@ export const shareMusic = (shareType, downloadFileName, musicInfo) => {
}
}
export const getAppearance = () => {
return Appearance.getColorScheme()
}
export const onAppearanceChange = callback => {
callback(Appearance.getColorScheme())
return Appearance.addChangeListener(({ colorScheme }) => {
callback(colorScheme)
})
}
let isSupportedAutoTheme = null
export const getIsSupportedAutoTheme = () => {
if (isSupportedAutoTheme == null) {
const osVerNum = parseInt(osVer)
return isAndroid
isSupportedAutoTheme = isAndroid
? osVerNum >= 10
: osVerNum >= 13
}
return isSupportedAutoTheme
}
export {