Skip to content

Commit

Permalink
working spotify scroller
Browse files Browse the repository at this point in the history
  • Loading branch information
FKD13 committed Mar 2, 2024
1 parent f25680c commit 7b9fa33
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ func Start(screenApp *screen.ScreenApp) {
r.GET("/message", getMessage)
r.POST("/message", postMessage)

r.POST("/spotify", spotifyHandlerWrapper(screenApp))

r.Run()
}
17 changes: 17 additions & 0 deletions api/spotify.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package api

import (
"github.com/gin-gonic/gin"
"scc/screen"
)

func spotifyHandlerWrapper(app *screen.ScreenApp) func(*gin.Context) {
return func(ctx *gin.Context) {
spotifyHandler(app, ctx)
}
}

func spotifyHandler(app *screen.ScreenApp, ctx *gin.Context) {
b, _ := ctx.GetRawData()
app.Spotify.Update(string(b))
}
12 changes: 10 additions & 2 deletions screen/spotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
"strings"
"sync"
"time"
)

type Spotify struct {
screenApp *ScreenApp
view *tview.TextView

mu sync.Mutex
text string
buffer string
}
Expand Down Expand Up @@ -41,22 +43,28 @@ func (spotify *Spotify) Run() {

if w != 0 {

spotify.mu.Lock()

if len(spotify.buffer) != w {
spotify.buffer = spotify.text + strings.Repeat(" ", w-len(spotify.text))
}

spotify.buffer = spotify.buffer[1:] + string(spotify.buffer[0])

spotify.mu.Unlock()

spotify.screenApp.app.QueueUpdateDraw(func() {
spotify.view.SetText(spotify.buffer)
})

}

time.Sleep(50 * time.Millisecond)
}
}

func (spotify *Spotify) Update(text string) {
spotify.mu.Lock()
defer spotify.mu.Unlock()

spotify.text = text
spotify.buffer = ""
}

0 comments on commit 7b9fa33

Please sign in to comment.