diff --git a/cfg/config_files.go b/cfg/config_files.go index 2fa6ca34..f2ad94ea 100644 --- a/cfg/config_files.go +++ b/cfg/config_files.go @@ -57,12 +57,20 @@ func CreateFile(fileName string) (string, error) { // Initialize takes care of settings up the initial state of WTF configuration // It ensures necessary directories and files exist -func Initialize() { - migrateOldConfig() +func Initialize(hasCustom bool) { + if hasCustom == false { + migrateOldConfig() + } + + // These always get created because this is where modules should write any permanent + // data they need to persist between runs (i.e.: log, textfile, etc.) createXdgConfigDir() createWtfConfigDir() - createWtfConfigFile() - chmodConfigFile() + + if hasCustom == false { + createWtfConfigFile() + chmodConfigFile() + } } // WtfConfigDir returns the absolute path to the configuration directory diff --git a/main.go b/main.go index 381820e2..84726545 100644 --- a/main.go +++ b/main.go @@ -46,14 +46,16 @@ func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) // Manage the configuration directories and config file - cfg.Initialize() // Parse and handle flags flags := flags.NewFlags() flags.Parse() + hasCustom := flags.HasCustomConfig() + cfg.Initialize(hasCustom) + // Load the configuration file - config := cfg.LoadWtfConfigFile(flags.ConfigFilePath(), flags.HasCustomConfig()) + config := cfg.LoadWtfConfigFile(flags.ConfigFilePath(), hasCustom) flags.RenderIf(version, config) if flags.Profile { @@ -66,7 +68,7 @@ func main() { // Build the application tviewApp = tview.NewApplication() - wtfApp := app.NewWtfApp(tviewApp, config, flags.Config, flags.HasCustomConfig()) + wtfApp := app.NewWtfApp(tviewApp, config, flags.Config, hasCustom) wtfApp.Start() if err := tviewApp.Run(); err != nil { diff --git a/modules/textfile/widget.go b/modules/textfile/widget.go index 558a10a5..39e33c0d 100644 --- a/modules/textfile/widget.go +++ b/modules/textfile/widget.go @@ -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) } }