mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
adding Spotify Module for https://github.com/senorprogrammer/wtf/issues/305
This commit is contained in:
parent
5569640c15
commit
f86f04080f
3
main.go
3
main.go
@ -39,6 +39,7 @@ import (
|
|||||||
"github.com/senorprogrammer/wtf/opsgenie"
|
"github.com/senorprogrammer/wtf/opsgenie"
|
||||||
"github.com/senorprogrammer/wtf/power"
|
"github.com/senorprogrammer/wtf/power"
|
||||||
"github.com/senorprogrammer/wtf/security"
|
"github.com/senorprogrammer/wtf/security"
|
||||||
|
"github.com/senorprogrammer/wtf/spotify"
|
||||||
"github.com/senorprogrammer/wtf/status"
|
"github.com/senorprogrammer/wtf/status"
|
||||||
"github.com/senorprogrammer/wtf/system"
|
"github.com/senorprogrammer/wtf/system"
|
||||||
"github.com/senorprogrammer/wtf/textfile"
|
"github.com/senorprogrammer/wtf/textfile"
|
||||||
@ -238,6 +239,8 @@ func addWidget(app *tview.Application, pages *tview.Pages, widgetName string) {
|
|||||||
widgets = append(widgets, status.NewWidget())
|
widgets = append(widgets, status.NewWidget())
|
||||||
case "system":
|
case "system":
|
||||||
widgets = append(widgets, system.NewWidget(date, version))
|
widgets = append(widgets, system.NewWidget(date, version))
|
||||||
|
case "spotify":
|
||||||
|
widgets = append(widgets, spotify.NewWidget(app, pages))
|
||||||
case "textfile":
|
case "textfile":
|
||||||
widgets = append(widgets, textfile.NewWidget(app, pages))
|
widgets = append(widgets, textfile.NewWidget(app, pages))
|
||||||
case "todo":
|
case "todo":
|
||||||
|
90
spotify/widget.go
Normal file
90
spotify/widget.go
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
package spotify
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gdamore/tcell"
|
||||||
|
"github.com/rivo/tview"
|
||||||
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
|
"github.com/sticreations/spotigopher/spotigopher"
|
||||||
|
)
|
||||||
|
|
||||||
|
const HelpText = `
|
||||||
|
Keyboard commands for Textfile:
|
||||||
|
TESTTEST
|
||||||
|
`
|
||||||
|
|
||||||
|
type Widget struct {
|
||||||
|
wtf.HelpfulWidget
|
||||||
|
wtf.TextWidget
|
||||||
|
spotigopher.SpotifyClient
|
||||||
|
spotigopher.Info
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
||||||
|
spotifyClient := spotigopher.NewClient()
|
||||||
|
widget := Widget{
|
||||||
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
|
TextWidget: wtf.NewTextWidget("Spotify", "spotify", true),
|
||||||
|
SpotifyClient: spotifyClient,
|
||||||
|
Info: spotigopher.Info{},
|
||||||
|
}
|
||||||
|
widget.HelpfulWidget.SetView(widget.View)
|
||||||
|
widget.TextWidget.RefreshInt = 5
|
||||||
|
widget.View.SetInputCapture(widget.captureInput)
|
||||||
|
widget.View.SetWrap(true)
|
||||||
|
widget.View.SetWordWrap(true)
|
||||||
|
widget.View.SetTitle(fmt.Sprint("[green]Spotify[white]"))
|
||||||
|
return &widget
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Widget) refreshSpotifyInfos() error {
|
||||||
|
info, err := w.SpotifyClient.GetInfo()
|
||||||
|
w.Info = info
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Widget) Refresh() {
|
||||||
|
w.render()
|
||||||
|
w.UpdateRefreshedAt()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Widget) render() {
|
||||||
|
err := w.refreshSpotifyInfos()
|
||||||
|
w.View.Clear()
|
||||||
|
if err != nil {
|
||||||
|
w.TextWidget.View.SetText(err.Error())
|
||||||
|
} else {
|
||||||
|
w.TextWidget.View.SetText(w.createOutput())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Widget) captureInput(event *tcell.EventKey) *tcell.EventKey {
|
||||||
|
switch (string)(event.Rune()) {
|
||||||
|
case "h":
|
||||||
|
w.SpotifyClient.Previous()
|
||||||
|
time.Sleep(time.Second * 1)
|
||||||
|
w.Refresh()
|
||||||
|
return nil
|
||||||
|
case "l":
|
||||||
|
w.SpotifyClient.Next()
|
||||||
|
time.Sleep(time.Second * 1)
|
||||||
|
w.Refresh()
|
||||||
|
return nil
|
||||||
|
case " ":
|
||||||
|
w.SpotifyClient.PlayPause()
|
||||||
|
time.Sleep(time.Second * 1)
|
||||||
|
w.Refresh()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Widget) createOutput() string {
|
||||||
|
output := wtf.CenterText(fmt.Sprintf("[green]Now %v [white]\n", w.Info.Status), w.Width())
|
||||||
|
output += wtf.CenterText(fmt.Sprintf("[green]Title:[white] %v\n ", w.Info.Title), w.Width())
|
||||||
|
output += wtf.CenterText(fmt.Sprintf("[green]Artist:[white] %v\n", w.Info.Artist), w.Width())
|
||||||
|
output += wtf.CenterText(fmt.Sprintf("[green]%v:[white] %v\n", w.Info.TrackNumber, w.Info.Album), w.Width())
|
||||||
|
return output
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user