From 161a77d58d7be79e8f1e6bc4bf25a53f6f5cb234 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 10 Jul 2024 00:12:53 -0700 Subject: [PATCH 01/12] add now to popups --- pkg/ui/dlgs.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pkg/ui/dlgs.go b/pkg/ui/dlgs.go index 5bef11081..59e0a76f9 100644 --- a/pkg/ui/dlgs.go +++ b/pkg/ui/dlgs.go @@ -2,7 +2,15 @@ package ui -import "github.com/gen2brain/dlgs" +import ( + "time" + + "github.com/gen2brain/dlgs" +) + +func now() string { + return "\nNow: " + time.Now().Format("Mon Jan 2, 2006 @ 15:04:05 MST") +} // Warning wraps dlgs.Warning. func Warning(title, msg string) (bool, error) { @@ -10,7 +18,7 @@ func Warning(title, msg string) (bool, error) { return true, nil } - return dlgs.Warning(title, msg) //nolint:wrapcheck + return dlgs.Warning(title, msg+now()) //nolint:wrapcheck } // Error wraps dlgs.Error. @@ -19,7 +27,7 @@ func Error(title, msg string) (bool, error) { return true, nil } - return dlgs.Error(title, msg) //nolint:wrapcheck + return dlgs.Error(title, msg+now()) //nolint:wrapcheck } // Info wraps dlgs.Info. @@ -28,7 +36,7 @@ func Info(title, msg string) (bool, error) { return true, nil } - return dlgs.Info(title, msg) //nolint:wrapcheck + return dlgs.Info(title, msg+now()) //nolint:wrapcheck } // Entry wraps dlgs.Entry. @@ -37,7 +45,7 @@ func Entry(title, msg, val string) (string, bool, error) { return val, true, nil } - return dlgs.Entry(title, msg, val) //nolint:wrapcheck + return dlgs.Entry(title, msg+now(), val) //nolint:wrapcheck } // Question wraps dlgs.Question. @@ -46,5 +54,5 @@ func Question(title, text string, defaultCancel bool) (bool, error) { return true, nil } - return dlgs.Question(title, text, defaultCancel) //nolint:wrapcheck + return dlgs.Question(title, text+now(), defaultCancel) //nolint:wrapcheck } From 3ff699798478c0206be20cae055f3808bb41008f Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 10 Jul 2024 00:47:06 -0700 Subject: [PATCH 02/12] do not poll with no api key --- pkg/triggers/crontimer/custom.go | 23 +++++++++++++++-------- pkg/website/website.go | 4 ++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pkg/triggers/crontimer/custom.go b/pkg/triggers/crontimer/custom.go index d1d3e3f87..6073a07fc 100644 --- a/pkg/triggers/crontimer/custom.go +++ b/pkg/triggers/crontimer/custom.go @@ -10,6 +10,7 @@ import ( "github.com/Notifiarr/notifiarr/pkg/triggers/common" "github.com/Notifiarr/notifiarr/pkg/website" "github.com/Notifiarr/notifiarr/pkg/website/clientinfo" + "github.com/hako/durafmt" "golift.io/cnfg" ) @@ -82,14 +83,7 @@ func (c *cmd) create() { ci := clientinfo.Get() // This poller is sorta shoehorned in here for lack of a better place to put it. if ci == nil { - c.Printf("==> Started Notifiarr Poller, have_clientinfo:%v interval:%s", - ci != nil, cnfg.Duration{Duration: pollDur.Round(time.Second)}) - c.Add(&common.Action{ - Name: TrigPollSite, - Fn: c.PollForReload, - D: cnfg.Duration{Duration: pollDur + time.Duration(c.Config.Rand().Intn(randomSeconds))*time.Second}, - }) - + c.startWebsitePoller() return } @@ -123,6 +117,19 @@ func (c *cmd) create() { c.Printf("==> Custom Timers Enabled: %d timers provided", len(ci.Actions.Custom)) } +func (c *cmd) startWebsitePoller() { + if c.ValidAPIKey() != nil { + return // only poll if the api key length is valid. + } + + c.Printf("==> Started Notifiarr Website Poller, interval: %s", durafmt.Parse(pollDur)) + c.Add(&common.Action{ + Name: TrigPollSite, + Fn: c.PollForReload, + D: cnfg.Duration{Duration: pollDur + time.Duration(c.Config.Rand().Intn(randomSeconds))*time.Second}, + }) +} + // PollForReload is only started if the initial connection to the website failed. // This will keep checking until it works, then reload to grab settings and start properly. func (c *cmd) PollForReload(ctx context.Context, input *common.ActionInput) { diff --git a/pkg/website/website.go b/pkg/website/website.go index aea71a281..e1c751574 100644 --- a/pkg/website/website.go +++ b/pkg/website/website.go @@ -24,7 +24,7 @@ type httpClient struct { *http.Client } -func (s *Server) validAPIKey() error { +func (s *Server) ValidAPIKey() error { if len(s.Config.Apps.APIKey) != APIKeyLength { return fmt.Errorf("%w: length must be %d characters", ErrInvalidAPIKey, APIKeyLength) } @@ -326,7 +326,7 @@ func (s *Server) watchSendDataChan(ctx context.Context) { } func (s *Server) sendRequest(ctx context.Context, data *Request) (*Response, time.Duration, error) { - if err := s.validAPIKey(); err != nil { + if err := s.ValidAPIKey(); err != nil { if data.respChan != nil { data.respChan <- &chResponse{ Response: nil, From 24927f5d37b06858a676f8eeed8998b5aad42896 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 10 Jul 2024 11:15:10 -0700 Subject: [PATCH 03/12] update cnfgfile --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e6fbc78a5..6e5ebea0a 100644 --- a/go.mod +++ b/go.mod @@ -40,7 +40,7 @@ require ( golang.org/x/time v0.5.0 golift.io/cache v0.0.2 golift.io/cnfg v0.2.3 - golift.io/cnfgfile v0.0.0-20240704165116-48378d0c6c38 + golift.io/cnfgfile v0.0.0-20240710181404-c328b7f27f47 golift.io/datacounter v1.0.4 golift.io/deluge v0.10.1 golift.io/mulery v0.0.8 diff --git a/go.sum b/go.sum index 087294b30..14d44c7d1 100644 --- a/go.sum +++ b/go.sum @@ -426,8 +426,8 @@ golift.io/cache v0.0.2 h1:759rPK+EOy6UX7HkqsesOToSQ3CWN4UN3b5BiehfpeY= golift.io/cache v0.0.2/go.mod h1:wT61rGyiP50Rg243x5UF8dWBEKSr1RpB0GpgIF5kOGE= golift.io/cnfg v0.2.3 h1:cQsC4JS20njJyu5drtGefNmgN7M4HrLaRDNBPLit3pQ= golift.io/cnfg v0.2.3/go.mod h1:T4t8MFa8aZilCdIk1qQrN4mOGaFVPZ/qHQBBMbCIZJ0= -golift.io/cnfgfile v0.0.0-20240704165116-48378d0c6c38 h1:euXQUUWtsi2M+Bf6Do4+yG3YrVj88WyN0WJdv/abeW0= -golift.io/cnfgfile v0.0.0-20240704165116-48378d0c6c38/go.mod h1:zHm9o8SkZ6Mm5DfGahsrEJPsogyR0qItP59s5lJ98/I= +golift.io/cnfgfile v0.0.0-20240710181404-c328b7f27f47 h1:ZZTKukG461j1npgWoIy6PI0RdkH29y3zBtXBPyzNEbg= +golift.io/cnfgfile v0.0.0-20240710181404-c328b7f27f47/go.mod h1:zHm9o8SkZ6Mm5DfGahsrEJPsogyR0qItP59s5lJ98/I= golift.io/datacounter v1.0.4 h1:b2gLQCs8WYRtKjOMG0qM82rF1o0+oKUXB9QH7kjmxZ4= golift.io/datacounter v1.0.4/go.mod h1:79Yf1ucynYvZzVS/hpfrAFt6y/w82FMlOJgh+MBaZvs= golift.io/deluge v0.10.1 h1:wu1GzXsDYzWGnRl4mNEd2IeY0O7+jhYJ4IKBPfDEanM= From 645ca5c5bf43cb3bcdc713173d2067dcaa414c3a Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 10 Jul 2024 13:10:54 -0700 Subject: [PATCH 04/12] detect console on windows --- Makefile | 3 +++ go.mod | 2 +- go.sum | 4 ++-- pkg/logs/logfile_others.go | 4 ++++ pkg/logs/logfiles_windows.go | 26 ++++++++++++++++++++++++++ pkg/logs/logs.go | 5 +---- 6 files changed, 37 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 7936e267d..26c29d40c 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,9 @@ include /tmp/.metadata.make # Travis CI passes the version in. Local builds get it from the current git tag. ifneq ($(_VERSION),) VERSION:=$(_VERSION) +endif + +ifneq ($(_ITERATION),) ITERATION:=$(_ITERATION) endif diff --git a/go.mod b/go.mod index 6e5ebea0a..0a8872bdd 100644 --- a/go.mod +++ b/go.mod @@ -40,7 +40,7 @@ require ( golang.org/x/time v0.5.0 golift.io/cache v0.0.2 golift.io/cnfg v0.2.3 - golift.io/cnfgfile v0.0.0-20240710181404-c328b7f27f47 + golift.io/cnfgfile v0.0.0-20240710195711-cc964880efd6 golift.io/datacounter v1.0.4 golift.io/deluge v0.10.1 golift.io/mulery v0.0.8 diff --git a/go.sum b/go.sum index 14d44c7d1..02cce840a 100644 --- a/go.sum +++ b/go.sum @@ -426,8 +426,8 @@ golift.io/cache v0.0.2 h1:759rPK+EOy6UX7HkqsesOToSQ3CWN4UN3b5BiehfpeY= golift.io/cache v0.0.2/go.mod h1:wT61rGyiP50Rg243x5UF8dWBEKSr1RpB0GpgIF5kOGE= golift.io/cnfg v0.2.3 h1:cQsC4JS20njJyu5drtGefNmgN7M4HrLaRDNBPLit3pQ= golift.io/cnfg v0.2.3/go.mod h1:T4t8MFa8aZilCdIk1qQrN4mOGaFVPZ/qHQBBMbCIZJ0= -golift.io/cnfgfile v0.0.0-20240710181404-c328b7f27f47 h1:ZZTKukG461j1npgWoIy6PI0RdkH29y3zBtXBPyzNEbg= -golift.io/cnfgfile v0.0.0-20240710181404-c328b7f27f47/go.mod h1:zHm9o8SkZ6Mm5DfGahsrEJPsogyR0qItP59s5lJ98/I= +golift.io/cnfgfile v0.0.0-20240710195711-cc964880efd6 h1:iTLfwDsKKw+5aEPi2QgFI32C7XiojotH/ZfWD/XMWcY= +golift.io/cnfgfile v0.0.0-20240710195711-cc964880efd6/go.mod h1:zHm9o8SkZ6Mm5DfGahsrEJPsogyR0qItP59s5lJ98/I= golift.io/datacounter v1.0.4 h1:b2gLQCs8WYRtKjOMG0qM82rF1o0+oKUXB9QH7kjmxZ4= golift.io/datacounter v1.0.4/go.mod h1:79Yf1ucynYvZzVS/hpfrAFt6y/w82FMlOJgh+MBaZvs= golift.io/deluge v0.10.1 h1:wu1GzXsDYzWGnRl4mNEd2IeY0O7+jhYJ4IKBPfDEanM= diff --git a/pkg/logs/logfile_others.go b/pkg/logs/logfile_others.go index f2142e632..c9a329094 100644 --- a/pkg/logs/logfile_others.go +++ b/pkg/logs/logfile_others.go @@ -38,3 +38,7 @@ func getFileOwner(fileInfo os.FileInfo) string { return uid + ":" + gid } + +func hasConsoleWindow() bool { + return true +} diff --git a/pkg/logs/logfiles_windows.go b/pkg/logs/logfiles_windows.go index 5abdb8d1c..0c64e26c7 100644 --- a/pkg/logs/logfiles_windows.go +++ b/pkg/logs/logfiles_windows.go @@ -1,9 +1,35 @@ package logs import ( + "debug/pe" "os" ) func getFileOwner(_ os.FileInfo) string { return "" } + +// Sometimes we compile with -H=windowsgui and sometimes without. +// Having this function allows us to detect which, so we can turn on/off console logging. +func hasConsoleWindow() bool { + exe, err := os.Executable() + if err != nil { + return false + } + + file, err := pe.Open(exe) + if err != nil { + return false + } + defer file.Close() + + const IMAGE_SUBSYSTEM_WINDOWS_CUI = 3 + + if header, ok := file.OptionalHeader.(*pe.OptionalHeader64); ok { + return header.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI + } else if header, ok := file.OptionalHeader.(*pe.OptionalHeader32); ok { + return header.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI + } + + return false +} diff --git a/pkg/logs/logs.go b/pkg/logs/logs.go index 6da7ee22e..e27bedae6 100644 --- a/pkg/logs/logs.go +++ b/pkg/logs/logs.go @@ -95,10 +95,7 @@ func (l *Logger) SetupLogging(config *LogConfig) { logFiles = config.LogFiles logFileMb = config.LogFileMb l.LogConfig = config - - if mnd.IsWindows { - config.Quiet = true - } + config.Quiet = !hasConsoleWindow() l.setDefaultLogPaths() l.setAppLogPath() From e95dbc0c57903b4617d1d1a677c8cca60b0d0ec1 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 10 Jul 2024 15:21:20 -0700 Subject: [PATCH 05/12] mac temps --- go.mod | 2 ++ go.sum | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 0a8872bdd..0a096763b 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,8 @@ go 1.22 // pflag and tail are pinned to master. 12/31/2022 +replace github.com/shirou/gopsutil/v4 => github.com/Girbons/gopsutil/v4 v4.0.0-20240708140948-ba82fefdee75 + require ( github.com/BurntSushi/toml v1.4.0 github.com/akavel/rsrc v0.10.2 diff --git a/go.sum b/go.sum index 02cce840a..6fae1225d 100644 --- a/go.sum +++ b/go.sum @@ -21,6 +21,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Girbons/gopsutil/v4 v4.0.0-20240708140948-ba82fefdee75 h1:lz2b9BI2CaVAsIAfc3jD7ip0hyIwrngEKs2vR4YWlp0= +github.com/Girbons/gopsutil/v4 v4.0.0-20240708140948-ba82fefdee75/go.mod h1:aoebb2vxetJ/yIDZISmduFvVNPHqXQ9SEJwRXxkf0RA= github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA= @@ -228,8 +230,6 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd/go.mod h1:hPqNNc0+uJM6H+SuU8sEs5K5IQeKccPqeSjfgcKGgPk= -github.com/shirou/gopsutil/v4 v4.24.6 h1:9qqCSYF2pgOU+t+NgJtp7Co5+5mHF/HyKBUckySQL64= -github.com/shirou/gopsutil/v4 v4.24.6/go.mod h1:aoebb2vxetJ/yIDZISmduFvVNPHqXQ9SEJwRXxkf0RA= github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= From 639fd22062d5556c6b7fe8acb2c8a20011bd7047 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 10 Jul 2024 17:43:49 -0700 Subject: [PATCH 06/12] fixes --- pkg/logs/logfiles_windows.go | 6 +++--- pkg/logs/logs.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/logs/logfiles_windows.go b/pkg/logs/logfiles_windows.go index 0c64e26c7..d25a2141f 100644 --- a/pkg/logs/logfiles_windows.go +++ b/pkg/logs/logfiles_windows.go @@ -23,12 +23,12 @@ func hasConsoleWindow() bool { } defer file.Close() - const IMAGE_SUBSYSTEM_WINDOWS_CUI = 3 + const windowsTerminal = 3 if header, ok := file.OptionalHeader.(*pe.OptionalHeader64); ok { - return header.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI + return header.Subsystem == windowsTerminal } else if header, ok := file.OptionalHeader.(*pe.OptionalHeader32); ok { - return header.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI + return header.Subsystem == windowsTerminal } return false diff --git a/pkg/logs/logs.go b/pkg/logs/logs.go index e27bedae6..70648fd5f 100644 --- a/pkg/logs/logs.go +++ b/pkg/logs/logs.go @@ -95,7 +95,7 @@ func (l *Logger) SetupLogging(config *LogConfig) { logFiles = config.LogFiles logFileMb = config.LogFileMb l.LogConfig = config - config.Quiet = !hasConsoleWindow() + config.Quiet = !hasConsoleWindow() || config.Quiet l.setDefaultLogPaths() l.setAppLogPath() From c38ac503f46423a6e5719c2f15f6dbcbff6b67f1 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Fri, 12 Jul 2024 15:47:53 -0700 Subject: [PATCH 07/12] add a bit more info to startup logs --- pkg/client/init.go | 19 ++++++++++++++----- pkg/client/start.go | 7 ++++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/pkg/client/init.go b/pkg/client/init.go index a60863cb5..161889b87 100644 --- a/pkg/client/init.go +++ b/pkg/client/init.go @@ -7,6 +7,7 @@ package client import ( "context" + "os" "path" "github.com/Notifiarr/notifiarr/pkg/mnd" @@ -42,8 +43,10 @@ func (c *Client) PrintStartupInfo(ctx context.Context, clientInfo *clientinfo.Cl c.Printf("==> Unique Host ID: %s (%s)", hi.HostID, hi.Hostname) } + hostname, _ := os.Hostname() + c.Printf("==> %s <==", mnd.HelpLink) - c.Printf("==> Startup Settings <==") + c.Printf("==> %s Startup Settings <==", hostname) c.printLidarr(&clientInfo.Actions.Apps.Lidarr) c.printProwlarr(&clientInfo.Actions.Apps.Prowlarr) c.printRadarr(&clientInfo.Actions.Apps.Radarr) @@ -83,15 +86,21 @@ func (c *Client) printVersionChangeInfo(ctx context.Context) { c.Errorf("XX> Getting version from database: %v", err) } + currentVersion := version.Version + "-" + version.Revision previousVersion := string(values[clientVersion]) - if previousVersion == version.Version || - version.Version == "" { + + if previousVersion == currentVersion || version.Version == "" { return } - c.Printf("==> Detected application version change! %s => %s", previousVersion, version.Version) + if previousVersion == "" { + hostname, _ := os.Hostname() + c.Printf("==> Detected a new client, %s. Welcome to Notifiarr!", hostname) + } else { + c.Printf("==> Detected application version change! %s => %s", previousVersion, currentVersion) + } - err = c.website.SetState(ctx, clientVersion, []byte(version.Version)) + err = c.website.SetState(ctx, clientVersion, []byte(currentVersion)) if err != nil { c.Errorf("Updating version in database: %v", err) } diff --git a/pkg/client/start.go b/pkg/client/start.go index 99c1c894b..00b28c4d6 100644 --- a/pkg/client/start.go +++ b/pkg/client/start.go @@ -151,9 +151,10 @@ func (c *Client) start(ctx context.Context) error { //nolint:cyclop } c.Logger.SetupLogging(c.Config.LogConfig) - c.Printf(" %s %s v%s-%s Starting! [PID: %v] %s", - mnd.TodaysEmoji(), c.Flags.Name(), version.Version, version.Revision, os.Getpid(), - version.Started.Format("Monday, January 2, 2006 @ 3:04:05 PM MST -0700")) + c.Printf(" %s %s v%s-%s Starting! [PID: %v, UID: %d, GID: %d] %s", + mnd.TodaysEmoji(), mnd.Title, version.Version, version.Revision, + os.Getpid(), os.Getuid(), os.Getgid(), + version.Started.Format("Mon, Jan 2, 2006 @ 3:04:05 PM MST -0700")) c.Printf("==> %s", msg) c.printUpdateMessage() From 13846500d0fac1c5f4deb86d702ab86bd91cce19 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Tue, 16 Jul 2024 23:12:52 -0700 Subject: [PATCH 08/12] lint --- pkg/client/start.go | 23 +++++++++++++---------- pkg/client/tray.go | 7 +++---- pkg/client/webserver.go | 3 +-- pkg/configfile/config.go | 3 +++ 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/pkg/client/start.go b/pkg/client/start.go index 00b28c4d6..4e7488b4f 100644 --- a/pkg/client/start.go +++ b/pkg/client/start.go @@ -103,7 +103,7 @@ func Start() error { _, err := fmt.Println(client.Flags.Name() + " " + version.Version + "-" + version.Revision) return err case client.Flags.PSlist: // print process list and exit. - ctx, cancel := context.WithTimeout(ctx, time.Minute) + ctx, cancel := context.WithTimeout(ctx, mnd.DefaultTimeout) defer cancel() return printProcessList(ctx) @@ -113,11 +113,11 @@ func Start() error { case client.Flags.Curl != "": // curl a URL and exit. return curlURL(client.Flags.Curl, client.Flags.Headers) default: - return client.start(ctx) + return client.checkFlags(ctx) } } -func (c *Client) start(ctx context.Context) error { //nolint:cyclop +func (c *Client) checkFlags(ctx context.Context) error { //nolint:cyclop msg, newPassword, err := c.loadConfiguration(ctx) ctx, cancel := context.WithCancel(ctx) @@ -131,14 +131,14 @@ func (c *Client) start(ctx context.Context) error { //nolint:cyclop return fmt.Errorf("cannot reset admin password, got error reading configuration file: %w", err) } - ctx, cancel := context.WithTimeout(ctx, time.Minute) + ctx, cancel := context.WithTimeout(ctx, mnd.DefaultTimeout) defer cancel() return c.resetAdminPassword(ctx) case c.Flags.Write != "" && (err == nil || strings.Contains(err.Error(), "ip:port")): c.Printf("==> %s", msg) - ctx, cancel := context.WithTimeout(ctx, time.Minute) + ctx, cancel := context.WithTimeout(ctx, mnd.DefaultTimeout) defer cancel() return c.forceWriteWithExit(ctx, c.Flags.Write) @@ -148,8 +148,12 @@ func (c *Client) start(ctx context.Context) error { //nolint:cyclop return nil case c.Config.APIKey == "": return fmt.Errorf("%s: %w %s_API_KEY", msg, ErrNilAPIKey, c.Flags.EnvPrefix) + default: + return c.start(ctx, msg, newPassword) } +} +func (c *Client) start(ctx context.Context, msg, newPassword string) error { c.Logger.SetupLogging(c.Config.LogConfig) c.Printf(" %s %s v%s-%s Starting! [PID: %v, UID: %d, GID: %d] %s", mnd.TodaysEmoji(), mnd.Title, version.Version, version.Revision, @@ -174,15 +178,15 @@ func (c *Client) start(ctx context.Context) error { //nolint:cyclop if ui.HasGUI() { // This starts the web server and calls os.Exit() when done. - c.startTray(ctx, cancel, clientInfo) + c.startTray(ctx, clientInfo) return nil } - return c.Exit(ctx, cancel) + return c.Exit(ctx) } func (c *Client) makeNewConfigFile(ctx context.Context, newPassword string) { - ctx, cancel := context.WithTimeout(ctx, time.Minute) + ctx, cancel := context.WithTimeout(ctx, mnd.DefaultTimeout) defer cancel() _, _ = c.Config.Write(ctx, c.Flags.ConfigFile, false) @@ -279,10 +283,9 @@ func (c *Client) triggerConfigReload(event website.EventType, source string) { } // Exit stops the web server and logs our exit messages. Start() calls this. -func (c *Client) Exit(ctx context.Context, cancel context.CancelFunc) error { +func (c *Client) Exit(ctx context.Context) error { defer func() { defer c.CapturePanic() - cancel() c.Print(" ❌ Good bye! Exiting" + mnd.DurationAge(version.Started)) }() diff --git a/pkg/client/tray.go b/pkg/client/tray.go index 17ef090ff..e6aa12fa8 100644 --- a/pkg/client/tray.go +++ b/pkg/client/tray.go @@ -8,7 +8,6 @@ import ( "fmt" "os" "strings" - "time" "github.com/Notifiarr/notifiarr/pkg/bindata" "github.com/Notifiarr/notifiarr/pkg/mnd" @@ -29,7 +28,7 @@ const timerPrefix = "TimErr" var menu = make(map[string]*systray.MenuItem) //nolint:gochecknoglobals // startTray Run()s readyTray to bring up the web server and the GUI app. -func (c *Client) startTray(ctx context.Context, cancel context.CancelFunc, clientInfo *clientinfo.ClientInfo) { +func (c *Client) startTray(ctx context.Context, clientInfo *clientinfo.ClientInfo) { systray.Run(func() { defer os.Exit(0) defer c.CapturePanic() @@ -44,7 +43,7 @@ func (c *Client) startTray(ctx context.Context, cancel context.CancelFunc, clien c.setupMenus(clientInfo) // code that runs on reload, too. // This starts the web server, and waits for reload/exit signals. - if err := c.Exit(ctx, cancel); err != nil { + if err := c.Exit(ctx); err != nil { c.Errorf("Server: %v", err) os.Exit(1) // web server problem } @@ -164,7 +163,7 @@ func (c *Client) configMenu(ctx context.Context) { menu["write"] = conf.AddSubMenuItem("Write", "write config file") menu["write"].Click(func() { - ctx, cancel := context.WithTimeout(ctx, time.Minute) + ctx, cancel := context.WithTimeout(ctx, mnd.DefaultTimeout) defer cancel() c.writeConfigFile(ctx) }) diff --git a/pkg/client/webserver.go b/pkg/client/webserver.go index 992a01eb1..cbe4e56dd 100644 --- a/pkg/client/webserver.go +++ b/pkg/client/webserver.go @@ -9,7 +9,6 @@ import ( "net/http" "os" "path" - "time" "github.com/Notifiarr/notifiarr/pkg/mnd" "github.com/gorilla/mux" @@ -42,7 +41,7 @@ func (c *Client) StartWebServer(ctx context.Context) { c.server = &http.Server{ //nolint: exhaustivestruct Handler: smx, Addr: c.Config.BindAddr, - IdleTimeout: time.Minute, + IdleTimeout: mnd.DefaultTimeout, WriteTimeout: c.Config.Timeout.Duration, ReadTimeout: c.Config.Timeout.Duration, ReadHeaderTimeout: c.Config.Timeout.Duration, diff --git a/pkg/configfile/config.go b/pkg/configfile/config.go index d73ae4232..d00544931 100644 --- a/pkg/configfile/config.go +++ b/pkg/configfile/config.go @@ -315,6 +315,9 @@ func (c *Config) Write(ctx context.Context, file string, encode bool) (string, e } defer newFile.Close() + ctx, cancel := context.WithTimeout(ctx, mnd.DefaultTimeout) + defer cancel() + if c.HostID == "" { c.HostID, _ = host.HostIDWithContext(ctx) } From 41b888cfbdf8877c62fcdc81ffa120c2c3b18410 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Tue, 16 Jul 2024 23:15:13 -0700 Subject: [PATCH 09/12] update starr --- go.mod | 2 +- go.sum | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index f2659f520..8722fefa6 100644 --- a/go.mod +++ b/go.mod @@ -49,7 +49,7 @@ require ( golift.io/nzbget v0.1.5 golift.io/qbit v0.0.0-20240715191156-11930ac2546e golift.io/rotatorr v0.0.0-20230911015553-cd2abbd726c7 - golift.io/starr v1.0.1-0.20240315164714-247399771c46 + golift.io/starr v1.0.1-0.20240717055349-aa3e015cc8a4 golift.io/version v0.0.2 golift.io/xtractr v0.2.2 modernc.org/sqlite v1.30.2 diff --git a/go.sum b/go.sum index 485c29c8b..a14338f41 100644 --- a/go.sum +++ b/go.sum @@ -436,14 +436,12 @@ golift.io/mulery v0.0.8 h1:0D57orumzv9QORLLfTi4ao7uIACSyXkGSze32xLc04Q= golift.io/mulery v0.0.8/go.mod h1:4qn4yK/A4GdSKjl4pKBK0ORVHTF466Zfsy8YI0+9dps= golift.io/nzbget v0.1.5 h1:TE/TPldaLr/Qy5wy+7R4Lvur1SosOpjTLs6BLK3TMrU= golift.io/nzbget v0.1.5/go.mod h1:YYGQsadsgvadzM6qlVBS21gz8DBhfbxexGMndsGelj8= -golift.io/qbit v0.0.0-20240407164833-5de994cfd55e h1:MUKqgMVV3RuXrWXQoDUD2sqWX6kAL3qHa/7nZpL5mGc= -golift.io/qbit v0.0.0-20240407164833-5de994cfd55e/go.mod h1:8fUXWdcWtuqnfJg/Z9yWbrOxovyhH0V9jE0eK7pFffA= golift.io/qbit v0.0.0-20240715191156-11930ac2546e h1:JtgHLTF8YPH9fuyHxUYvteJMKyDtxCIbTA9KkbtwsgI= golift.io/qbit v0.0.0-20240715191156-11930ac2546e/go.mod h1:rW0J8ruEeqTiICfWSk54gja8WLqUjNkbcsFN3wVdO94= golift.io/rotatorr v0.0.0-20230911015553-cd2abbd726c7 h1:8reg8mRdLxCz168FaGPf/kVxmDRDc92/Dhub54trdOc= golift.io/rotatorr v0.0.0-20230911015553-cd2abbd726c7/go.mod h1:59bC4ue06MetIY4iiHu3PCqVbzW0leGoCONZhH8dPZ8= -golift.io/starr v1.0.1-0.20240315164714-247399771c46 h1:RpNfYz8V2EZGF52U+RpurYDKFMpQYXW6VxIOVlHBbr0= -golift.io/starr v1.0.1-0.20240315164714-247399771c46/go.mod h1:XdwHrSBkAbcEfqOOXJGg5QQQ2sE/PVo1PMY/WMhzd8s= +golift.io/starr v1.0.1-0.20240717055349-aa3e015cc8a4 h1:8ijJymuEKA2xvSuRh3/k6G1esCGQxL6RiuFQ4jjN5Kk= +golift.io/starr v1.0.1-0.20240717055349-aa3e015cc8a4/go.mod h1:hoY+g9EudDC7lbpJxdSjfdxfFMeEtU3ko9BKon0qUrs= golift.io/version v0.0.2 h1:i0gXRuSDHKs4O0sVDUg4+vNIuOxYoXhaxspftu2FRTE= golift.io/version v0.0.2/go.mod h1:76aHNz8/Pm7CbuxIsDi97jABL5Zui3f2uZxDm4vB6hU= golift.io/xtractr v0.2.2 h1:MvujxeuX629d1rQs2VJbbcvYMvMmN5SzIkEflU5ryOc= @@ -522,8 +520,6 @@ modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4= modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0= modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc= modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss= -modernc.org/sqlite v1.30.1 h1:YFhPVfu2iIgUf9kuA1CR7iiHdcEEsI2i+yjRYHscyxk= -modernc.org/sqlite v1.30.1/go.mod h1:DUmsiWQDaAvU4abhc/N+djlom/L2o8f7gZ95RCvyoLU= modernc.org/sqlite v1.30.2 h1:IPVVkhLu5mMVnS1dQgh3h0SAACRWcVk7aoLP9Us3UCk= modernc.org/sqlite v1.30.2/go.mod h1:DUmsiWQDaAvU4abhc/N+djlom/L2o8f7gZ95RCvyoLU= modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA= From 2177a08e9358490490caad48f52ddb7395e05bc1 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Tue, 16 Jul 2024 23:20:30 -0700 Subject: [PATCH 10/12] oops, breaking change in starr --- pkg/apps/radarr.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/apps/radarr.go b/pkg/apps/radarr.go index bb006e03c..2201dc88d 100644 --- a/pkg/apps/radarr.go +++ b/pkg/apps/radarr.go @@ -980,7 +980,7 @@ func radarrAddImportList(req *http.Request) (int, interface{}) { return apiError(http.StatusBadRequest, "decoding payload", err) } - output, err := getRadarr(req).CreateImportListContext(req.Context(), &ilist) + output, err := getRadarr(req).AddImportListContext(req.Context(), &ilist) if err != nil { return apiError(http.StatusInternalServerError, "creating import list", err) } From 1f128b83553ff59e498a18765d35c9dde4f2b342 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Tue, 16 Jul 2024 23:27:34 -0700 Subject: [PATCH 11/12] missed one --- pkg/client/client_other.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/client/client_other.go b/pkg/client/client_other.go index 31f976db7..0d1614f4f 100644 --- a/pkg/client/client_other.go +++ b/pkg/client/client_other.go @@ -23,9 +23,9 @@ func (f *fakeMenu) Uncheck() {} func (f *fakeMenu) Check() {} func (f *fakeMenu) SetTooltip(interface{}) {} -func (c *Client) printUpdateMessage() {} -func (c *Client) setupMenus(interface{}) {} -func (c *Client) startTray(_, _, _ interface{}) {} +func (c *Client) printUpdateMessage() {} +func (c *Client) setupMenus(interface{}) {} +func (c *Client) startTray(_, _ interface{}) {} func (c *Client) handleAptHook(_ context.Context) error { return fmt.Errorf("this feature is not supported on this platform") //nolint:goerr113 } From 856f2bc8388abf124d7571481af878fa9fdeac3a Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Thu, 18 Jul 2024 11:55:08 -0700 Subject: [PATCH 12/12] remove override --- go.mod | 2 -- go.sum | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 8722fefa6..ff5e56e7d 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,6 @@ go 1.22 // pflag and tail are pinned to master. 12/31/2022 -replace github.com/shirou/gopsutil/v4 => github.com/Girbons/gopsutil/v4 v4.0.0-20240708140948-ba82fefdee75 - require ( github.com/BurntSushi/toml v1.4.0 github.com/akavel/rsrc v0.10.2 diff --git a/go.sum b/go.sum index a14338f41..e0f8f010f 100644 --- a/go.sum +++ b/go.sum @@ -21,8 +21,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/Girbons/gopsutil/v4 v4.0.0-20240708140948-ba82fefdee75 h1:lz2b9BI2CaVAsIAfc3jD7ip0hyIwrngEKs2vR4YWlp0= -github.com/Girbons/gopsutil/v4 v4.0.0-20240708140948-ba82fefdee75/go.mod h1:aoebb2vxetJ/yIDZISmduFvVNPHqXQ9SEJwRXxkf0RA= github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA= @@ -230,6 +228,8 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd/go.mod h1:hPqNNc0+uJM6H+SuU8sEs5K5IQeKccPqeSjfgcKGgPk= +github.com/shirou/gopsutil/v4 v4.24.6 h1:9qqCSYF2pgOU+t+NgJtp7Co5+5mHF/HyKBUckySQL64= +github.com/shirou/gopsutil/v4 v4.24.6/go.mod h1:aoebb2vxetJ/yIDZISmduFvVNPHqXQ9SEJwRXxkf0RA= github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=