Skip to content

Commit 411d051

Browse files
Separate osascript default button from the one to press
1 parent cf31546 commit 411d051

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func loop() {
178178
// If we are updating manually from 1.2.7 to 1.3.0 we have to uninstall the old agent manually first.
179179
// This check will inform the user if he needs to run the uninstall first
180180
if runtime.GOOS == "darwin" && oldInstallExists() {
181-
utilities.UserPrompt("Old agent installation of the Arduino Create Agent found, please uninstall it before launching the new one", "\"OK\"", "OK", "Error")
181+
utilities.UserPrompt("Old agent installation of the Arduino Create Agent found, please uninstall it before launching the new one", "\"OK\"", "OK", "OK", "Error")
182182
os.Exit(0)
183183
}
184184

@@ -378,7 +378,7 @@ func loop() {
378378
if expired, err := cert.IsExpired(); err != nil {
379379
log.Errorf("cannot check if certificates are expired something went wrong: %s", err)
380380
} else if expired {
381-
buttonPressed := utilities.UserPrompt("The Arduino Agent needs a local HTTPS certificate to work correctly with Safari.\nYour certificate is expired or close to expiration. Do you want to update it?", "{\"Do not update\", \"Update the certificate for Safari\"}", "Update the certificate for Safari", "Arduino Agent: Update certificate")
381+
buttonPressed := utilities.UserPrompt("The Arduino Agent needs a local HTTPS certificate to work correctly with Safari.\nYour certificate is expired or close to expiration. Do you want to update it?", "{\"Do not update\", \"Update the certificate for Safari\"}", "Update the certificate for Safari", "Update the certificate for Safari", "Arduino Agent: Update certificate")
382382
if buttonPressed {
383383
err := cert.UninstallCertificates()
384384
if err != nil {
@@ -555,5 +555,5 @@ func installCertsKeyExists(filename string) (bool, error) {
555555
}
556556

557557
func promptInstallCertsSafari() bool {
558-
return utilities.UserPrompt("The Arduino Agent needs a local HTTPS certificate to work correctly with Safari.\nIf you use Safari, you need to install it.", "{\"Do not install\", \"Install the certificate for Safari\"}", "Install the certificate for Safari", "Arduino Agent: Install certificate")
558+
return utilities.UserPrompt("The Arduino Agent needs a local HTTPS certificate to work correctly with Safari.\nIf you use Safari, you need to install it.", "{\"Do not install\", \"Install the certificate for Safari\"}", "Install the certificate for Safari", "Install the certificate for Safari", "Arduino Agent: Install certificate")
559559
}

systray/systray_real.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,18 @@ func (s *Systray) start() {
9595
s.updateMenuItem(mRmCrashes, config.LogsIsEmpty())
9696
case <-mManageCerts.ClickedCh:
9797
infoMsg := "The Arduino Agent needs a local HTTPS certificate to work correctly with Safari.\n\nYour HTTPS certificate status:\n"
98-
buttons := "{\"OK\", \"Install the certificate for Safari\"}"
99-
defaultButton := "Install the certificate for Safari"
98+
buttons := "{\"Install the certificate for Safari\", \"OK\"}"
99+
toPress := "Install the certificate for Safari"
100100
certDir := config.GetCertificatesDir()
101101
if cert.CertInKeychain() || config.CertsExist() {
102102
expDate, err := cert.GetExpirationDate()
103103
if err != nil {
104104
log.Errorf("cannot get certificates expiration date, something went wrong: %s", err)
105105
}
106106
infoMsg = infoMsg + "- Certificate installed: Yes\n- Certificate trusted: Yes\n- Certificate expiration date: " + expDate.Format(time.DateTime)
107-
buttons = "{\"OK\", \"Uninstall the certificate for Safari\"}"
108-
defaultButton = "Uninstall the certificate for Safari"
109-
pressedButton := utilities.UserPrompt(infoMsg, buttons, defaultButton, "Arduino Agent: Manage HTTPS certificate")
107+
buttons = "{\"Uninstall the certificate for Safari\", \"OK\"}"
108+
toPress = "Uninstall the certificate for Safari"
109+
pressedButton := utilities.UserPrompt(infoMsg, buttons, "OK", toPress, "Arduino Agent: Manage HTTPS certificate")
110110
if pressedButton {
111111
err := cert.UninstallCertificates()
112112
if err != nil {
@@ -122,7 +122,7 @@ func (s *Systray) start() {
122122
}
123123
} else {
124124
infoMsg = infoMsg + "- Certificate installed: No\n- Certificate trusted: N/A\n- Certificate expiration date: N/A"
125-
pressedButton := utilities.UserPrompt(infoMsg, buttons, defaultButton, "Arduino Agent: Manage HTTPS certificate")
125+
pressedButton := utilities.UserPrompt(infoMsg, buttons, "OK", toPress, "Arduino Agent: Manage HTTPS certificate")
126126
if pressedButton {
127127
cert.GenerateAndInstallCertificates(certDir)
128128
err := config.SetInstallCertsIni(s.currentConfigFilePath.String(), "true")

utilities/utilities.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ func VerifyInput(input string, signature string) error {
151151
}
152152

153153
// UserPrompt executes an osascript and returns the pressed button
154-
func UserPrompt(dialog string, buttons string, defaultButton string, title string) bool {
154+
func UserPrompt(dialog string, buttons string, defaultButton string, toPress string, title string) bool {
155155
oscmd := exec.Command("osascript", "-e", "display dialog \""+dialog+"\" buttons "+buttons+" default button\""+defaultButton+"\" with title \""+title+"\"")
156156
pressedButton, _ := oscmd.Output()
157-
return strings.Contains(string(pressedButton), "button returned:"+defaultButton)
157+
return strings.Contains(string(pressedButton), "button returned:"+toPress)
158158
}

0 commit comments

Comments
 (0)