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