mirror of
				https://github.com/taigrr/wtf
				synced 2025-01-18 04:03:14 -08:00 
			
		
		
		
	* WTF-1031 Rename WtfApp.app to WtfApp.tviewApp Signed-off-by: Chris Cummer <chriscummer@me.com> * WTF-1031 Add scaffolding for main to support multiple WtfApp instances Signed-off-by: Chris Cummer <chriscummer@me.com> * WTF-1031 WIP Signed-off-by: Chris Cummer <chriscummer@me.com> * Remove common functionality from KeyboardWidget and into Base Signed-off-by: Chris Cummer <chriscummer@me.com> * Augment with some descriptive comments Signed-off-by: Chris Cummer <chriscummer@me.com> * Add full support for multiple app instances via the AppManager. Still to do: * Config support for multiple apps/multiple config files * The ability to switch between apps Signed-off-by: Chris Cummer <chriscummer@me.com> * Move SetTerminal out of main and into its own file Signed-off-by: Chris Cummer <chriscummer@me.com>
		
			
				
	
	
		
			67 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			67 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package spotifyweb
 | 
						|
 | 
						|
import (
 | 
						|
	"time"
 | 
						|
 | 
						|
	"github.com/gdamore/tcell"
 | 
						|
)
 | 
						|
 | 
						|
func (widget *Widget) initializeKeyboardControls() {
 | 
						|
	widget.InitializeHelpTextKeyboardControl(widget.ShowHelp)
 | 
						|
	widget.InitializeRefreshKeyboardControl(widget.Refresh)
 | 
						|
 | 
						|
	widget.SetKeyboardChar("h", widget.selectPrevious, "Select previous item")
 | 
						|
	widget.SetKeyboardChar("l", widget.selectNext, "Select next item")
 | 
						|
	widget.SetKeyboardChar(" ", widget.playPause, "Play/pause")
 | 
						|
	widget.SetKeyboardChar("s", widget.toggleShuffle, "Toggle shuffle")
 | 
						|
 | 
						|
	widget.SetKeyboardKey(tcell.KeyDown, widget.selectNext, "Select next item")
 | 
						|
	widget.SetKeyboardKey(tcell.KeyUp, widget.selectPrevious, "Select previous item")
 | 
						|
}
 | 
						|
 | 
						|
func (widget *Widget) selectPrevious() {
 | 
						|
	err := widget.client.Previous()
 | 
						|
	if err != nil {
 | 
						|
		return
 | 
						|
	}
 | 
						|
 | 
						|
	time.Sleep(time.Millisecond * 500)
 | 
						|
	widget.Refresh()
 | 
						|
}
 | 
						|
 | 
						|
func (widget *Widget) selectNext() {
 | 
						|
	err := widget.client.Next()
 | 
						|
	if err != nil {
 | 
						|
		return
 | 
						|
	}
 | 
						|
 | 
						|
	time.Sleep(time.Millisecond * 500)
 | 
						|
	widget.Refresh()
 | 
						|
}
 | 
						|
 | 
						|
func (widget *Widget) playPause() {
 | 
						|
	var err error
 | 
						|
	if widget.playerState.CurrentlyPlaying.Playing {
 | 
						|
		err = widget.client.Pause()
 | 
						|
	} else {
 | 
						|
		err = widget.client.Play()
 | 
						|
	}
 | 
						|
	if err != nil {
 | 
						|
		return
 | 
						|
	}
 | 
						|
 | 
						|
	time.Sleep(time.Millisecond * 500)
 | 
						|
	widget.Refresh()
 | 
						|
}
 | 
						|
 | 
						|
func (widget *Widget) toggleShuffle() {
 | 
						|
	widget.playerState.ShuffleState = !widget.playerState.ShuffleState
 | 
						|
	err := widget.client.Shuffle(widget.playerState.ShuffleState)
 | 
						|
	if err != nil {
 | 
						|
		return
 | 
						|
	}
 | 
						|
 | 
						|
	time.Sleep(time.Millisecond * 500)
 | 
						|
	widget.Refresh()
 | 
						|
}
 |