Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for automatic reloading the config when it has been changed #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dolfje
Copy link

@dolfje dolfje commented Oct 5, 2021

No description provided.

@muesli
Copy link
Owner

muesli commented Oct 5, 2021

Thanks for this! General recommendation when getting started with Go: make sure your IDE/editor uses gofmt (comes with Go!) to automatically format the code for you. This fixes several indentation issues for you and makes coding in Go a lot more fun, promised. Check out vim-go for vim or the Go extension for VSCode! Using another editor? Let me know and I'll point you in the right direction.

Alternatively you can also run this manually on the command line:

gofmt -w *.go

deck.go Outdated
select {
case event := <-watcher.Events:
if currentDeck == path {
fmt.Println("Change: %s: %s", event.Op, event.Name)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful, Println doesn't expect formatting directives like %s. You'll have to use Printf here and finish it with a \n for a newline.

@@ -70,6 +72,32 @@ func LoadDeck(dev *streamdeck.Device, base string, deck string) (*Deck, error) {
d.Widgets = append(d.Widgets, w)
}

watcher, err := fsnotify.NewWatcher()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to check the error assignments for this line and the one below. Two options here:

  1. Consider this feature optional, and if an error occurs while setting up the file-watcher, we continue without config monitoring
  2. Propagate the error, so we can display an error to the user:
if err != nil {
    return nil, err
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants