@@ -22,6 +22,7 @@ package systray
2222import (
2323 "os"
2424 "runtime"
25+ "strings"
2526
2627 "fyne.io/systray"
2728 cert "github.com/arduino/arduino-create-agent/certificates"
@@ -64,18 +65,11 @@ func (s *Systray) start() {
6465 mRmCrashes := systray .AddMenuItem ("Remove crash reports" , "" )
6566 s .updateMenuItem (mRmCrashes , config .LogsIsEmpty ())
6667
67- mGenCerts := systray .AddMenuItem ("Generate and Install HTTPS certificates" , "HTTPS Certs" )
68- mRemoveCerts := systray .AddMenuItem ("Remove HTTPS certificates" , "" )
69- mCertsInfo := systray .AddMenuItem ("Show HTTPS certificates info" , "" )
68+ mManageCerts := systray .AddMenuItem ("Manage HTTPS certificates" , "HTTPS Certs" )
7069 // On linux/windows chrome/firefox/edge(chromium) the agent works without problems on plain HTTP,
7170 // so we disable the menuItem to generate/install the certificates
7271 if runtime .GOOS != "darwin" {
73- s .updateMenuItem (mGenCerts , true )
74- s .updateMenuItem (mRemoveCerts , true )
75- s .updateMenuItem (mCertsInfo , true )
76- } else {
77- s .updateMenuItem (mGenCerts , config .CertsExist ())
78- s .updateMenuItem (mRemoveCerts , ! config .CertsExist ())
72+ s .updateMenuItem (mManageCerts , true )
7973 }
8074
8175 // Add pause/quit
@@ -99,41 +93,46 @@ func (s *Systray) start() {
9993 case <- mRmCrashes .ClickedCh :
10094 RemoveCrashes ()
10195 s .updateMenuItem (mRmCrashes , config .LogsIsEmpty ())
102- case <- mGenCerts .ClickedCh :
103- certDir := config .GetCertificatesDir ()
104- cert .GenerateCertificates (certDir )
105- err := cert .InstallCertificate (certDir .Join ("ca.cert.cer" ))
106- // if something goes wrong during the cert install we remove them, so the user is able to retry
107- if err != nil {
108- log .Errorf ("cannot install certificates something went wrong: %s" , err )
109- cert .DeleteCertificates (certDir )
110- }
111- err = config .SetInstallCertsIni (s .currentConfigFilePath .String (), "true" )
112- if err != nil {
113- log .Errorf ("cannot set installCerts value in config.ini: %s" , err )
114- }
115- s .Restart ()
116- case <- mRemoveCerts .ClickedCh :
117- err := cert .UninstallCertificates ()
118- if err != nil {
119- log .Errorf ("cannot uninstall certificates something went wrong: %s" , err )
120- } else {
121- certDir := config .GetCertificatesDir ()
122- cert .DeleteCertificates (certDir )
123- }
124- s .Restart ()
125- case <- mCertsInfo .ClickedCh :
96+ case <- mManageCerts .ClickedCh :
12697 infoMsg := "The Arduino Agent needs a local HTTPS certificate to work correctly with Safari.\n \n Your HTTPS certificate status:\n "
98+ buttons := "{\" OK\" , \" Install certificate for Safari\" }"
99+ certDir := config .GetCertificatesDir ()
127100 if config .CertsExist () {
128101 expDate , err := cert .GetExpirationDate ()
129102 if err != nil {
130103 log .Errorf ("cannot get certificates expiration date, something went wrong: %s" , err )
131104 }
132105 infoMsg = infoMsg + "- Certificate installed: Yes\n - Certificate trusted: Yes\n - Certificate expiration date: " + expDate
106+ buttons = "{\" OK\" , \" Uninstall certificate for Safari\" }"
133107 } else {
134108 infoMsg = infoMsg + "- Certificate installed: No\n - Certificate trusted: N/A\n - Certificate expiration date: N/A"
135109 }
136- utilities .UserPrompt ("display dialog \" " + infoMsg + "\" buttons \" OK\" with title \" Arduino Agent: certificates info\" " )
110+ pressedButton := utilities .UserPrompt ("display dialog \" " + infoMsg + "\" buttons " + buttons + " with title \" Arduino Agent: manage HTTPS certificates\" " )
111+ if strings .Contains (pressedButton , "Install certificate for Safari" ) {
112+ cert .GenerateCertificates (certDir )
113+ err := cert .InstallCertificate (certDir .Join ("ca.cert.cer" ))
114+ // if something goes wrong during the cert install we remove them, so the user is able to retry
115+ if err != nil {
116+ log .Errorf ("cannot install certificates something went wrong: %s" , err )
117+ cert .DeleteCertificates (certDir )
118+ }
119+ err = config .SetInstallCertsIni (s .currentConfigFilePath .String (), "true" )
120+ if err != nil {
121+ log .Errorf ("cannot set installCerts value in config.ini: %s" , err )
122+ }
123+ } else if strings .Contains (pressedButton , "Uninstall certificate for Safari" ) {
124+ err := cert .UninstallCertificates ()
125+ if err != nil {
126+ log .Errorf ("cannot uninstall certificates something went wrong: %s" , err )
127+ } else {
128+ cert .DeleteCertificates (certDir )
129+ err = config .SetInstallCertsIni (s .currentConfigFilePath .String (), "false" )
130+ if err != nil {
131+ log .Errorf ("cannot set installCerts value in config.ini: %s" , err )
132+ }
133+ }
134+ }
135+ s .Restart ()
137136 case <- mPause .ClickedCh :
138137 s .Pause ()
139138 case <- mQuit .ClickedCh :
0 commit comments