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

Merge pull request #671 from wtfutil/WTF-661-tranismission-blocker

WTF-661 Fix tranmission module to no longer block on initialization
This commit is contained in:
Chris Cummer 2019-10-02 19:35:25 -07:00 committed by GitHub
commit acf6785bba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,15 +34,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
widget.KeyboardWidget.SetView(widget.View) widget.KeyboardWidget.SetView(widget.View)
// Create a persisten transmission client for use in the calls below go buildClient(&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
return &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 // Fetch retrieves torrent data from the Transmission daemon
func (widget *Widget) Fetch() ([]*transmissionrpc.Torrent, error) { func (widget *Widget) Fetch() ([]*transmissionrpc.Torrent, error) {
if widget.client == nil { 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() torrents, err := widget.client.TorrentGetAll()
@ -102,6 +94,20 @@ func (widget *Widget) Unselect() {
/* -------------------- Unexported Functions -------------------- */ /* -------------------- 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 { func (widget *Widget) currentTorrent() *transmissionrpc.Torrent {
if len(widget.torrents) == 0 { if len(widget.torrents) == 0 {
return nil return nil