diff --git a/android/app/src/main/assets/script/user-api-preload.js b/android/app/src/main/assets/script/user-api-preload.js index 6f013fb..1f7e12e 100644 --- a/android/app/src/main/assets/script/user-api-preload.js +++ b/android/app/src/main/assets/script/user-api-preload.js @@ -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 diff --git a/android/app/src/main/java/cn/toside/music/mobile/userApi/QuickJS.java b/android/app/src/main/java/cn/toside/music/mobile/userApi/QuickJS.java index e106d07..5656b91 100644 --- a/android/app/src/main/java/cn/toside/music/mobile/userApi/QuickJS.java +++ b/android/app/src/main/java/cn/toside/music/mobile/userApi/QuickJS.java @@ -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()); diff --git a/publish/changeLog.md b/publish/changeLog.md index d9f1918..e3cd526 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -6,6 +6,7 @@ ### 优化 - 添加是否忽略电池优化检查,用于提醒用户添加白名单,确保APP后台播放稳定性 +- 在设置界面返回时,不再直接返回桌面,将回到进入设置界面前的界面,再非设置界面返回时才会返回桌面 ### 修复 diff --git a/src/core/common.ts b/src/core/common.ts index 4ab3627..ae1e0f8 100644 --- a/src/core/common.ts +++ b/src/core/common.ts @@ -78,7 +78,10 @@ export const removeComponentId = (name: string) => { export const setNavActiveId = (id: Parameters['0']) => { if (id == commonState.navActiveId) return commonActions.setNavActiveId(id) - saveViewPrevState({ id }) + if (id != 'nav_setting') { + commonActions.setLastNavActiveId(id) + saveViewPrevState({ id }) + } } export const showPactModal = () => { diff --git a/src/navigation/navigation.ts b/src/navigation/navigation.ts index 53b8b4d..ee7b1b7 100644 --- a/src/navigation/navigation.ts +++ b/src/navigation/navigation.ts @@ -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'], }, diff --git a/src/screens/Comment/index.tsx b/src/screens/Comment/index.tsx index 05054f8..7812c14 100644 --- a/src/screens/Comment/index.tsx +++ b/src/screens/Comment/index.tsx @@ -120,10 +120,12 @@ export default memo(({ componentId }: { }, []) useEffect(() => { - if (!playerState.playMusicInfo.musicInfo) return - let playerMusicInfo = playerState.playMusicInfo.musicInfo - if ('progress' in playerMusicInfo) playerMusicInfo = playerMusicInfo.metadata.musicInfo - setMusicInfo(playerMusicInfo) + setTimeout(() => { + if (!playerState.playMusicInfo.musicInfo) return + let playerMusicInfo = playerState.playMusicInfo.musicInfo + if ('progress' in playerMusicInfo) playerMusicInfo = playerMusicInfo.metadata.musicInfo + setMusicInfo(playerMusicInfo) + }, 300) }, []) return ( diff --git a/src/screens/Home/Views/Setting/index.tsx b/src/screens/Home/Views/Setting/index.tsx index b61cee8..e1ab86b 100644 --- a/src/screens/Home/Views/Setting/index.tsx +++ b/src/screens/Home/Views/Setting/index.tsx @@ -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 ? diff --git a/src/store/common/action.ts b/src/store/common/action.ts index ed9153d..72153ae 100644 --- a/src/store/common/action.ts +++ b/src/store/common/action.ts @@ -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) diff --git a/src/store/common/state.ts b/src/store/common/state.ts index 63659e4..3ed6310 100644 --- a/src/store/common/state.ts +++ b/src/store/common/state.ts @@ -5,6 +5,7 @@ export interface InitState { fontSize: number componentIds: Partial> navActiveId: NAV_ID_Type + lastNavActiveId: NAV_ID_Type sourceNames: Record } @@ -14,6 +15,7 @@ const state: InitState = { fontSize: global.lx.fontSize, componentIds: {}, navActiveId: 'nav_search', + lastNavActiveId: 'nav_search', sourceNames: initData as InitState['sourceNames'], } diff --git a/src/utils/hooks/useBackHandler.ts b/src/utils/hooks/useBackHandler.ts new file mode 100644 index 0000000..757893b --- /dev/null +++ b/src/utils/hooks/useBackHandler.ts @@ -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]) +}