Skip to content

Commit

Permalink
fix: show dialog on error
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Falk Nielsen committed May 2, 2024
1 parent de05423 commit 53ebf65
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 28 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ go 1.21.1
require (
fyne.io/systray v1.10.0
github.com/netbox-community/go-netbox/v3 v3.4.5
github.com/sqweek/dialog v0.0.0-20240226140203-065105509627
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/go-openapi/analysis v0.21.2 // indirect
github.com/go-openapi/errors v0.20.2 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tN
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf h1:FPsprx82rdrX2jiKyS17BH6IrTmUBYqZa/CXT4uvb+I=
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf/go.mod h1:peYoMncQljjNS6tZwI9WVyQB3qZS6u79/N3mBOcnd3I=
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ=
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
Expand Down Expand Up @@ -122,6 +124,8 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/sqweek/dialog v0.0.0-20240226140203-065105509627 h1:2JL2wmHXWIAxDofCK+AdkFi1KEg3dgkefCsm7isADzQ=
github.com/sqweek/dialog v0.0.0-20240226140203-065105509627/go.mod h1:/qNPSY91qTz/8TgHEMioAUc6q7+3SOybeKczHMXFcXw=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
Expand Down
20 changes: 3 additions & 17 deletions internal/tray/systray.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
package tray

import (
"fmt"
"time"

"fyne.io/systray"
"github.com/jysk-network/netbox-securecrt-inventory/internal/config"
"github.com/jysk-network/netbox-securecrt-inventory/internal/tray/assets"
)

type SysTrayStatus struct {
Message string
Status bool
MenusDisabled bool
}

type SysTray struct {
mStatus *systray.MenuItem
mSyncNow *systray.MenuItem
Expand All @@ -23,7 +16,6 @@ type SysTray struct {
cfg *config.Config
animationTicker *time.Ticker
ClickedCh chan string
startupStatus SysTrayStatus
}

func New(cfg *config.Config) *SysTray {
Expand Down Expand Up @@ -53,13 +45,8 @@ func (s *SysTray) onStartup() {

s.mQuit = systray.AddMenuItem("Quit", "Quit the whole app")

if s.startupStatus.MenusDisabled {
s.mSyncNow.Disable()
mSettings.Disable()
}

s.SetStatus(s.startupStatus.Status)
s.SetStatusMessage(fmt.Sprintf("Status: %s", s.startupStatus.Message))
s.SetStatus(true)
s.SetStatusMessage("Status: Not synced yet")
s.togglePeriodicSync()
s.handleClicks()
}
Expand Down Expand Up @@ -90,8 +77,7 @@ func (s *SysTray) togglePeriodicSync() {
}
}

func (s *SysTray) Run(status SysTrayStatus) {
s.startupStatus = status
func (s *SysTray) Run() {
systray.Run(s.onStartup, s.onExit)
}

Expand Down
17 changes: 6 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/jysk-network/netbox-securecrt-inventory/internal/netbox"
"github.com/jysk-network/netbox-securecrt-inventory/internal/tray"
"github.com/jysk-network/netbox-securecrt-inventory/pkg/securecrt"
"github.com/sqweek/dialog"
)

func main() {
Expand All @@ -16,21 +17,15 @@ func main() {

cfg, err := config.NewConfig(cfgPath)
if err != nil {
panic(err)
}

// setup our startup status so we can report errors in the systray
sysTrayStatupStatus := tray.SysTrayStatus{
Status: true,
Message: "Not synced yet",
dialog.Message("Error: %v", err).Title("Config Error").Error()
return
}

// setup securecrt config builder, and validate it's installed
scrt, err := securecrt.New(cfg.DefaultCredential)
if err != nil {
sysTrayStatupStatus.Message = err.Error()
sysTrayStatupStatus.Status = false
sysTrayStatupStatus.MenusDisabled = true
dialog.Message("Error: %v", err).Title("Credentials Error").Error()
return
}

// setup the systray, and all menu items
Expand Down Expand Up @@ -63,5 +58,5 @@ func main() {
}()

// show the systray in a blocking way
systray.Run(sysTrayStatupStatus)
systray.Run()
}

0 comments on commit 53ebf65

Please sign in to comment.