mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-04-28 13:48:53 +08:00
use popup timeout from config file
This commit is contained in:
parent
8316f3b917
commit
26d3312b6d
@ -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)
|
||||
|
||||
|
16
playlist.go
16
playlist.go
@ -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()
|
||||
|
19
popup.go
19
popup.go
@ -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())
|
||||
|
||||
}
|
||||
|
||||
|
2
start.go
2
start.go
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user