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

Added a setting to hide the completed downloads in the transmission module (#746)

This commit is contained in:
Toon Schoenmakers 2019-11-13 04:14:49 +00:00 committed by Chris Cummer
parent c6a10295c1
commit 14c2e0c627
2 changed files with 28 additions and 13 deletions

View File

@ -20,6 +20,7 @@ type Settings struct {
port uint16 `help:"The port to connect to the Transmission daemon on"` port uint16 `help:"The port to connect to the Transmission daemon on"`
url string `help:"The RPC URI that the daemon is accessible at"` url string `help:"The RPC URI that the daemon is accessible at"`
username string `help:"The username of the Transmission user"` username string `help:"The username of the Transmission user"`
hideComplete bool `help:"Hide the torrents that are finished downloading"`
} }
// NewSettingsFromYAML creates a new settings instance from a YAML config block // NewSettingsFromYAML creates a new settings instance from a YAML config block
@ -33,6 +34,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
port: uint16(ymlConfig.UInt("port", 9091)), port: uint16(ymlConfig.UInt("port", 9091)),
url: ymlConfig.UString("url", "/transmission/"), url: ymlConfig.UString("url", "/transmission/"),
username: ymlConfig.UString("username", ""), username: ymlConfig.UString("username", ""),
hideComplete: ymlConfig.UBool("hideComplete", false),
} }
return &settings return &settings

View File

@ -57,9 +57,22 @@ func (widget *Widget) Fetch() ([]*transmissionrpc.Torrent, error) {
return nil, err return nil, err
} }
if !widget.settings.hideComplete {
return torrents, nil return torrents, nil
} }
out := make([]*transmissionrpc.Torrent, 0)
for _, torrent := range torrents {
if *torrent.PercentDone == 1.0 {
continue
}
out = append(out, torrent)
}
return out, nil
}
// Refresh updates the data for this widget and displays it onscreen // Refresh updates the data for this widget and displays it onscreen
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
torrents, err := widget.Fetch() torrents, err := widget.Fetch()