在设置界面返回时,不再直接返回桌面

This commit is contained in:
lyswhut 2023-11-06 11:40:39 +08:00
parent ccff6596bd
commit a316732622
10 changed files with 57 additions and 35 deletions

View File

@ -1,6 +1,6 @@
'use strict'
globalThis.lx_setup = (key, id, name, description, rawScript) => {
globalThis.lx_setup = (key, id, name, description) => {
delete globalThis.lx_setup
const _nativeCall = globalThis.__lx_native_call__
delete globalThis.__lx_native_call__
@ -471,18 +471,6 @@ globalThis.lx_setup = (key, id, name, description, rawScript) => {
globalThis.setTimeout = _setTimeout
globalThis.clearTimeout = _clearTimeout
globalThis.window = globalThis
globalThis.document = {
getElementsByTagName(name) {
if (name == 'script') {
return [
Object.freeze({
innerText: rawScript,
}),
]
}
return null
},
}
const freezeObject = (obj) => {
if (typeof obj != 'object') return

View File

@ -123,7 +123,7 @@ public class QuickJS {
});
}
private boolean createJSEnv(String id, String name, String desc, String rawScript) {
private boolean createJSEnv(String id, String name, String desc) {
init();
QuickJSContext quickJSContext = this.jsContext;
if (quickJSContext != null) quickJSContext.destroy();
@ -134,7 +134,7 @@ public class QuickJS {
if (preloadScript == null) return false;
createEnvObj(this.jsContext);
this.jsContext.evaluate(preloadScript);
this.jsContext.getGlobalObject().getJSFunction("lx_setup").call(this.key, id, name, desc, rawScript);
this.jsContext.getGlobalObject().getJSFunction("lx_setup").call(this.key, id, name, desc);
return true;
}
@ -148,12 +148,11 @@ public class QuickJS {
public String loadScript(Bundle scriptInfo) {
Log.d("UserApi", "UserApi Thread id: " + Thread.currentThread().getId());
String script = scriptInfo.getString("script", "");
if (createJSEnv(scriptInfo.getString("id", ""),
scriptInfo.getString("name", "Unknown"),
scriptInfo.getString("description", ""), script)) {
scriptInfo.getString("description", ""))) {
try {
this.jsContext.evaluate(script);
this.jsContext.evaluate(scriptInfo.getString("script", ""));
return "";
} catch (Exception e) {
Log.e("UserApi", "load script error: " + e.getMessage());

View File

@ -6,6 +6,7 @@
### 优化
- 添加是否忽略电池优化检查用于提醒用户添加白名单确保APP后台播放稳定性
- 在设置界面返回时,不再直接返回桌面,将回到进入设置界面前的界面,再非设置界面返回时才会返回桌面
### 修复

View File

@ -78,7 +78,10 @@ export const removeComponentId = (name: string) => {
export const setNavActiveId = (id: Parameters<typeof commonActions.setNavActiveId>['0']) => {
if (id == commonState.navActiveId) return
commonActions.setNavActiveId(id)
if (id != 'nav_setting') {
commonActions.setLastNavActiveId(id)
saveViewPrevState({ id })
}
}
export const showPactModal = () => {

View File

@ -136,10 +136,10 @@ export function pushPlayDetailScreen(componentId: string) {
style: getStatusBarStyle(theme.isDark),
backgroundColor: 'transparent',
},
// navigationBar: {
// // visible: false,
// backgroundColor: theme['c-content-background'],
// },
navigationBar: {
// visible: false,
backgroundColor: theme['c-content-background'],
},
layout: {
componentBackgroundColor: theme['c-content-background'],
},
@ -231,10 +231,10 @@ export function pushSonglistDetailScreen(componentId: string, id: string) {
style: getStatusBarStyle(theme.isDark),
backgroundColor: 'transparent',
},
// navigationBar: {
// // visible: false,
// backgroundColor: theme['c-content-background'],
// },
navigationBar: {
// visible: false,
backgroundColor: theme['c-content-background'],
},
layout: {
componentBackgroundColor: theme['c-content-background'],
},
@ -366,10 +366,10 @@ export function pushCommentScreen(componentId: string) {
style: getStatusBarStyle(theme.isDark),
backgroundColor: 'transparent',
},
// navigationBar: {
// // visible: false,
// backgroundColor: theme['c-content-background'],
// },
navigationBar: {
// visible: false,
backgroundColor: theme['c-content-background'],
},
layout: {
componentBackgroundColor: theme['c-content-background'],
},

View File

@ -120,10 +120,12 @@ export default memo(({ componentId }: {
}, [])
useEffect(() => {
setTimeout(() => {
if (!playerState.playMusicInfo.musicInfo) return
let playerMusicInfo = playerState.playMusicInfo.musicInfo
if ('progress' in playerMusicInfo) playerMusicInfo = playerMusicInfo.metadata.musicInfo
setMusicInfo(playerMusicInfo)
}, 300)
}, [])
return (

View File

@ -1,12 +1,23 @@
import { useWindowSize } from '@/utils/hooks'
import Vertical from './Vertical'
import Horizontal from './Horizontal'
import { useBackHandler } from '@/utils/hooks/useBackHandler'
import { useCallback } from 'react'
// import { AppColors } from '@/theme'
import commonState from '@/store/common/state'
import { setNavActiveId } from '@/core/common'
export type { SettingScreenIds } from './Main'
export default () => {
const windowSize = useWindowSize()
useBackHandler(useCallback(() => {
if (Object.keys(commonState.componentIds).length == 1 && commonState.navActiveId == 'nav_setting') {
setNavActiveId(commonState.lastNavActiveId)
return true
}
return false
}, []))
return windowSize.height > windowSize.width
? <Vertical />

View File

@ -19,8 +19,12 @@ export default {
},
setNavActiveId(id: InitState['navActiveId']) {
state.navActiveId = id
if (id != 'nav_setting') state.lastNavActiveId = id
global.state_event.navActiveIdUpdated(id)
},
setLastNavActiveId(id: InitState['navActiveId']) {
state.lastNavActiveId = id
},
setSourceNames(names: InitState['sourceNames']) {
state.sourceNames = names
global.state_event.sourceNamesUpdated(names)

View File

@ -5,6 +5,7 @@ export interface InitState {
fontSize: number
componentIds: Partial<Record<COMPONENT_IDS, string>>
navActiveId: NAV_ID_Type
lastNavActiveId: NAV_ID_Type
sourceNames: Record<LX.OnlineSource | 'all', string>
}
@ -14,6 +15,7 @@ const state: InitState = {
fontSize: global.lx.fontSize,
componentIds: {},
navActiveId: 'nav_search',
lastNavActiveId: 'nav_search',
sourceNames: initData as InitState['sourceNames'],
}

View File

@ -0,0 +1,12 @@
import { useEffect } from 'react'
import { BackHandler } from 'react-native'
export function useBackHandler(handler: () => boolean) {
useEffect(() => {
BackHandler.addEventListener('hardwareBackPress', handler)
return () => {
BackHandler.removeEventListener('hardwareBackPress', handler)
}
}, [handler])
}