Skip to content

Fix buttons and improve handling of certificates when Safari is not the default browser #949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f43b0e4
Fix check on buttons returning the correct message
MatteoPologruto May 8, 2024
f69980a
Update certificates regardless of the default browser
MatteoPologruto May 8, 2024
f7bd6e3
Set installCerts when the certificate is installed from previous vers…
MatteoPologruto May 8, 2024
8006310
Do not set installCerts to false if the default browser is not Safari
MatteoPologruto May 8, 2024
aa02ed0
Do not ask again to update the certificate if the user refuses once
MatteoPologruto May 9, 2024
e46bfbf
Fix user script on macOS
MatteoPologruto May 9, 2024
7f4cdf6
Check for the presence of the certificate in the keychain to determin…
MatteoPologruto May 9, 2024
4285c04
Fix getExpirationDate breaking when the certificate is expired
MatteoPologruto May 9, 2024
4064541
Fix return value in case of error
MatteoPologruto May 9, 2024
cf31546
getExpirationDate rewritten to use the correct expiration field.
Xayton May 9, 2024
411d051
Separate osascript default button from the one to press
MatteoPologruto May 9, 2024
c11610b
Fix leftover buttons
MatteoPologruto May 9, 2024
9494f25
Small text fixes in the "manage certificate" dialog
Xayton May 10, 2024
d56f231
Simplify error management in getExpirationDate
Xayton May 10, 2024
8ec1efc
Fix compiler warnings and move obj-c code into a separate file.
Xayton May 10, 2024
34fae24
certInKeychain returns a bool
Xayton May 10, 2024
8854680
Fix building errors caused by objective-c files on Ubuntu and Windows
MatteoPologruto May 13, 2024
681a250
Build objective-c files only on Darwin
MatteoPologruto May 13, 2024
c461c40
Remove -ld_classic library because XCode is not up to date on the CI
MatteoPologruto May 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Separate osascript default button from the one to press
  • Loading branch information
MatteoPologruto committed May 9, 2024
commit 411d051fb7882714bbeb4a8700a43099a4629fc5
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func loop() {
// If we are updating manually from 1.2.7 to 1.3.0 we have to uninstall the old agent manually first.
// This check will inform the user if he needs to run the uninstall first
if runtime.GOOS == "darwin" && oldInstallExists() {
utilities.UserPrompt("Old agent installation of the Arduino Create Agent found, please uninstall it before launching the new one", "\"OK\"", "OK", "Error")
utilities.UserPrompt("Old agent installation of the Arduino Create Agent found, please uninstall it before launching the new one", "\"OK\"", "OK", "OK", "Error")
os.Exit(0)
}

Expand Down Expand Up @@ -378,7 +378,7 @@ func loop() {
if expired, err := cert.IsExpired(); err != nil {
log.Errorf("cannot check if certificates are expired something went wrong: %s", err)
} else if expired {
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")
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")
if buttonPressed {
err := cert.UninstallCertificates()
if err != nil {
Expand Down Expand Up @@ -555,5 +555,5 @@ func installCertsKeyExists(filename string) (bool, error) {
}

func promptInstallCertsSafari() bool {
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")
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")
}
12 changes: 6 additions & 6 deletions systray/systray_real.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,18 @@ func (s *Systray) start() {
s.updateMenuItem(mRmCrashes, config.LogsIsEmpty())
case <-mManageCerts.ClickedCh:
infoMsg := "The Arduino Agent needs a local HTTPS certificate to work correctly with Safari.\n\nYour HTTPS certificate status:\n"
buttons := "{\"OK\", \"Install the certificate for Safari\"}"
defaultButton := "Install the certificate for Safari"
buttons := "{\"Install the certificate for Safari\", \"OK\"}"
toPress := "Install the certificate for Safari"
certDir := config.GetCertificatesDir()
if cert.CertInKeychain() || config.CertsExist() {
expDate, err := cert.GetExpirationDate()
if err != nil {
log.Errorf("cannot get certificates expiration date, something went wrong: %s", err)
}
infoMsg = infoMsg + "- Certificate installed: Yes\n- Certificate trusted: Yes\n- Certificate expiration date: " + expDate.Format(time.DateTime)
buttons = "{\"OK\", \"Uninstall the certificate for Safari\"}"
defaultButton = "Uninstall the certificate for Safari"
pressedButton := utilities.UserPrompt(infoMsg, buttons, defaultButton, "Arduino Agent: Manage HTTPS certificate")
buttons = "{\"Uninstall the certificate for Safari\", \"OK\"}"
toPress = "Uninstall the certificate for Safari"
pressedButton := utilities.UserPrompt(infoMsg, buttons, "OK", toPress, "Arduino Agent: Manage HTTPS certificate")
if pressedButton {
err := cert.UninstallCertificates()
if err != nil {
Expand All @@ -122,7 +122,7 @@ func (s *Systray) start() {
}
} else {
infoMsg = infoMsg + "- Certificate installed: No\n- Certificate trusted: N/A\n- Certificate expiration date: N/A"
pressedButton := utilities.UserPrompt(infoMsg, buttons, defaultButton, "Arduino Agent: Manage HTTPS certificate")
pressedButton := utilities.UserPrompt(infoMsg, buttons, "OK", toPress, "Arduino Agent: Manage HTTPS certificate")
if pressedButton {
cert.GenerateAndInstallCertificates(certDir)
err := config.SetInstallCertsIni(s.currentConfigFilePath.String(), "true")
Expand Down
4 changes: 2 additions & 2 deletions utilities/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ func VerifyInput(input string, signature string) error {
}

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