Beispiel #1
0
// Opens all links with browser.
func readAll(bw *bufioutil.Writer, conn net.Conn) (err error) {
	// Read in config file to settings.Global
	err = ini.ReadSettings(settings.ConfigPath)
	if err != nil {
		return errutil.Err(err)
	}

	ups, err := getUpdates(bw, conn)
	if err != nil {
		return errutil.Err(err)
	}

	if settings.Global.Browser == "" {
		fmt.Println("No browser path set in:", settings.ConfigPath)
		return nil
	}

	// If no updates was found, ask for forgiveness.
	if len(ups) == 0 {
		fmt.Println("Sorry, no updates :(")
		return nil
	}

	var arguments []string
	// Loop through all updates and open them with the browser
	for up := range ups {
		arguments = append(arguments, up)
	}
	cmd := exec.Command(settings.Global.Browser, arguments...)
	err = cmd.Start()
	if err != nil {
		return errutil.Err(err)
	}
	return nil
}
Beispiel #2
0
func watchConfig(watcher *fsnotify.Watcher) (err error) {
	for {
		select {
		case ev := <-watcher.Event:
			if ev != nil {
				if ev.Name == settings.ConfigPath {
					// Read settings from config file.
					err = ini.ReadSettings(settings.ConfigPath)
					if err != nil {
						return errutil.Err(err)
					}
				}
				// Retrieve an array of pages from INI file.
				pages, err := ini.ReadPages(settings.PagesPath)
				if err != nil {
					return errutil.Err(err)
				}
				err = page.ForceUpdate(pages)
				if err != nil {
					return errutil.Err(err)
				}
			}
		case err = <-watcher.Error:
			if err != nil {
				return errutil.Err(err)
			}
		}
	}
}