Skip to content

Commit

Permalink
Merge pull request #147 from Notifiarr/dn2_fixes
Browse files Browse the repository at this point in the history
Fixes.
  • Loading branch information
davidnewhall authored Dec 22, 2021
2 parents a5a1c2d + b6ee342 commit 54469cb
Show file tree
Hide file tree
Showing 20 changed files with 127 additions and 382 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ addons:
- upx
install:
- mkdir -p $(go env GOPATH)/bin
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.41.1
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.43.0
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then rvm install 2.6.0; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then rvm 2.6.0 do gem install --no-document fpm -v 1.11.0; fi
before_script:
Expand Down
2 changes: 1 addition & 1 deletion examples/notifiarr.conf.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
###############################################
# Notifiarr Client Example Configuration File #
# Created by Notifiarr v0.2.1 @ 212910T0624 #
# Created by Notifiarr v0.2.2 @ 212212T1108 #
###############################################

# This API key must be copied from your notifiarr.com account.
Expand Down
21 changes: 12 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.17

// home grown goodness.
require (
golift.io/cnfg v0.0.8
golift.io/cnfg v0.1.0
golift.io/deluge v0.9.3
golift.io/qbit v0.0.0-20211121074815-1558e8969b98
golift.io/rotatorr v0.0.0-20210307012029-65b11a8ea8f9
Expand All @@ -28,18 +28,20 @@ require (
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect
github.com/godbus/dbus/v5 v5.0.6 // indirect
github.com/gonutz/w32 v1.0.0
github.com/iamacarpet/go-win64api v0.0.0-20211108120233-071bd1c17e1c
github.com/iamacarpet/go-win64api v0.0.0-20211130162011-82e31fe23f80
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
)

// snapshot and other stuff.
require (
github.com/BurntSushi/toml v0.4.1 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-sql-driver/mysql v1.6.0
github.com/go-stack/stack v1.8.1 // indirect
github.com/google/cabbie v1.0.2 // indirect
github.com/google/glazier v0.0.0-20211108210834-fdacc9e76703 // indirect
github.com/gopherjs/gopherjs v0.0.0-20210825203111-a709d8e111b3 // indirect
github.com/google/glazier v0.0.0-20211220153819-27898a677049 // indirect
github.com/gopherjs/gopherjs v0.0.0-20211219123610-ec9572f70e60 // indirect
github.com/gopherjs/gopherwasm v1.1.0 // indirect
github.com/gorilla/mux v1.8.0
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b
Expand All @@ -53,15 +55,16 @@ require (
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/scjalliance/comshim v0.0.0-20190308082608-cf06d2532c4e // indirect
github.com/shirou/gopsutil/v3 v3.21.10
github.com/shirou/gopsutil/v3 v3.21.11
github.com/spf13/pflag v1.0.6-0.20201009195203-85dd5c8bc61c
github.com/tklauser/go-sysconf v0.3.9 // indirect
github.com/tklauser/numcpus v0.3.0 // indirect
golang.org/x/mod v0.5.0
golang.org/x/net v0.0.0-20211118161319-6a13c67c3ce4 // indirect
golang.org/x/sys v0.0.0-20211107104306-e0b2ad06fe42
golang.org/x/mod v0.5.1
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
howett.net/plist v0.0.0-20201203080718-1454fab16a06 // indirect
howett.net/plist v1.0.0 // indirect
)
308 changes: 25 additions & 283 deletions go.sum

Large diffs are not rendered by default.

Binary file modified init/windows/application.ico
Binary file not shown.
102 changes: 51 additions & 51 deletions pkg/apps/sabnzbd.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,58 +114,58 @@ type HistorySlots struct {
}

type History struct {
TotalSize SabNZBSize `json:"total_size"`
MonthSize SabNZBSize `json:"month_size"`
WeekSize SabNZBSize `json:"week_size"`
DaySize SabNZBSize `json:"day_size"`
Slots []*HistorySlots `json:"slots"`
Noofslots int `json:"noofslots"`
LastHistoryUpdate int64 `json:"last_history_update"`
Version string `json:"version"`
TotalSize SabNZBSize `json:"total_size"`
MonthSize SabNZBSize `json:"month_size"`
WeekSize SabNZBSize `json:"week_size"`
DaySize SabNZBSize `json:"day_size"`
Slots []HistorySlots `json:"slots"`
Noofslots int `json:"noofslots"`
LastHistoryUpdate int64 `json:"last_history_update"`
Version string `json:"version"`
}

type Queue struct {
Version string `json:"version"`
Paused bool `json:"paused"`
PauseInt string `json:"pause_int"`
PausedAll bool `json:"paused_all"`
Diskspace1 float64 `json:"diskspace1,string"`
Diskspace2 float64 `json:"diskspace2,string"`
Diskspace1Norm SabNZBSize `json:"diskspace1_norm"`
Diskspace2Norm SabNZBSize `json:"diskspace2_norm"`
Diskspacetotal1 float64 `json:"diskspacetotal1,string"`
Diskspacetotal2 float64 `json:"diskspacetotal2,string"`
Loadavg string `json:"loadavg"`
Speedlimit int `json:"speedlimit,string"`
SpeedlimitAbs string `json:"speedlimit_abs"`
HaveWarnings string `json:"have_warnings"`
Finishaction interface{} `json:"finishaction"`
Quota string `json:"quota"`
HaveQuota bool `json:"have_quota"`
LeftQuota string `json:"left_quota"`
CacheArt string `json:"cache_art"`
CacheSize SabNZBSize `json:"cache_size"`
CacheMax int64 `json:"cache_max,string"`
Kbpersec float64 `json:"kbpersec,string"`
Speed SabNZBSize `json:"speed"`
Mbleft float64 `json:"mbleft,string"`
Mb float64 `json:"mb,string"`
Sizeleft SabNZBSize `json:"sizeleft"`
Size SabNZBSize `json:"size"`
NoofslotsTotal int `json:"noofslots_total"`
Status string `json:"status"`
Timeleft string `json:"timeleft"`
Eta string `json:"eta"`
RefreshRate string `json:"refresh_rate"`
InterfaceSettings string `json:"interface_settings"`
Scripts []string `json:"scripts"`
Categories []string `json:"categories"`
RatingEnable bool `json:"rating_enable"`
Noofslots int `json:"noofslots"`
Start int64 `json:"start"`
Limit int64 `json:"limit"`
Finish int64 `json:"finish"`
Slots []*QueueSlots `json:"slots"`
Version string `json:"version"`
Paused bool `json:"paused"`
PauseInt string `json:"pause_int"`
PausedAll bool `json:"paused_all"`
Diskspace1 float64 `json:"diskspace1,string"`
Diskspace2 float64 `json:"diskspace2,string"`
Diskspace1Norm SabNZBSize `json:"diskspace1_norm"`
Diskspace2Norm SabNZBSize `json:"diskspace2_norm"`
Diskspacetotal1 float64 `json:"diskspacetotal1,string"`
Diskspacetotal2 float64 `json:"diskspacetotal2,string"`
Loadavg string `json:"loadavg"`
Speedlimit int `json:"speedlimit,string"`
SpeedlimitAbs string `json:"speedlimit_abs"`
HaveWarnings string `json:"have_warnings"`
Finishaction interface{} `json:"finishaction"`
Quota string `json:"quota"`
HaveQuota bool `json:"have_quota"`
LeftQuota string `json:"left_quota"`
CacheArt string `json:"cache_art"`
CacheSize SabNZBSize `json:"cache_size"`
CacheMax int64 `json:"cache_max,string"`
Kbpersec float64 `json:"kbpersec,string"`
Speed SabNZBSize `json:"speed"`
Mbleft float64 `json:"mbleft,string"`
Mb float64 `json:"mb,string"`
Sizeleft SabNZBSize `json:"sizeleft"`
Size SabNZBSize `json:"size"`
NoofslotsTotal int `json:"noofslots_total"`
Status string `json:"status"`
Timeleft string `json:"timeleft"`
Eta string `json:"eta"`
RefreshRate string `json:"refresh_rate"`
InterfaceSettings string `json:"interface_settings"`
Scripts []string `json:"scripts"`
Categories []string `json:"categories"`
RatingEnable bool `json:"rating_enable"`
Noofslots int `json:"noofslots"`
Start int64 `json:"start"`
Limit int64 `json:"limit"`
Finish int64 `json:"finish"`
Slots []QueueSlots `json:"slots"`
}

func (s *SabNZBConfig) setup(timeout time.Duration) {
Expand All @@ -182,7 +182,7 @@ func (s *SabNZBConfig) setup(timeout time.Duration) {

func (s *SabNZBConfig) GetHistory() (*History, error) {
if s == nil || s.URL == "" {
return nil, nil
return &History{}, nil
}

params := url.Values{}
Expand All @@ -204,7 +204,7 @@ func (s *SabNZBConfig) GetHistory() (*History, error) {

func (s *SabNZBConfig) GetQueue() (*Queue, error) {
if s == nil || s.URL == "" {
return nil, nil
return &Queue{}, nil
}

params := url.Values{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apps/tautulli.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (t *TautulliConfig) setup(timeout time.Duration) {
// GetUsers returns the Tautulli users.
func (t *TautulliConfig) GetUsers() (*TautulliUsers, error) {
if t == nil || t.URL == "" {
return nil, nil
return &TautulliUsers{}, nil
}

params := url.Values{}
Expand Down
24 changes: 11 additions & 13 deletions pkg/client/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,21 @@ var (
)

// forceWriteWithExit is called only when a user passes --write on the command line.
func (c *Client) forceWriteWithExit(f string) error {
if f == "-" {
f = c.Flags.ConfigFile
} else if f == "example" || f == "---" {
func (c *Client) forceWriteWithExit(fileName string) error {
if fileName == "-" {
fileName = c.Flags.ConfigFile
} else if fileName == "example" || fileName == "---" {
// Bubilding a default template.
f = c.Flags.ConfigFile
fileName = c.Flags.ConfigFile
c.Config.LogFile = ""
c.Config.LogConfig.DebugLog = ""
c.Config.HTTPLog = ""
c.Config.FileMode = logs.FileMode(rotatorr.FileMode)
c.Config.Debug = false
c.Config.Snapshot.Interval.Duration = mnd.HalfHour
c.Config.Services.Disabled = false
configfile.ForceAllTmpl = true
}

f, err := c.Config.Write(f)
f, err := c.Config.Write(fileName)
if err != nil { // f purposely shadowed.
return fmt.Errorf("writing config: %s: %w", f, err)
}
Expand All @@ -59,18 +57,18 @@ func printProcessList() error {
return fmt.Errorf("unable to get processes: %w", err)
}

for _, p := range pslist {
for _, proc := range pslist {
if mnd.IsFreeBSD {
fmt.Printf("[%-5d] %s\n", p.PID, p.CmdLine)
fmt.Printf("[%-5d] %s\n", proc.PID, proc.CmdLine)
continue
}

t := "unknown"
if !p.Created.IsZero() {
t = time.Since(p.Created).Round(time.Second).String()
if !proc.Created.IsZero() {
t = time.Since(proc.Created).Round(time.Second).String()
}

fmt.Printf("[%-5d] %-11s: %s\n", p.PID, t, p.CmdLine)
fmt.Printf("[%-5d] %-11s: %s\n", proc.PID, t, proc.CmdLine)
}

return nil
Expand Down
1 change: 0 additions & 1 deletion pkg/client/client_other.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !windows && !darwin
// +build !windows,!darwin

package client

Expand Down
1 change: 0 additions & 1 deletion pkg/mnd/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const (
Megabyte = Kilobyte * Kilobyte
KB100 = Kilobyte * 100
OneDay = 24 * time.Hour
HalfHour = 30 * time.Minute
Base10 = 10
Base8 = 8
Bits64 = 64
Expand Down
2 changes: 1 addition & 1 deletion pkg/snapshot/helpers_others.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !windows
//go:build !windows

package snapshot

Expand Down
2 changes: 1 addition & 1 deletion pkg/snapshot/memory_others.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !linux,!freebsd,!windows
//go:build !linux && !freebsd && !windows

package snapshot

Expand Down
2 changes: 1 addition & 1 deletion pkg/snapshot/synology.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Synology struct {
// GetSynology checks if the app is running on a Synology, and gets system info.
func GetSynology(run bool) (*Synology, error) { //nolint:cyclop
if !run || !mnd.IsSynology {
return nil, nil
return &Synology{}, nil
}

file, err := os.Open(mnd.Synology)
Expand Down
2 changes: 1 addition & 1 deletion pkg/snapshot/users_others.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !windows
//go:build !windows

package snapshot

Expand Down
2 changes: 1 addition & 1 deletion pkg/ui/dlgs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build windows darwin
//go:build windows || darwin

package ui

Expand Down
2 changes: 1 addition & 1 deletion pkg/ui/dlgs_other.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !windows,!darwin
//go:build !windows && !darwin

package ui

Expand Down
4 changes: 2 additions & 2 deletions pkg/ui/menuwrap.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build windows darwin
//go:build windows || darwin

package ui

Expand All @@ -9,7 +9,7 @@ type menuItem struct {
}

// WrapMenu is just gross.
func WrapMenu(m *systray.MenuItem) MenuItem {
func WrapMenu(m *systray.MenuItem) MenuItem { //nolint:ireturn
return MenuItem(&menuItem{MenuItem: m})
}

Expand Down
1 change: 0 additions & 1 deletion pkg/ui/ui_other.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !windows && !darwin
// +build !windows,!darwin

package ui

Expand Down
27 changes: 16 additions & 11 deletions pkg/ui/ui_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,29 @@ func getPNG() string {
return ""
}

const minimumFileSize = 100 // arbitrary

pngPath := filepath.Join(folder, "notifiarr.png")
if f, err := os.Stat(pngPath); err == nil && f.Size() > minimumFileSize {
return pngPath // most code paths land here.
} else if !os.IsNotExist(err) || (f != nil && f.Size() < minimumFileSize) {
return ""
}

data, err := bindata.Asset("files/favicon.png")
if err != nil {
return ""
}

if err := os.WriteFile(pngPath, data, mnd.Mode0600); err != nil {
return ""
const (
percent99 = 0.99
percent101 = 1.01
)

minimumFileSize := int64(float64(len(data)) * percent99)
maximumFileSize := int64(float64(len(data)) * percent101)
pngPath := filepath.Join(folder, "notifiarr.png")

f, err := os.Stat(pngPath)
if err != nil || f.Size() < minimumFileSize || f.Size() > maximumFileSize {
// File does not exist, or not within 1% of correct size. Overwrite it.
if err := os.WriteFile(pngPath, data, mnd.Mode0600); err != nil {
return ""
}
}

// go log.Println("minmaxsize", minimumFileSize, maximumFileSize, f.Size(), len(data))
return pngPath
}

Expand Down
2 changes: 1 addition & 1 deletion settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ HBREPO="golift/homebrew-mugs"
AUREPO="golift/aur"
MAINT="David Newhall II <captain at golift dot io>"
DESC="Unified Client for Notifiarr.com"
GOLANGCI_LINT_ARGS="--enable-all -D exhaustivestruct,nlreturn,forbidigo,cyclop,interfacer,maligned,scopelint,dupl,tagliatelle,golint"
GOLANGCI_LINT_ARGS="--enable-all -D exhaustivestruct,nlreturn,forbidigo,cyclop,interfacer,maligned,scopelint,dupl,tagliatelle,golint,varnamelen"
# Example must exist at examples/$CONFIG_FILE.example
CONFIG_FILE="notifiarr.conf"
LICENSE="MIT"
Expand Down

0 comments on commit 54469cb

Please sign in to comment.