From cd46ad42d2d688b74848bcc4aa68835a91fc495b Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Sat, 17 Jul 2021 10:32:43 -0400 Subject: [PATCH] Working using qtdeploy --- .gitignore | 2 + go.mod | 2 + go.sum | 9 ++ main.go | 394 ++++------------------------------------------------- 4 files changed, 36 insertions(+), 371 deletions(-) diff --git a/.gitignore b/.gitignore index 86fed2b..690b20a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ vendor TeslaGo *.log .vscode +deploy +linux \ No newline at end of file diff --git a/go.mod b/go.mod index 2ac9cf6..db61e20 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,8 @@ require ( github.com/bogosj/tesla v1.0.1 github.com/golang/protobuf v1.5.2 // indirect github.com/therecipe/qt v0.0.0-20200904063919-c0c124a5770d + github.com/therecipe/qt/internal/binding/files/docs/5.12.0 v0.0.0-20200904063919-c0c124a5770d // indirect + github.com/therecipe/qt/internal/binding/files/docs/5.13.0 v0.0.0-20200904063919-c0c124a5770d // indirect golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.27.1 // indirect diff --git a/go.sum b/go.sum index 08614f1..9468332 100644 --- a/go.sum +++ b/go.sum @@ -128,6 +128,7 @@ github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= @@ -142,6 +143,11 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/therecipe/qt v0.0.0-20200904063919-c0c124a5770d h1:T+d8FnaLSvM/1BdlDXhW4d5dr2F07bAbB+LpgzMxx+o= github.com/therecipe/qt v0.0.0-20200904063919-c0c124a5770d/go.mod h1:SUUR2j3aE1z6/g76SdD6NwACEpvCxb3fvG82eKbD6us= +github.com/therecipe/qt/internal/binding/files/docs v0.0.0-20191019224306-1097424d656c h1:/VhcwU7WuFEVgDHZ9V8PIYAyYqQ6KNxFUjBMOf2aFZM= +github.com/therecipe/qt/internal/binding/files/docs/5.12.0 v0.0.0-20200904063919-c0c124a5770d h1:hAZyEG2swPRWjF0kqqdGERXUazYnRJdAk4a58f14z7Y= +github.com/therecipe/qt/internal/binding/files/docs/5.12.0 v0.0.0-20200904063919-c0c124a5770d/go.mod h1:7m8PDYDEtEVqfjoUQc2UrFqhG0CDmoVJjRlQxexndFc= +github.com/therecipe/qt/internal/binding/files/docs/5.13.0 v0.0.0-20200904063919-c0c124a5770d h1:AJRoBel/g9cDS+yE8BcN3E+TDD/xNAguG21aoR8DAIE= +github.com/therecipe/qt/internal/binding/files/docs/5.13.0 v0.0.0-20200904063919-c0c124a5770d/go.mod h1:mH55Ek7AZcdns5KPp99O0bg+78el64YCYWHiQKrOdt4= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -185,6 +191,7 @@ golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -262,6 +269,7 @@ golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -314,6 +322,7 @@ golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d h1:W07d4xkoAUSNOkOzdzXCdFGxT7o2rW4q8M34tB2i//k= golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/main.go b/main.go index 5f20b7c..3bb4bbe 100644 --- a/main.go +++ b/main.go @@ -2,52 +2,26 @@ package main import ( "flag" - "fmt" "os" - "strconv" - "strings" - "time" "github.com/bogosj/tesla" "github.com/therecipe/qt/widgets" + + "git.nightmare.haus/rudi/TeslaGo/ui" ) var ( - // Info/Statuses - batteryLevel *widgets.QLabel - batteryRange *widgets.QLabel - chargingState *widgets.QLabel - minutesToFull *widgets.QLabel - fastChargerInd *widgets.QLabel - batteryHeaterInd *widgets.QLabel - chargeDoorOpenInd *widgets.QLabel - insideTemp *widgets.QLabel - outsideTemp *widgets.QLabel - climateUnitLabel *widgets.QLabel - - // Controls - tempSetting *widgets.QLineEdit - climateOn *widgets.QCheckBox - lockedDoors *widgets.QCheckBox - sentryMode *widgets.QCheckBox - startStopCharge *widgets.QCheckBox - - honk *widgets.QPushButton - flashLights *widgets.QPushButton - trunk *widgets.QPushButton - frunk *widgets.QPushButton - vehicle *tesla.Vehicle vehicleState *tesla.VehicleState chargeStats *tesla.ChargeState climateState *tesla.ClimateState guiSettings *tesla.GuiSettings - window *widgets.QMainWindow + window *ui.MainWindow mainApp *widgets.QApplication vehicleSearch string refresh int - popup = false + popup bool ) func init() { @@ -55,9 +29,9 @@ func init() { flag.IntVar(&refresh, "r", -1, "Auto-refresh (every \"r\" minutes) WARNING: Vehicle can not sleep while refreshing.") flag.Parse() } + func main() { mainApp = widgets.NewQApplication(len(os.Args), os.Args) - window = widgets.NewQMainWindow(nil, 0) c := getTeslaClient() vehicles, err := c.Vehicles() @@ -72,353 +46,31 @@ func main() { showDialogue(false, "Unable to determine vehicle.") } - // Setup all UI Elements - window.SetWindowTitle("Loading, please wait!") - - batteryLevel = widgets.NewQLabel(nil, 0) - batteryRange = widgets.NewQLabel(nil, 0) - chargingState = widgets.NewQLabel(nil, 0) - minutesToFull = widgets.NewQLabel(nil, 0) - fastChargerInd = widgets.NewQLabel(nil, 0) - batteryHeaterInd = widgets.NewQLabel(nil, 0) - chargeDoorOpenInd = widgets.NewQLabel(nil, 0) - insideTemp = widgets.NewQLabel(nil, 0) - outsideTemp = widgets.NewQLabel(nil, 0) - currentChargeLabel := widgets.NewQLabel(nil, 0) - currentRangeLabel := widgets.NewQLabel(nil, 0) - insideTempLabel := widgets.NewQLabel(nil, 0) - outsideTempLabel := widgets.NewQLabel(nil, 0) - climateEnabledLabel := widgets.NewQLabel(nil, 0) - climateSettingLabel := widgets.NewQLabel(nil, 0) - doorLockLabel := widgets.NewQLabel(nil, 0) - sentryModeLabel := widgets.NewQLabel(nil, 0) - chargingStateLabel := widgets.NewQLabel(nil, 0) - climateUnitLabel = widgets.NewQLabel(nil, 0) - - tempSetting = widgets.NewQLineEdit(nil) - - climateOn = widgets.NewQCheckBox(nil) - lockedDoors = widgets.NewQCheckBox(nil) - sentryMode = widgets.NewQCheckBox(nil) - startStopCharge = widgets.NewQCheckBox(nil) - - honk = widgets.NewQPushButton(nil) - flashLights = widgets.NewQPushButton(nil) - trunk = widgets.NewQPushButton(nil) - frunk = widgets.NewQPushButton(nil) - - statusLayout := widgets.NewQFormLayout(nil) - chargeHbox := widgets.NewQHBoxLayout() - tempHbox := widgets.NewQHBoxLayout() - climateHbox := widgets.NewQHBoxLayout() - securityHbox := widgets.NewQHBoxLayout() - actionHbox := widgets.NewQHBoxLayout() - - centralWidget := widgets.NewQWidget(window, 0) - - // Set Values for everything - setValues() - if refresh >= 1 { - go func() { - for { - time.Sleep(time.Duration(refresh) * time.Minute) - setValues() - } - }() - } - - // Some adjustments - - lockedDoors.SetCheckable(false) - climateOn.SetCheckable(false) - tempSetting.SetReadOnly(true) - - batteryLevel.SetFixedWidth(30) - insideTemp.SetFixedWidth(25) - outsideTemp.SetFixedWidth(25) - tempSetting.SetFixedWidth(25) - - currentChargeLabel.SetText("Current Charge:") - currentRangeLabel.SetText("Current Range:") - insideTempLabel.SetText("Inside Temp:") - outsideTempLabel.SetText("Outside Temp:") - climateEnabledLabel.SetText("Climate On:") - climateSettingLabel.SetText("Climate Setting:") - doorLockLabel.SetText("Lock Doors:") - sentryModeLabel.SetText("Sentry Mode:") - chargingStateLabel.SetText("Charging:") - honk.SetText("Honk") - flashLights.SetText("Flash") - trunk.SetText("Trunk") - frunk.SetText("Frunk") - - // Connect Controls - honk.ConnectClicked(honkHorn) - flashLights.ConnectClicked(flash) - trunk.ConnectClicked(openTrunk) - frunk.ConnectClicked(openFrunk) - lockedDoors.ConnectStateChanged(lockDoors) - sentryMode.ConnectStateChanged(sentryModeEnable) - startStopCharge.ConnectStateChanged(enableCharging) - climateOn.ConnectStateChanged(enableClimate) - - // Setup Layout for first row, Current Charge - chargeHbox.AddWidget(batteryLevel, 0, 0) - chargeHbox.AddItem(widgets.NewQSpacerItem(5, 2, widgets.QSizePolicy__Expanding, widgets.QSizePolicy__Expanding)) - chargeHbox.AddWidget(currentRangeLabel, 0, 0) - chargeHbox.AddWidget(batteryRange, 0, 0) - - // Charging State has its own section and is handled differently based on if it is present or not - if chargeStats.ChargingState != "Disconnected" { - statusLayout.AddRow3("Time to Full:", minutesToFull) - if chargeStats.FastChargerPresent { - statusLayout.AddRow3("Fast Charger:", fastChargerInd) - } - if chargeStats.BatteryHeaterOn { - statusLayout.AddRow3("Battey Heater:", batteryHeaterInd) - } - statusLayout.AddRow3(" ", nil) - } - - // Temperature section (NOT CLIMATE CONTROL) - tempHbox.AddWidget(insideTemp, 0, 0) - tempHbox.AddItem(widgets.NewQSpacerItem(10, 10, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed)) - tempHbox.AddWidget(outsideTempLabel, 0, 0) - tempHbox.AddWidget(outsideTemp, 0, 0) - - // Climate Control Section - climateHbox.AddWidget(climateOn, 0, 0) - climateHbox.AddItem(widgets.NewQSpacerItem(10, 10, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed)) - climateHbox.AddWidget(climateSettingLabel, 0, 0) - climateHbox.AddWidget(tempSetting, 0, 0) - climateHbox.AddWidget(climateUnitLabel, 0, 0) - - // Security Section (Lock/Unlock doors & start/stop charge. Also enable Sentry Mode) - securityHbox.AddWidget(lockedDoors, 0, 0) - securityHbox.AddItem(widgets.NewQSpacerItem(10, 10, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed)) - securityHbox.AddWidget(sentryModeLabel, 0, 0) - securityHbox.AddWidget(sentryMode, 0, 0) - if chargeStats.ChargingState != "Disconnected" { - securityHbox.AddItem(widgets.NewQSpacerItem(10, 10, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed)) - securityHbox.AddWidget(chargingStateLabel, 0, 0) - securityHbox.AddWidget(startStopCharge, 0, 0) - } - - // Action Buttons - actionHbox.AddWidget(honk, 0, 0) - actionHbox.AddItem(widgets.NewQSpacerItem(2, 2, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed)) - actionHbox.AddWidget(flashLights, 0, 0) - actionHbox.AddItem(widgets.NewQSpacerItem(2, 2, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed)) - actionHbox.AddWidget(trunk, 0, 0) - actionHbox.AddItem(widgets.NewQSpacerItem(2, 2, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed)) - actionHbox.AddWidget(frunk, 0, 0) - actionHbox.AddItem(widgets.NewQSpacerItem(2, 2, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed)) - - // Put all Sections Together, note ChargingState (top) is already handled - statusLayout.AddRow2(currentChargeLabel, chargeHbox) - statusLayout.AddRow3("Charging State:", chargingState) - statusLayout.AddRow3("Charge Port:", chargeDoorOpenInd) - statusLayout.AddRow3(" ", nil) - statusLayout.AddRow2(insideTempLabel, tempHbox) - statusLayout.AddRow2(climateEnabledLabel, climateHbox) - statusLayout.AddRow3(" ", nil) - statusLayout.AddRow2(doorLockLabel, securityHbox) - statusLayout.AddRow6(actionHbox) - - // Finish setting up the window, and let her go - centralWidget.SetLayout(statusLayout) - window.SetCentralWidget(centralWidget) if !popup { - window.Show() + NewMainWindow().Show() } widgets.QApplication_Exec() } -func setValues() { - vehicle = getVehicle(vehicleSearch) - if vehicle == nil { - showDialogue(false, "Unable to get vehicle") - return - } - test, err := vehicle.Data(vehicle.ID) - if err != nil { - showDialogue(false, "Unable to get Vehicle State") - } - vehicleState = test.Response.VehicleState - chargeStats = test.Response.ChargeState - climateState = test.Response.ClimateState - guiSettings = test.Response.GuiSettings - - window.SetWindowTitle(fmt.Sprintf("%+v: %+v", vehicle.DisplayName, vehicle.Vin)) - tempSettingVal := climateState.DriverTempSetting - insideTempVal := climateState.InsideTemp - outsideTempVal := climateState.OutsideTemp - if guiSettings.GuiTemperatureUnits == "F" { - tempSettingVal = (climateState.DriverTempSetting * 1.8) + 32 - insideTempVal = (climateState.InsideTemp * 1.8) + 32 - outsideTempVal = (climateState.OutsideTemp * 1.8) + 32 - } - batteryLevel.SetText(fmt.Sprintf("%+v%%", chargeStats.BatteryLevel)) - batteryRange.SetText(fmt.Sprintf("%.2f%+v", chargeStats.BatteryRange, - strings.Replace(guiSettings.GuiDistanceUnits, "/hr", "", -1))) - batteryRange.SetFixedWidth(10 * len(batteryRange.Text())) - chargingState.SetText(chargeStats.ChargingState) - chargeTimer := time.Duration(chargeStats.MinutesToFullCharge) * time.Minute - minutesToFull.SetText(fmt.Sprintf("%+v (%+v)", formatDuration(chargeTimer), time.Now().Add(chargeTimer).Format("15:04"))) - - fastChargerInd.SetText(chargeStats.FastChargerBrand) - if chargeStats.BatteryHeaterOn { - batteryHeaterInd.SetText("On") - } - - if chargeStats.ChargePortDoorOpen { - chargeDoorOpenInd.SetText("Open") - } else { - chargeDoorOpenInd.SetText("Closed") - } - - insideTemp.SetText(fmt.Sprintf("%.0f %+v", insideTempVal, guiSettings.GuiTemperatureUnits)) - outsideTemp.SetText(fmt.Sprintf("%.0f %+v", outsideTempVal, guiSettings.GuiTemperatureUnits)) - climateOn.SetChecked(climateState.IsClimateOn) - tempSetting.SetText(fmt.Sprintf("%.0f", tempSettingVal)) - climateUnitLabel.SetText(guiSettings.GuiTemperatureUnits) - - lockedDoors.SetChecked(vehicleState.Locked) - sentryMode.SetChecked(vehicleState.SentryMode) - sentryMode.SetCheckable(!vehicleState.SentryMode) - lockedDoors.SetCheckable(true) - climateOn.SetCheckable(true) - tempSetting.SetReadOnly(false) - - startStopCharge.SetChecked(chargeStats.ChargingState == "Charging") - - startStopCharge.SetCheckable(chargeStats.ChargingState != "Disconnected") - -} - -func enableClimate(i int) { - temp, err := strconv.ParseFloat(tempSetting.Text(), 64) - if err != nil { - showDialogue(true, "Unable to parse temp setting\n%+v", err) - } - if guiSettings.GuiTemperatureUnits == "F" { - temp = (temp - 32) * 5 / 9 - } - if i == 0 { - vehicle.StopAirConditioning() - } else { - vehicle.SetTemperature(temp, temp) - vehicle.StartAirConditioning() - } - - go setValues() -} - -func lockDoors(i int) { - if i == 0 { - vehicle.UnlockDoors() - } else { - vehicle.LockDoors() - } - go setValues() -} - -func sentryModeEnable(i int) { - vehicle.EnableSentry() - go setValues() -} - -func enableCharging(i int) { - if i == 0 { - vehicle.StopCharging() - } else { - vehicle.StartCharging() - } +func NewMainWindow() *ui.MainWindow { + window = ui.NewMainWindow(nil) + + window.SetWindowTitle("Tesla Go!") + window.HonkPushButton.ConnectClicked(honkHorn) + window.TimeToChargeLabel.SetText("") + window.TimeToChargeVal.SetText("") + window.FlashPushButton.ConnectClicked(flash) + window.FrunkPushButton.ConnectClicked(openFrunk) + window.TrunkPushButton.ConnectClicked(openTrunk) + window.LockPushButton.ConnectClicked(lockDoors) + window.ChargePushButton.ConnectClicked(enableCharging) + window.VehiclePreviewView.SetFixedWidth(50) + window.ClimateOnCheckbox.ConnectStateChanged(enableClimate) + window.ActionRefresh.ConnectTriggered(setVal2) go setValues() + return window } -func honkHorn(c bool) { - err := vehicle.HonkHorn() - if err != nil { - showDialogue(true, "There was an error honking the horn\n%+v", err) - fmt.Printf("%+v\n", err) - } - go setValues() -} -func flash(c bool) { - err := vehicle.FlashLights() - if err != nil { - showDialogue(true, "There was an error flashing the lights\n%+v", err) - fmt.Printf("%+v\n", err) - } - go setValues() -} -func openTrunk(c bool) { - err := vehicle.OpenTrunk("rear") - if err != nil { - showDialogue(true, "There was an error opening your trunk\n%+v", err) - fmt.Printf("%+v\n", err) - } +func setVal2(check bool) { go setValues() } -func openFrunk(c bool) { - err := vehicle.OpenTrunk("front") - if err != nil { - showDialogue(true, "There was an error opening your frunk\n%+v", err) - fmt.Printf("%+v\n", err) - } - go setValues() -} - -func showDialogue(recover bool, msg string, a ...interface{}) { - popup = true - if !recover { - window.Close() - } - dialogue := widgets.NewQDialog(nil, 0) - centralWidget := widgets.NewQWidget(dialogue, 0) - actionHBox := widgets.NewQHBoxLayout() - formLayout := widgets.NewQFormLayout(nil) - contBtn := widgets.NewQPushButton(nil) - quitBtn := widgets.NewQPushButton(nil) - message := widgets.NewQLabel(nil, 0) - - dialogue.SetWindowTitle("TeslaGo Alert") - dialogue.SetMinimumWidth(255) - dialogue.SetMinimumHeight(50 + (20 * (1 + strings.Count(msg, "\n")))) - - contBtn.SetText("Continue") - quitBtn.SetText("Quit") - message.SetText(fmt.Sprintf(msg, a...)) - message.SetWordWrap(true) - - contBtn.ConnectClicked(func(checked bool) { - window.Show() - popup = false - dialogue.Close() - - go setValues() - }) - quitBtn.ConnectClicked(func(checked bool) { - mainApp.Quit() - }) - - if recover { - actionHBox.AddWidget(contBtn, 0, 0) - } - actionHBox.AddWidget(quitBtn, 0, 0) - - formLayout.AddRow5(message) - formLayout.AddRow6(actionHBox) - centralWidget.SetLayout(formLayout) - - dialogue.Show() -} - -func formatDuration(d time.Duration) string { - d = d.Round(time.Minute) - h := d / time.Hour - d -= h * time.Hour - m := d / time.Minute - return fmt.Sprintf("%02dh%02dm", h, m) -}