use popup timeout from config file

This commit is contained in:
raziman 2020-07-04 09:47:41 +08:00
parent 8316f3b917
commit 26d3312b6d
4 changed files with 27 additions and 12 deletions

View File

@ -81,7 +81,7 @@ func (p *Player) Run() {
popupMessage := fmt.Sprintf("%s\n\n[ %s ]", song.name, fmtDuration(p.length))
timedPopup(" Current Song ", popupMessage, popupTimeout)
timedPopup(" Current Song ", popupMessage, getPopupTimeout())
done := make(chan bool, 1)

View File

@ -118,11 +118,11 @@ func InitPlaylist() *Playlist {
if err != nil {
timedPopup(
" Error ",
"Unable to delete dir "+selectedDir.Name, popupTimeout)
"Unable to delete dir "+selectedDir.Name, getPopupTimeout())
} else {
timedPopup(
" Success ",
selectedDir.Name+"\nhas been deleted successfully", popupTimeout)
selectedDir.Name+"\nhas been deleted successfully", getPopupTimeout())
playlist.Refresh()
}
@ -152,11 +152,11 @@ func InitPlaylist() *Playlist {
if err != nil {
timedPopup(
" Error ", "Unable to delete "+audioFile.Name, popupTimeout)
" Error ", "Unable to delete "+audioFile.Name, getPopupTimeout())
} else {
timedPopup(
" Success ",
audioFile.Name+"\nhas been deleted successfully", popupTimeout)
audioFile.Name+"\nhas been deleted successfully", getPopupTimeout())
playlist.Refresh()
}
@ -467,7 +467,7 @@ func Ytdl(url string, selPlaylist *tview.TreeNode) {
_, err := exec.LookPath("youtube-dl")
if err != nil {
timedPopup(" Error ", "youtube-dl is not in your $PATH", popupTimeout)
timedPopup(" Error ", "youtube-dl is not in your $PATH", getPopupTimeout())
return
}
@ -476,7 +476,7 @@ func Ytdl(url string, selPlaylist *tview.TreeNode) {
selAudioFile := selPlaylist.GetReference().(*AudioFile)
selPlaylistName := selAudioFile.Name
timedPopup(" Ytdl ", "Downloading", popupTimeout)
timedPopup(" Ytdl ", "Downloading", getPopupTimeout())
// specify the output path for ytdl
outputDir := fmt.Sprintf(
@ -502,7 +502,7 @@ func Ytdl(url string, selPlaylist *tview.TreeNode) {
err := cmd.Run()
if err != nil {
timedPopup(" Error ", "Error running youtube-dl", popupTimeout)
timedPopup(" Error ", "Error running youtube-dl", getPopupTimeout())
return
}
@ -523,7 +523,7 @@ func Ytdl(url string, selPlaylist *tview.TreeNode) {
timedPopup(
" Ytdl ",
downloadFinishedMessage,
popupTimeout,
getPopupTimeout(),
)
app.Draw()

View File

@ -16,9 +16,23 @@ import (
// this mitigates the issue of closing all popups when timeout ends
var (
popupCounter = 0
popupTimeout = time.Duration(viper.GetInt("popup_timeout")) * time.Second
)
// gets popup timeout from config file
func getPopupTimeout() time.Duration {
dur := viper.GetString("popup_timeout")
m, err := time.ParseDuration(dur)
if err != nil {
appLog(err)
}
return m
}
func confirmationPopup(
text string,
handler func(buttonIndex int, buttonLabel string),
@ -74,6 +88,7 @@ func timedPopup(title string, desc string, timeout time.Duration) {
pages.AddPage(popupId, topRight(box, 70, 7), true, true)
app.SetFocus(prevPanel.(tview.Primitive))
go func() {
time.Sleep(timeout)
pages.RemovePage(popupId)
@ -93,7 +108,7 @@ func volumePopup(volume float64) {
"50",
)
timedPopup(" Volume ", progress, popupTimeout)
timedPopup(" Volume ", progress, getPopupTimeout())
}

View File

@ -209,7 +209,7 @@ func readConfig() {
viper.SetDefault("music_dir", "~/music")
viper.SetDefault("confirm_on_exit", true)
viper.SetDefault("confirm_bulk_add", true)
viper.SetDefault("popup_timeout", 10)
viper.SetDefault("popup_timeout", "5s")
// creates gomu config dir if does not exist
if _, err := os.Stat(configPath); err != nil {