@@ -22,6 +22,7 @@ package systray
22
22
import (
23
23
"os"
24
24
"runtime"
25
+ "strings"
25
26
26
27
"fyne.io/systray"
27
28
cert "github.com/arduino/arduino-create-agent/certificates"
@@ -64,18 +65,11 @@ func (s *Systray) start() {
64
65
mRmCrashes := systray .AddMenuItem ("Remove crash reports" , "" )
65
66
s .updateMenuItem (mRmCrashes , config .LogsIsEmpty ())
66
67
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" )
70
69
// On linux/windows chrome/firefox/edge(chromium) the agent works without problems on plain HTTP,
71
70
// so we disable the menuItem to generate/install the certificates
72
71
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 )
79
73
}
80
74
81
75
// Add pause/quit
@@ -99,41 +93,46 @@ func (s *Systray) start() {
99
93
case <- mRmCrashes .ClickedCh :
100
94
RemoveCrashes ()
101
95
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 :
126
97
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 ()
127
100
if config .CertsExist () {
128
101
expDate , err := cert .GetExpirationDate ()
129
102
if err != nil {
130
103
log .Errorf ("cannot get certificates expiration date, something went wrong: %s" , err )
131
104
}
132
105
infoMsg = infoMsg + "- Certificate installed: Yes\n - Certificate trusted: Yes\n - Certificate expiration date: " + expDate
106
+ buttons = "{\" OK\" , \" Uninstall certificate for Safari\" }"
133
107
} else {
134
108
infoMsg = infoMsg + "- Certificate installed: No\n - Certificate trusted: N/A\n - Certificate expiration date: N/A"
135
109
}
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 ()
137
136
case <- mPause .ClickedCh :
138
137
s .Pause ()
139
138
case <- mQuit .ClickedCh :
0 commit comments