mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-04-25 13:48:49 +08:00
fix updateCurrentSong to handle delete
This commit is contained in:
parent
7695bc6a7f
commit
126f7f7820
2
gomu.go
2
gomu.go
@ -140,7 +140,7 @@ func (g *Gomu) setUnfocusPanel(panel Panel) {
|
||||
func (g *Gomu) quit(args Args) error {
|
||||
|
||||
if !*args.empty {
|
||||
err := gomu.queue.saveQueue(true)
|
||||
err := gomu.queue.saveQueue()
|
||||
if err != nil {
|
||||
return tracerr.Wrap(err)
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ func (p *Playlist) deleteSong(audioFile *AudioFile) (err error) {
|
||||
|
||||
// Here we remove the song from queue
|
||||
gomu.queue.updateQueuePath()
|
||||
gomu.queue.updateCurrentSong(audioFile, nil)
|
||||
gomu.queue.updateCurrentSong(audioFile, nil, true)
|
||||
}
|
||||
|
||||
})
|
||||
@ -809,7 +809,7 @@ func (p *Playlist) paste() error {
|
||||
|
||||
newAudio := oldAudio
|
||||
newAudio.path = newPathFull
|
||||
gomu.queue.updateCurrentSong(oldAudio, newAudio)
|
||||
gomu.queue.updateCurrentSong(oldAudio, newAudio, false)
|
||||
|
||||
p.yankFile = nil
|
||||
|
||||
@ -844,14 +844,14 @@ func (p *Playlist) refreshByNode(node *AudioFile, newName string) error {
|
||||
// update queue
|
||||
newNode := p.getCurrentFile()
|
||||
if node.isAudioFile {
|
||||
err := gomu.queue.rename(node, newNode)
|
||||
err := gomu.queue.renameItem(node, newNode)
|
||||
if err != nil {
|
||||
return tracerr.Wrap(err)
|
||||
}
|
||||
} else {
|
||||
gomu.queue.updateQueuePath()
|
||||
}
|
||||
gomu.queue.updateCurrentSong(node, newNode)
|
||||
gomu.queue.updateCurrentSong(node, newNode, false)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
2
popup.go
2
popup.go
@ -146,7 +146,7 @@ func confirmDeleteAllPopup(selPlaylist *tview.TreeNode) (err error) {
|
||||
errorPopup(err)
|
||||
}
|
||||
gomu.queue.updateQueuePath()
|
||||
gomu.queue.updateCurrentSong(selPlaylist.GetReference().(*AudioFile), nil)
|
||||
gomu.queue.updateCurrentSong(selPlaylist.GetReference().(*AudioFile), nil, true)
|
||||
}
|
||||
|
||||
case tcell.KeyEscape:
|
||||
|
11
queue.go
11
queue.go
@ -193,13 +193,12 @@ func (q *Queue) getItems() []string {
|
||||
}
|
||||
|
||||
// Save the current queue
|
||||
func (q *Queue) saveQueue(isQuit bool) error {
|
||||
func (q *Queue) saveQueue() error {
|
||||
|
||||
songPaths := q.getItems()
|
||||
var content strings.Builder
|
||||
|
||||
if gomu.player.HasInit() && gomu.player.GetCurrentSong() != nil {
|
||||
// if gomu.player.HasInit() && isQuit && gomu.player.GetCurrentSong() != nil {
|
||||
currentSongPath := gomu.player.GetCurrentSong().Path()
|
||||
currentSongInQueue := false
|
||||
for _, songPath := range songPaths {
|
||||
@ -414,7 +413,7 @@ func sha1Hex(input string) string {
|
||||
}
|
||||
|
||||
// Modify the title of songs in queue
|
||||
func (q *Queue) rename(oldAudio *AudioFile, newAudio *AudioFile) error {
|
||||
func (q *Queue) renameItem(oldAudio *AudioFile, newAudio *AudioFile) error {
|
||||
for i, v := range q.items {
|
||||
if v.name != oldAudio.name {
|
||||
continue
|
||||
@ -510,7 +509,7 @@ func (q *Queue) updateQueuePath() {
|
||||
q.updateTitle()
|
||||
}
|
||||
|
||||
func (q *Queue) updateCurrentSong(oldAudio *AudioFile, newAudio *AudioFile) {
|
||||
func (q *Queue) updateCurrentSong(oldAudio *AudioFile, newAudio *AudioFile, isDelete bool) {
|
||||
|
||||
if !gomu.player.IsRunning() && !gomu.player.IsPaused() {
|
||||
return
|
||||
@ -520,10 +519,9 @@ func (q *Queue) updateCurrentSong(oldAudio *AudioFile, newAudio *AudioFile) {
|
||||
position := gomu.playingBar.getProgress()
|
||||
paused := gomu.player.IsPaused()
|
||||
|
||||
if !oldAudio.isAudioFile {
|
||||
if !oldAudio.isAudioFile && isDelete {
|
||||
//Here we check the situation when currentsong is under oldAudio folder
|
||||
if strings.Contains(currentSong.Path(), oldAudio.path) {
|
||||
|
||||
tmpLoop := q.isLoop
|
||||
q.isLoop = false
|
||||
gomu.player.Skip()
|
||||
@ -532,7 +530,6 @@ func (q *Queue) updateCurrentSong(oldAudio *AudioFile, newAudio *AudioFile) {
|
||||
}
|
||||
q.isLoop = tmpLoop
|
||||
return
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user