Skip to content

Commit

Permalink
Merge pull request #439 from lovegaoshi/dev
Browse files Browse the repository at this point in the history
fix: various bug fixes
  • Loading branch information
lovegaoshi authored May 22, 2024
2 parents 9d76d13 + 07d3de8 commit 5ec26a4
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 124 deletions.
2 changes: 1 addition & 1 deletion ios/example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<string>LaunchScreen.storyboard</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
<string>arm64</string>
</array>
<key>UIStatusBarHidden</key>
<true/>
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"@sentry/react-native": "^5.22.2",
"@sharcoux/slider": "^7.2.1",
"@shopify/flash-list": "^1.6.4",
"@shopify/react-native-skia": "1.2.3",
"axios": "^1.7.1",
"@shopify/react-native-skia": "1.3.0",
"axios": "^1.7.2",
"base-64": "^1.0.0",
"base64-js": "^1.5.1",
"big-integer": "^1.6.52",
Expand All @@ -63,7 +63,7 @@
"fflate": "^0.8.2",
"ffmpeg-kit-react-native": "^6.0.2",
"he": "^1.2.0",
"i18next": "^23.11.4",
"i18next": "^23.11.5",
"js-base64": "^3.7.7",
"libmuse": "git+https://github.com/lovegaoshi/muse.git#apm-release",
"lottie-react-native": "6.7.2",
Expand Down Expand Up @@ -101,7 +101,7 @@
"react-native-track-player": "https://[email protected]/lovegaoshi/react-native-track-player.git#commit=826bd575a98b662750e043397ed9f8d5f05a6077",
"react-native-url-polyfill": "^2.0.0",
"react-native-vector-icons": "^10.1.0",
"react-native-video": "^6.0.0",
"react-native-video": "^6.1.0",
"react-native-webview": "13.10.2",
"sp-react-native-in-app-updates": "^1.4.0",
"use-debounce": "^10.0.0",
Expand Down Expand Up @@ -135,8 +135,8 @@
"@types/react-native-video": "^5.0.20",
"@types/react-test-renderer": "^18.3.0",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^7.9.0",
"@typescript-eslint/parser": "^7.9.0",
"@typescript-eslint/eslint-plugin": "^7.10.0",
"@typescript-eslint/parser": "^7.10.0",
"@welldone-software/why-did-you-render": "^8.0.1",
"argparse": "^2.0.1",
"babel-jest": "^29.7.0",
Expand Down Expand Up @@ -167,4 +167,4 @@
},
"isSwift": true,
"packageManager": "[email protected]"
}
}
2 changes: 2 additions & 0 deletions src/components/setting/DeveloperSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';
import { APPSTORE } from '@env';
import { useStore } from 'zustand';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import * as Sentry from '@sentry/react-native';

import { useNoxSetting } from '@stores/useApp';
import { logStore, LOGLEVEL } from '@utils/Logger';
Expand Down Expand Up @@ -67,6 +68,7 @@ const developerSettings: { [key: string]: SettingEntry } = {
memoryEfficiency: {
settingName: 'memoryEfficiency',
settingCategory: 'GeneralSettings',
callback: Sentry.nativeCrash,
},
/**
chatGPTSongName: {
Expand Down
1 change: 1 addition & 0 deletions src/components/setting/SetttingEntries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface SettingEntry {
reRender?: boolean;
settingType?: string;
checkbox?: boolean;
callback?: () => void;
}

export const dummySelectSettingEntry: SelectSettingEntry<string> = {
Expand Down
6 changes: 3 additions & 3 deletions src/components/setting/useRenderSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const BooleanSetting = ({
settingCategory,
reRender = false,
checkbox = false,
callback,
}: SettingEntry) => {
const { t } = useTranslation();
const playerStyle = useNoxSetting(state => state.playerStyle);
Expand All @@ -75,12 +76,11 @@ const BooleanSetting = ({
);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const saveSettings = (toggled: { [key: string]: any }) => {
const saveSettings = (toggled: { [key: string]: any }) =>
setPlayerSetting(toggled);
};

const onToggle = () => {
saveSettings({ [settingName]: !playerSetting[settingName] });
saveSettings({ [settingName]: !playerSetting[settingName] }).then(callback);
if (reRender) {
togglePlaylistReRender();
}
Expand Down
32 changes: 12 additions & 20 deletions src/hooks/usePlayback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@utils/RNTPUtils';
import { NoxRepeatMode } from '@enums/RepeatMode';
import noxPlayingList, { setPlayingIndex } from '@stores/playingList';
import noxCache, { noxCacheKey } from '@utils/Cache';
import { dataSaverPlaylist, dataSaverSongs } from '@utils/Cache';
import useDataSaver from './useDataSaver';
import useSnack from '@stores/useSnack';
import { PlaylistTypes } from '@enums/Playlist';
Expand All @@ -21,15 +21,6 @@ const PLAYLIST_MEDIAID = 'playlist-';

const { getState } = noxPlayingList;

const dataSaverPlaylist = (playlist: NoxMedia.Playlist) => {
const newSongList = playlist.songList.filter(
song => noxCache.noxMediaCache?.peekCache(song) !== undefined
);
return newSongList.length === 0
? playlist
: { ...playlist, songList: newSongList };
};

const dataSaverPlaylistWrapper = (datasave = true) => {
return datasave
? dataSaverPlaylist
Expand Down Expand Up @@ -90,16 +81,20 @@ const usePlayback = () => {

const playAsSearchList = async ({
songs,
playlistSongs,
title = String(t('PlaylistsDrawer.SearchListTitle')),
song,
}: PlayAsSearchList) => {
const newSearchPlaylist = {
const newPlayingPlaylist = {
...searchPlaylist,
title,
songList: songs,
};
const newSearchPlaylist = playlistSongs
? { ...newPlayingPlaylist, songList: playlistSongs }
: newPlayingPlaylist;
setSearchPlaylist(newSearchPlaylist);
await playFromPlaylist({ playlist: newSearchPlaylist, song });
await playFromPlaylist({ playlist: newPlayingPlaylist, song });
setCurrentPlaylist(newSearchPlaylist);
};

Expand All @@ -109,18 +104,14 @@ const usePlayback = () => {
.filter(playlist => playlist.type === PlaylistTypes.Typical)
.map(p => getPlaylist(p.id))
);
let allSongs = allPlaylists.reduce(
const allSongs = allPlaylists.reduce(
(acc, curr) => acc.concat(curr.songList),
[] as NoxMedia.Song[]
);
if (isDataSaving) {
const cachedSongs = Array.from(noxCache.noxMediaCache.cache.keys());
allSongs = allSongs.filter(song =>
cachedSongs.includes(noxCacheKey(song))
);
}
const cachedSongs = isDataSaving ? dataSaverSongs(allSongs) : allSongs;
playAsSearchList({
songs: allSongs,
songs: cachedSongs,
playlistSongs: allSongs,
title: String(t('PlaylistOperations.all')),
});
};
Expand Down Expand Up @@ -255,6 +246,7 @@ interface PlayFromPlaylist {

interface PlayAsSearchList {
songs: NoxMedia.Song[];
playlistSongs?: NoxMedia.Song[];
title?: string;
song?: NoxMedia.Song;
}
2 changes: 1 addition & 1 deletion src/localization/zhcn/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
},
"Settings": {
"PluginsSettingName": "插件",
"PluginsSettingDesc": "测试功能,可能导致数据丢失损坏,别说我没告诉你",
"PluginsSettingDesc": "有可能导致数据错误的插件",
"GeneralSettingName": "播放器设置",
"GeneralSettingDesc": "一般的播放器设置",
"AppearanceSettingName": "播放器外观",
Expand Down
11 changes: 10 additions & 1 deletion src/stores/initializeStores.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { NativeModules, Platform } from 'react-native';
import { useNoxSetting } from './useApp';
import { fetch } from '@react-native-community/netinfo';

import { initialize as initializeAppStore } from './appStore';
import { initializeR128Gain } from '../utils/ffmpeg/r128Store';
import { dataSaverPlaylist } from '../utils/Cache';

const { NoxAndroidAutoModule } = NativeModules;

const useInitializeStore = () => {
const setGestureMode = useNoxSetting(state => state.setGestureMode);
const initPlayer = useNoxSetting(state => state.initPlayer);
const setCurrentPlayingList = useNoxSetting(
state => state.setCurrentPlayingList
);

const initializeStores = async (val: NoxStorage.PlayerStorageObject) => {
switch (Platform.OS) {
Expand All @@ -29,7 +34,11 @@ const useInitializeStore = () => {
}
await initializeAppStore();
await initializeR128Gain();
return await initPlayer(val);
const results = await initPlayer(val);
if ((await fetch()) && results.storedPlayerSetting.dataSaver) {
setCurrentPlayingList(dataSaverPlaylist(results.currentPlayingList));
}
return results;
};
return { initializeStores };
};
Expand Down
47 changes: 28 additions & 19 deletions src/stores/useApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ interface NoxSetting {
getPlaylist: (val: string) => Promise<NoxMedia.Playlist>;

playerSetting: NoxStorage.PlayerSettingDict;
setPlayerSetting: (val: Partial<NoxStorage.PlayerSettingDict>) => void;
setPlayerSetting: (
val: Partial<NoxStorage.PlayerSettingDict>
) => Promise<void>;

addPlaylist: (val: NoxMedia.Playlist) => void;
removePlaylist: (val: string) => void;
Expand Down Expand Up @@ -205,11 +207,12 @@ export const useNoxSetting = create<NoxSetting>((set, get) => ({
},
currentPlayingList: dummyPlaylistList,
setCurrentPlayingList: val => {
if (val.songList === get().currentPlayingList.songList) {
const { currentPlayingList, currentPlayingId } = get();
if (val.songList === currentPlayingList.songList) {
return false;
}
set({ currentPlayingList: val });
savelastPlaylistId([val.id, String(get().currentPlayingId)]);
savelastPlaylistId([val.id, String(currentPlayingId)]);
setPlayingList(val.songList);
return true;
},
Expand All @@ -236,26 +239,27 @@ export const useNoxSetting = create<NoxSetting>((set, get) => ({
set({ favoritePlaylist: val, playlists });
},
getPlaylist: async v => {
const appState: NoxSetting = get();
const { searchPlaylist, favoritePlaylist, playlists, playerSetting } =
get();
switch (v) {
case StorageKeys.SEARCH_PLAYLIST_KEY:
return appState.searchPlaylist;
return searchPlaylist;
case StorageKeys.FAVORITE_PLAYLIST_KEY:
return appState.favoritePlaylist;
return favoritePlaylist;
default:
if (appState.playerSetting.memoryEfficiency) {
if (playerSetting.memoryEfficiency) {
return getPlaylist({ key: v });
}
return appState.playlists[v];
return playlists[v];
}
},

playerSetting: DefaultSetting,
setPlayerSetting: val => {
const newPlayerSetting = { ...get().playerSetting, ...val };
set({ playerSetting: newPlayerSetting });
saveSettings(newPlayerSetting);
setPlayerSettingVanilla(newPlayerSetting);
return saveSettings(newPlayerSetting);
},

addPlaylist: playlist => {
Expand All @@ -268,9 +272,10 @@ export const useNoxSetting = create<NoxSetting>((set, get) => ({
savePlaylistIds(playlistIds);
},
removePlaylist: playlistId => {
let playlistIds = get().playlistIds;
let playlists = get().playlists;
const currentPlaylist = get().currentPlaylist;
const appState = get();
let playlistIds = appState.playlistIds;
let playlists = appState.playlists;
const currentPlaylist = appState.currentPlaylist;
if (currentPlaylist.id === playlistId) {
set({ currentPlaylist: playlists[StorageKeys.SEARCH_PLAYLIST_KEY] });
}
Expand All @@ -281,19 +286,22 @@ export const useNoxSetting = create<NoxSetting>((set, get) => ({
},

updatePlaylist: async (playlist, addSongs = [], removeSongs = []) => {
const appState: NoxSetting = get();
let playlists = appState.playlists;
const currentPlaylist = appState.currentPlaylist;
const {
playlists,
playerSetting,
currentPlaylist,
playlistShouldReRender,
} = get();
updatePlaylistSongs(playlist, addSongs, removeSongs);
playlists[playlist.id] = appState.playerSetting.memoryEfficiency
playlists[playlist.id] = playerSetting.memoryEfficiency
? { ...playlist, songList: [] }
: playlist;
if (playlist.id === currentPlaylist.id) {
set({ currentPlaylist: playlist });
}
set({ playlists });
savePlaylist(playlist);
set({ playlistShouldReRender: !appState.playlistShouldReRender });
set({ playlistShouldReRender: !playlistShouldReRender });
return playlist;
},

Expand Down Expand Up @@ -358,12 +366,13 @@ export const useNoxSetting = create<NoxSetting>((set, get) => ({
},

exportLegacy: () => {
const { playlistIds, playlists } = get();
const exportedLegacy: {
[key: string]: NoxMedia.Playlist | string[];
} = {
MyFavList: get().playlistIds,
MyFavList: playlistIds,
};
for (const [key, value] of Object.entries(get().playlists)) {
for (const [key, value] of Object.entries(playlists)) {
exportedLegacy[key] = value;
}
return exportedLegacy;
Expand Down
15 changes: 15 additions & 0 deletions src/utils/Cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,19 @@ export const cacheWrapper = (
getURL: () => Promise<string>
) => cache.noxMediaCache.loadCacheFunction(identifier, getURL);

const _dataSaverSongs = (v: NoxMedia.Song[]) =>
v.filter(song => cache.noxMediaCache?.peekCache(song) !== undefined);

export const dataSaverSongs = (v: NoxMedia.Song[]) => {
const cachedSongIds = Array.from(cache.noxMediaCache.cache.keys());
return v.filter(song => cachedSongIds.includes(noxCacheKey(song)));
};

export const dataSaverPlaylist = (playlist: NoxMedia.Playlist) => {
const newSongList = _dataSaverSongs(playlist.songList);
return newSongList.length === 0
? playlist
: { ...playlist, songList: newSongList };
};

export default cache;
Loading

0 comments on commit 5ec26a4

Please sign in to comment.