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
11
command.go
11
command.go
@ -43,11 +43,12 @@ func (c Command) defineCommands() {
|
|||||||
|
|
||||||
c.define("delete_playlist", func() {
|
c.define("delete_playlist", func() {
|
||||||
audioFile := gomu.playlist.getCurrentFile()
|
audioFile := gomu.playlist.getCurrentFile()
|
||||||
if !audioFile.isAudioFile {
|
if audioFile.isAudioFile {
|
||||||
err := confirmDeleteAllPopup(audioFile.node)
|
return
|
||||||
if err != nil {
|
}
|
||||||
errorPopup(err)
|
err := confirmDeleteAllPopup(audioFile.node)
|
||||||
}
|
if err != nil {
|
||||||
|
errorPopup(err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
22
playlist.go
22
playlist.go
@ -266,33 +266,17 @@ func (p *Playlist) deleteSong(audioFile *AudioFile) (err error) {
|
|||||||
// Deletes playlist/dir from filesystem
|
// Deletes playlist/dir from filesystem
|
||||||
func (p *Playlist) deletePlaylist(audioFile *AudioFile) (err error) {
|
func (p *Playlist) deletePlaylist(audioFile *AudioFile) (err error) {
|
||||||
|
|
||||||
var selectedDir *AudioFile
|
err = os.RemoveAll(audioFile.path)
|
||||||
|
|
||||||
// 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)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
errorPopup(err)
|
|
||||||
|
|
||||||
err = tracerr.Wrap(err)
|
err = tracerr.Wrap(err)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
defaultTimedPopup(
|
defaultTimedPopup(
|
||||||
" Success ",
|
" Success ",
|
||||||
selectedDir.name+"\nhas been deleted successfully")
|
audioFile.name+"\nhas been deleted successfully")
|
||||||
|
|
||||||
p.refresh()
|
p.refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bulk add a playlist to queue
|
// 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) {
|
func confirmDeleteAllPopup(selPlaylist *tview.TreeNode) (err error) {
|
||||||
|
|
||||||
popupID := "confirm-deleteall-input-popup"
|
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 := newInputPopup(popupID, "Are you sure to delete the folder and all files under it?", "Type DELETE to Confirm: ", "")
|
||||||
|
|
||||||
input.SetDoneFunc(func(key tcell.Key) {
|
input.SetDoneFunc(func(key tcell.Key) {
|
||||||
@ -144,9 +141,9 @@ func confirmDeleteAllPopup(selPlaylist *tview.TreeNode) (err error) {
|
|||||||
gomu.popups.pop()
|
gomu.popups.pop()
|
||||||
|
|
||||||
if confirmationText == "DELETE" {
|
if confirmationText == "DELETE" {
|
||||||
err := gomu.playlist.deletePlaylist(selPlaylist.GetReference().(*AudioFile))
|
err = gomu.playlist.deletePlaylist(selPlaylist.GetReference().(*AudioFile))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logError(err)
|
errorPopup(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user