Skip to content

Commit 3ba9355

Browse files
committed
Remove lifecycle binding and usages from playerStore
1 parent 54a133c commit 3ba9355

1 file changed

Lines changed: 1 addition & 20 deletions

File tree

client/src/stores/playerStore.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import axios from 'axios';
88
let audioElement = null;
99
let nextAudioElement = null;
1010
let progressAutoSaveInterval = null;
11-
let lifecycleBound = false;
1211

1312
const getAudioUrl = (song) =>
1413
song?.download_url?.[4]?.link || song?.download_url?.[3]?.link || '';
@@ -41,22 +40,6 @@ export const usePlayerStore = create(
4140
nextAudioElement = nextAudio;
4241
},
4342

44-
bindLifecycle: () => {
45-
if (lifecycleBound) return;
46-
lifecycleBound = true;
47-
48-
const persistNow = () => {
49-
try {
50-
get().saveProgress();
51-
} catch {}
52-
};
53-
54-
window.addEventListener('pagehide', persistNow);
55-
document.addEventListener('visibilitychange', () => {
56-
if (document.visibilityState === 'hidden') persistNow();
57-
});
58-
},
59-
6043
updateTime: (currentTime) => set({ currentTime }),
6144

6245
saveProgress: () => {
@@ -204,7 +187,6 @@ export const usePlayerStore = create(
204187
updateMediaSession,
205188
preloadNextTrack,
206189
startAutoSave,
207-
bindLifecycle,
208190
} = get();
209191

210192
if (!audioElement || !currentSong || currentSong.id === prevSongId) {
@@ -222,7 +204,6 @@ export const usePlayerStore = create(
222204

223205
await audioElement.play();
224206
startAutoSave();
225-
bindLifecycle();
226207

227208
set({ isPlaying: true });
228209
addToHistory(currentSong, audioElement.currentTime, 'autoplay');
@@ -321,4 +302,4 @@ export const useIsPlaying = () => usePlayerStore((s) => s.isPlaying);
321302
export const usePlaylist = () => usePlayerStore((s) => s.playlist);
322303
export const useVolume = () => usePlayerStore((s) => s.volume);
323304

324-
export { getAudioUrl };
305+
export { getAudioUrl };

0 commit comments

Comments
 (0)