mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Remove the sleeps from the cryptocurrecy modules. Don't need them
This commit is contained in:
parent
c6aee425a0
commit
4c5a203a1f
@ -28,7 +28,7 @@ type TextColors struct {
|
|||||||
|
|
||||||
var ok = true
|
var ok = true
|
||||||
var errorText = ""
|
var errorText = ""
|
||||||
var started = false
|
|
||||||
var baseURL = "https://bittrex.com/api/v1.1/public/getmarketsummary"
|
var baseURL = "https://bittrex.com/api/v1.1/public/getmarketsummary"
|
||||||
|
|
||||||
// Widget define wtf widget to register widget later
|
// Widget define wtf widget to register widget later
|
||||||
@ -40,13 +40,11 @@ type Widget struct {
|
|||||||
|
|
||||||
// NewWidget Make new instance of widget
|
// NewWidget Make new instance of widget
|
||||||
func NewWidget() *Widget {
|
func NewWidget() *Widget {
|
||||||
|
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(" Bittrex ", "bittrex", false),
|
TextWidget: wtf.NewTextWidget(" Bittrex ", "bittrex", false),
|
||||||
summaryList: summaryList{},
|
summaryList: summaryList{},
|
||||||
}
|
}
|
||||||
|
|
||||||
started = false
|
|
||||||
ok = true
|
ok = true
|
||||||
errorText = ""
|
errorText = ""
|
||||||
|
|
||||||
@ -106,20 +104,9 @@ func (widget *Widget) Refresh() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if started == false {
|
widget.updateSummary()
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
widget.updateSummary()
|
|
||||||
time.Sleep(time.Second * time.Duration(widget.RefreshInterval()))
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
started = true
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.UpdateRefreshedAt()
|
widget.UpdateRefreshedAt()
|
||||||
|
|
||||||
widget.display()
|
widget.display()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
@ -13,7 +13,6 @@ import (
|
|||||||
// Config is a pointer to the global config object
|
// Config is a pointer to the global config object
|
||||||
var Config *config.Config
|
var Config *config.Config
|
||||||
|
|
||||||
var started = false
|
|
||||||
var baseURL = "https://min-api.cryptocompare.com/data/price"
|
var baseURL = "https://min-api.cryptocompare.com/data/price"
|
||||||
var ok = true
|
var ok = true
|
||||||
|
|
||||||
@ -26,7 +25,6 @@ type Widget struct {
|
|||||||
|
|
||||||
// NewWidget Make new instance of widget
|
// NewWidget Make new instance of widget
|
||||||
func NewWidget() *Widget {
|
func NewWidget() *Widget {
|
||||||
started = false
|
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(" CryptoLive ", "cryptolive", false),
|
TextWidget: wtf.NewTextWidget(" CryptoLive ", "cryptolive", false),
|
||||||
}
|
}
|
||||||
@ -36,19 +34,6 @@ func NewWidget() *Widget {
|
|||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) setList() {
|
|
||||||
currenciesMap, _ := Config.Map("wtf.mods.cryptolive.currencies")
|
|
||||||
|
|
||||||
widget.list = &list{}
|
|
||||||
|
|
||||||
for currency := range currenciesMap {
|
|
||||||
displayName, _ := Config.String("wtf.mods.cryptolive.currencies." + currency + ".displayName")
|
|
||||||
toList := getToList(currency)
|
|
||||||
widget.list.addItem(currency, displayName, toList)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
// Refresh & update after interval time
|
// Refresh & update after interval time
|
||||||
@ -57,21 +42,8 @@ func (widget *Widget) Refresh() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if started == false {
|
widget.updateCurrencies()
|
||||||
// this code should run once
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
widget.updateCurrencies()
|
|
||||||
time.Sleep(time.Duration(widget.RefreshInterval()) * time.Second)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
started = true
|
|
||||||
|
|
||||||
widget.UpdateRefreshedAt()
|
widget.UpdateRefreshedAt()
|
||||||
widget.View.Clear()
|
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
widget.View.SetText(
|
widget.View.SetText(
|
||||||
@ -79,12 +51,13 @@ func (widget *Widget) Refresh() {
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
display(widget)
|
|
||||||
|
widget.display()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func display(widget *Widget) {
|
func (widget *Widget) display() {
|
||||||
str := ""
|
str := ""
|
||||||
var (
|
var (
|
||||||
fromNameColor = Config.UString("wtf.mods.cryptolive.colors.from.name", "coral")
|
fromNameColor = Config.UString("wtf.mods.cryptolive.colors.from.name", "coral")
|
||||||
@ -118,6 +91,18 @@ func getToList(fromName string) []*toCurrency {
|
|||||||
return toList
|
return toList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) setList() {
|
||||||
|
currenciesMap, _ := Config.Map("wtf.mods.cryptolive.currencies")
|
||||||
|
|
||||||
|
widget.list = &list{}
|
||||||
|
|
||||||
|
for currency := range currenciesMap {
|
||||||
|
displayName, _ := Config.String("wtf.mods.cryptolive.currencies." + currency + ".displayName")
|
||||||
|
toList := getToList(currency)
|
||||||
|
widget.list.addItem(currency, displayName, toList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (widget *Widget) updateCurrencies() {
|
func (widget *Widget) updateCurrencies() {
|
||||||
defer func() {
|
defer func() {
|
||||||
recover()
|
recover()
|
||||||
@ -149,7 +134,7 @@ func (widget *Widget) updateCurrencies() {
|
|||||||
setPrices(&jsonResponse, fromCurrency)
|
setPrices(&jsonResponse, fromCurrency)
|
||||||
}
|
}
|
||||||
|
|
||||||
display(widget)
|
widget.display()
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeRequest(currency *fromCurrency) *http.Request {
|
func makeRequest(currency *fromCurrency) *http.Request {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user