mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-04-26 13:49:21 +08:00
cleanup error handling code
This commit is contained in:
parent
20f2f0ca7e
commit
506615b67e
@ -43,12 +43,13 @@ func (c Command) defineCommands() {
|
||||
|
||||
c.define("delete_playlist", func() {
|
||||
audioFile := gomu.playlist.getCurrentFile()
|
||||
if !audioFile.isAudioFile {
|
||||
if audioFile.isAudioFile {
|
||||
return
|
||||
}
|
||||
err := confirmDeleteAllPopup(audioFile.node)
|
||||
if err != nil {
|
||||
errorPopup(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
c.define("delete_file", func() {
|
||||
|
22
playlist.go
22
playlist.go
@ -266,33 +266,17 @@ func (p *Playlist) deleteSong(audioFile *AudioFile) (err error) {
|
||||
// Deletes playlist/dir from filesystem
|
||||
func (p *Playlist) deletePlaylist(audioFile *AudioFile) (err error) {
|
||||
|
||||
var selectedDir *AudioFile
|
||||
|
||||
// gets the parent dir if current focused node is not a dir
|
||||
if audioFile.isAudioFile {
|
||||
return nil
|
||||
} else {
|
||||
selectedDir = audioFile
|
||||
}
|
||||
|
||||
err = os.RemoveAll(selectedDir.path)
|
||||
|
||||
err = os.RemoveAll(audioFile.path)
|
||||
if err != nil {
|
||||
|
||||
errorPopup(err)
|
||||
|
||||
err = tracerr.Wrap(err)
|
||||
|
||||
} else {
|
||||
|
||||
defaultTimedPopup(
|
||||
" Success ",
|
||||
selectedDir.name+"\nhas been deleted successfully")
|
||||
|
||||
audioFile.name+"\nhas been deleted successfully")
|
||||
p.refresh()
|
||||
}
|
||||
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
// Bulk add a playlist to queue
|
||||
|
7
popup.go
7
popup.go
@ -129,9 +129,6 @@ func confirmationPopup(
|
||||
func confirmDeleteAllPopup(selPlaylist *tview.TreeNode) (err error) {
|
||||
|
||||
popupID := "confirm-deleteall-input-popup"
|
||||
if selPlaylist.GetReference().(*AudioFile).isAudioFile {
|
||||
return fmt.Errorf("not a folder")
|
||||
}
|
||||
input := newInputPopup(popupID, "Are you sure to delete the folder and all files under it?", "Type DELETE to Confirm: ", "")
|
||||
|
||||
input.SetDoneFunc(func(key tcell.Key) {
|
||||
@ -144,9 +141,9 @@ func confirmDeleteAllPopup(selPlaylist *tview.TreeNode) (err error) {
|
||||
gomu.popups.pop()
|
||||
|
||||
if confirmationText == "DELETE" {
|
||||
err := gomu.playlist.deletePlaylist(selPlaylist.GetReference().(*AudioFile))
|
||||
err = gomu.playlist.deletePlaylist(selPlaylist.GetReference().(*AudioFile))
|
||||
if err != nil {
|
||||
logError(err)
|
||||
errorPopup(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user