1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

WTF-661 Fix tranmission module to no longer block on initialization

Fixes #661.
This commit is contained in:
Chris Cummer 2019-10-02 05:58:40 -07:00
parent ca0345a0b4
commit 4aa0f4e43b

View File

@ -34,15 +34,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
widget.KeyboardWidget.SetView(widget.View)
// Create a persisten transmission client for use in the calls below
client, err := transmissionrpc.New(widget.settings.host, widget.settings.username, widget.settings.password,
&transmissionrpc.AdvancedConfig{
Port: widget.settings.port,
})
if err != nil {
client = nil
}
widget.client = client
go buildClient(&widget)
return &widget
}
@ -52,7 +44,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
// Fetch retrieves torrent data from the Transmission daemon
func (widget *Widget) Fetch() ([]*transmissionrpc.Torrent, error) {
if widget.client == nil {
return nil, errors.New("client could not be initialized")
return nil, errors.New("client was not initialized")
}
torrents, err := widget.client.TorrentGetAll()
@ -102,6 +94,20 @@ func (widget *Widget) Unselect() {
/* -------------------- Unexported Functions -------------------- */
// buildClient creates a persisten transmission client
func buildClient(widget *Widget) {
client, err := transmissionrpc.New(widget.settings.host, widget.settings.username, widget.settings.password,
&transmissionrpc.AdvancedConfig{
Port: widget.settings.port,
})
if err != nil {
client = nil
}
widget.client = client
widget.Refresh()
}
func (widget *Widget) currentTorrent() *transmissionrpc.Torrent {
if len(widget.torrents) == 0 {
return nil