Пример #1
0
// RunApp runs the main loop for the application.
func RunApp(dockapp *dockapp.DockApp, app *App, metrics <-chan *battery.Metrics, formatter <-chan battery.MetricFormatter) {
	defer dockapp.Quit()
	var m *battery.Metrics
	var f battery.MetricFormatter
	for {
		select {
		case m = <-metrics:
		case f = <-formatter:
		}
		if m == nil {
			log.Printf("nil metrics")
			continue
		}
		if f == nil {
			log.Printf("nil formatter")
			continue
		}
		// draw the widget to the screen.
		err := app.Draw(dockapp.Canvas(), m, f)
		if err != nil {
			log.Panic(err)
		}
		dockapp.FlushImage()
	}
}
Пример #2
0
// RunApp is the main loop for the application.
func RunApp(dockapp *dockapp.DockApp, app *App, delta <-chan []CPU) {
	defer close(app.done)

	img := dockapp.Canvas()
	app.Draw(img, nil)
	dockapp.FlushImage()

	var cpus []CPU
	var ok bool
	var cpuNamesOld []string
	for {
		select {
		case cpus, ok = <-delta:
			if !ok {
				return
			}
		}

		var cpuNames []string
		for _, t := range cpus {
			cpuNames = append(cpuNames, t.Name())
		}
		if len(cpuNames) != len(cpuNamesOld) {
			cpuNamesOld = cpuNames
			log.Printf("cpus: %q", cpuNames)
		} else {
			for i, name := range cpuNamesOld {
				if name != cpuNames[i] {
					cpuNamesOld = cpuNames
					log.Printf("cpus: %q", cpuNames)
				}
			}
		}

		// draw the widget to the screen.
		app.Draw(dockapp.Canvas(), cpus)
		dockapp.FlushImage()
	}
}