Skip to content

Commit

Permalink
player: show warning when user removes the current song in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
cosven committed Jan 15, 2025
1 parent f7d210c commit 2bb84c4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
13 changes: 12 additions & 1 deletion feeluown/gui/components/player_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,15 @@ def scroll_to_current_song(self):

def _remove_songs(self, songs):
for song in songs:
self._app.playlist.remove(song)
playlist_songs = self._app.playlist.list()
if (
self._app.playlist.mode is PlaylistMode.fm
# playlist_songs should not be empty, just for robustness
and playlist_songs
and song == self._app.playlist.current_song
and playlist_songs[-1] == song
):
self._app.show_msg("FM 模式下,如果当前歌曲是最后一首歌,则无法移除,请稍后再尝试移除", timeout=3000)
self._app.playlist.next()
else:
self._app.playlist.remove(song)
7 changes: 6 additions & 1 deletion feeluown/player/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,13 @@ def remove_no_lock(self, song):
self._songs.remove(song)
new_next_song = self._get_next_song_no_lock()
self.set_existing_song_as_current_song(new_next_song)
elif next_song is None and self.mode is PlaylistMode.fm:
# The caller should not remove the current song when it
# is the last song in fm mode.
logger.error("Can't remove the last song in fm mode, will play next")
self._next_no_lock()
return
else:
next_song = self._get_next_song_no_lock()
self._songs.remove(song)
self.set_existing_song_as_current_song(next_song)
else:
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ addopts = -q
--cov-report=
--cov=feeluown
--doctest-modules
asyncio_default_fixture_loop_scope = function
[mypy-feeluown.mpv]
ignore_errors = True

Expand Down
9 changes: 7 additions & 2 deletions tests/player/test_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,13 @@ def feed_playlist():


@pytest.mark.asyncio
async def test_playlist_remove_current_song(app_mock):
pass
async def test_playlist_remove_current_song(pl, song1, mocker):
# Remove the current song, and it is the last song in the playlist.
mock_emit = mocker.patch.object(pl.eof_reached, 'emit')
pl.mode = PlaylistMode.fm
pl._current_song = song1
pl.remove(song1)
assert mock_emit.called


@pytest.mark.asyncio
Expand Down

0 comments on commit 2bb84c4

Please sign in to comment.