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

Improve the config file handling process

* Don't create a default config if a custom config is being passed in
* Textfile: don't die if the file cannot be found
This commit is contained in:
Chris Cummer
2019-08-02 01:49:05 -07:00
parent 45da40e4c9
commit 4c2b52cdbb
3 changed files with 28 additions and 13 deletions

View File

@@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"time"
@@ -18,6 +17,10 @@ import (
"github.com/wtfutil/wtf/wtf"
)
const (
pollingIntervalms = 100
)
type Widget struct {
wtf.KeyboardWidget
wtf.MultiSourceWidget
@@ -137,7 +140,8 @@ func (widget *Widget) watchForFileChanges() {
case <-watch.Event:
widget.display()
case err := <-watch.Error:
log.Fatalln(err)
fmt.Println(err)
os.Exit(1)
case <-watch.Closed:
return
}
@@ -149,13 +153,14 @@ func (widget *Widget) watchForFileChanges() {
fullPath, err := utils.ExpandHomeDir(source)
if err == nil {
if err := watch.Add(fullPath); err != nil {
log.Fatalln(err)
// Ignore it, don't care about a file that doesn't exist
}
}
}
// Start the watching process - it'll check for changes every 100ms.
if err := watch.Start(time.Millisecond * 100); err != nil {
log.Fatalln(err)
// Start the watching process - it'll check for changes every pollingIntervalms.
if err := watch.Start(time.Millisecond * pollingIntervalms); err != nil {
fmt.Println(err)
os.Exit(1)
}
}