diff --git a/main.go b/main.go index c07b089..f5fb223 100644 --- a/main.go +++ b/main.go @@ -203,26 +203,26 @@ func setValues() { vehicle = getVehicle("") var err error if vehicle == nil { - showDialogue("Unable to get vehicle") + showDialogue(false, "Unable to get vehicle") return } vehicleState, err = vehicle.VehicleState() if err != nil { - showDialogue("Unable to get Vehicle State") + showDialogue(false, "Unable to get Vehicle State") } chargeStats, err = vehicle.ChargeState() if err != nil { - showDialogue("Unable to get Vehicle Charge State") + showDialogue(false, "Unable to get Vehicle Charge State") } climateState, err = vehicle.ClimateState() if err != nil { - showDialogue("Unable to get Vehicle Climate") + showDialogue(false, "Unable to get Vehicle Climate") } guiSettings, err = vehicle.GuiSettings() if err != nil { - showDialogue("Unable to get Gui Settings") + showDialogue(false, "Unable to get Gui Settings") } tempSettingVal := climateState.DriverTempSetting insideTempVal := climateState.InsideTemp @@ -271,7 +271,7 @@ func setValues() { func enableClimate(i int) { temp, err := strconv.ParseFloat(tempSetting.Text(), 64) if err != nil { - showDialogue("Unable to parse temp setting\n%+v", err) + showDialogue(true, "Unable to parse temp setting\n%+v", err) } if guiSettings.GuiTemperatureUnits == "F" { temp = (temp - 32) * 5 / 9 @@ -312,7 +312,7 @@ func enableCharging(i int) { func honkHorn(c bool) { err := vehicle.HonkHorn() if err != nil { - showDialogue("There was an error honking the horn\n%+v", err) + showDialogue(true, "There was an error honking the horn\n%+v", err) fmt.Printf("%+v\n", err) } go setValues() @@ -320,7 +320,7 @@ func honkHorn(c bool) { func flash(c bool) { err := vehicle.FlashLights() if err != nil { - showDialogue("There was an error flashing the lights\n%+v", err) + showDialogue(true, "There was an error flashing the lights\n%+v", err) fmt.Printf("%+v\n", err) } go setValues() @@ -328,7 +328,7 @@ func flash(c bool) { func openTrunk(c bool) { err := vehicle.OpenTrunk("rear") if err != nil { - showDialogue("There was an error opening your trunk\n%+v", err) + showDialogue(true, "There was an error opening your trunk\n%+v", err) fmt.Printf("%+v\n", err) } go setValues() @@ -336,24 +336,30 @@ func openTrunk(c bool) { func openFrunk(c bool) { err := vehicle.OpenTrunk("front") if err != nil { - showDialogue("There was an error opening your frunk\n%+v", err) + showDialogue(true, "There was an error opening your frunk\n%+v", err) fmt.Printf("%+v\n", err) } go setValues() } -func showDialogue(msg string, a ...interface{}) { +func showDialogue(recover bool, msg string, a ...interface{}) { popup = true dialogue := widgets.NewQDialog(nil, 0) - dialogue.SetWindowTitle("TeslaGo Alert") + 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() @@ -366,19 +372,14 @@ func showDialogue(msg string, a ...interface{}) { mainApp.Quit() }) - actionHBox.AddWidget(contBtn, 0, 0) + if recover { + actionHBox.AddWidget(contBtn, 0, 0) + } actionHBox.AddWidget(quitBtn, 0, 0) - message := widgets.NewQLabel(nil, 0) - message.SetText(fmt.Sprintf(msg, a...)) - message.SetWordWrap(true) - formLayout.AddRow5(message) formLayout.AddRow6(actionHBox) - centralWidget := widgets.NewQWidget(dialogue, 0) centralWidget.SetLayout(formLayout) - dialogue.SetMinimumWidth(255) - dialogue.SetMinimumHeight(50 + (20 * (1 + strings.Count(msg, "\n")))) dialogue.Show() }