forked from Elara6331/itd
		
	Add context support and update lrpc
This commit is contained in:
		| @@ -1,6 +1,7 @@ | ||||
| package main | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"image/color" | ||||
|  | ||||
| @@ -27,11 +28,13 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container { | ||||
| 	) | ||||
| 	infoLayout.Add(heartRateSect) | ||||
|  | ||||
| 	heartRateCh, cancel, err := client.WatchHeartRate() | ||||
| 	ctx, cancel := context.WithCancel(context.Background()) | ||||
| 	onClose = append(onClose, cancel) | ||||
|  | ||||
| 	heartRateCh, err := client.WatchHeartRate(ctx) | ||||
| 	if err != nil { | ||||
| 		guiErr(err, "Error getting heart rate channel", true, parent) | ||||
| 	} | ||||
| 	onClose = append(onClose, cancel) | ||||
| 	go func() { | ||||
| 		for heartRate := range heartRateCh { | ||||
| 			// Change text of heart rate label | ||||
| @@ -51,11 +54,10 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container { | ||||
| 	) | ||||
| 	infoLayout.Add(stepCountSect) | ||||
|  | ||||
| 	stepCountCh, cancel, err := client.WatchStepCount() | ||||
| 	stepCountCh, err := client.WatchStepCount(ctx) | ||||
| 	if err != nil { | ||||
| 		guiErr(err, "Error getting step count channel", true, parent) | ||||
| 	} | ||||
| 	onClose = append(onClose, cancel) | ||||
| 	go func() { | ||||
| 		for stepCount := range stepCountCh { | ||||
| 			// Change text of heart rate label | ||||
| @@ -75,11 +77,10 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container { | ||||
| 	) | ||||
| 	infoLayout.Add(battLevel) | ||||
|  | ||||
| 	battLevelCh, cancel, err := client.WatchBatteryLevel() | ||||
| 	battLevelCh, err := client.WatchBatteryLevel(ctx) | ||||
| 	if err != nil { | ||||
| 		guiErr(err, "Error getting battery level channel", true, parent) | ||||
| 	} | ||||
| 	onClose = append(onClose, cancel) | ||||
| 	go func() { | ||||
| 		for battLevel := range battLevelCh { | ||||
| 			// Change text of battery level label | ||||
| @@ -89,7 +90,7 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container { | ||||
| 		} | ||||
| 	}() | ||||
|  | ||||
| 	fwVerString, err := client.Version() | ||||
| 	fwVerString, err := client.Version(context.Background()) | ||||
| 	if err != nil { | ||||
| 		guiErr(err, "Error getting firmware string", true, parent) | ||||
| 	} | ||||
| @@ -101,7 +102,7 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container { | ||||
| 	) | ||||
| 	infoLayout.Add(fwVer) | ||||
|  | ||||
| 	btAddrString, err := client.Address() | ||||
| 	btAddrString, err := client.Address(context.Background()) | ||||
| 	if err != nil { | ||||
| 		panic(err) | ||||
| 	} | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package main | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"image/color" | ||||
| 	"strconv" | ||||
|  | ||||
| @@ -44,6 +45,10 @@ func motionTab(parent fyne.Window, client *api.Client) *fyne.Container { | ||||
|  | ||||
| 	// Create button to stop motion | ||||
| 	stopBtn := widget.NewButton("Stop", nil) | ||||
|  | ||||
| 	ctx, cancel := context.WithCancel(context.Background()) | ||||
| 	onClose = append(onClose, cancel) | ||||
|  | ||||
| 	// Create button to start motion | ||||
| 	startBtn := widget.NewButton("Start", func() { | ||||
| 		// if motion is started | ||||
| @@ -54,7 +59,7 @@ func motionTab(parent fyne.Window, client *api.Client) *fyne.Container { | ||||
| 		// Set motion started | ||||
| 		started = true | ||||
| 		// Watch motion values | ||||
| 		motionCh, cancel, err := client.WatchMotion() | ||||
| 		motionCh, err := client.WatchMotion(ctx) | ||||
| 		if err != nil { | ||||
| 			guiErr(err, "Error getting heart rate channel", true, parent) | ||||
| 		} | ||||
|   | ||||
| @@ -1,6 +1,8 @@ | ||||
| package main | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
|  | ||||
| 	"fyne.io/fyne/v2" | ||||
| 	"fyne.io/fyne/v2/container" | ||||
| 	"fyne.io/fyne/v2/layout" | ||||
| @@ -19,7 +21,7 @@ func notifyTab(parent fyne.Window, client *api.Client) *fyne.Container { | ||||
|  | ||||
| 	// Create new button to send notification | ||||
| 	sendBtn := widget.NewButton("Send", func() { | ||||
| 		err := client.Notify(titleEntry.Text, bodyEntry.Text) | ||||
| 		err := client.Notify(context.Background(), titleEntry.Text, bodyEntry.Text) | ||||
| 		if err != nil { | ||||
| 			guiErr(err, "Error sending notification", false, parent) | ||||
| 			return | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package main | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"time" | ||||
|  | ||||
| 	"fyne.io/fyne/v2" | ||||
| @@ -49,9 +50,9 @@ func timeTab(parent fyne.Window, client *api.Client) *fyne.Container { | ||||
| func setTime(client *api.Client, current bool, t ...time.Time) error { | ||||
| 	var err error | ||||
| 	if current { | ||||
| 		err = client.SetTime(time.Now()) | ||||
| 		err = client.SetTime(context.Background(), time.Now()) | ||||
| 	} else { | ||||
| 		err = client.SetTime(t[0]) | ||||
| 		err = client.SetTime(context.Background(), t[0]) | ||||
| 	} | ||||
| 	if err != nil { | ||||
| 		return err | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package main | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"path/filepath" | ||||
|  | ||||
| @@ -125,7 +126,7 @@ func upgradeTab(parent fyne.Window, client *api.Client) *fyne.Container { | ||||
| 			files = append(files, initPktPath, firmwarePath) | ||||
| 		} | ||||
|  | ||||
| 		progress, err := client.FirmwareUpgrade(fwUpgType, files...) | ||||
| 		progress, err := client.FirmwareUpgrade(context.Background(), fwUpgType, files...) | ||||
| 		if err != nil { | ||||
| 			guiErr(err, "Error initiating DFU", false, parent) | ||||
| 			return | ||||
|   | ||||
		Reference in New Issue
	
	Block a user