@@ -22,7 +22,6 @@ import (
22
22
_ "embed"
23
23
"encoding/json"
24
24
"flag"
25
- "fmt"
26
25
"html/template"
27
26
"io"
28
27
"os"
@@ -103,18 +102,21 @@ var homeTemplateHTML string
103
102
104
103
// global clients
105
104
var (
106
- Tools * tools.Tools
107
- Index * index.Resource
105
+ Tools * tools.Tools
106
+ Systray systray.Systray
107
+ Index * index.Resource
108
108
)
109
109
110
- // TODO: enable it
110
+ // FIXME; the loggerWS is useind in the multiwrite in the hub
111
111
// type logWriter struct{}
112
112
113
113
// func (u *logWriter) Write(p []byte) (n int, err error) {
114
114
// h.broadcastSys <- p
115
115
// return len(p), nil
116
116
// }
117
117
118
+ // var loggerWs logWriter
119
+
118
120
func homeHandler (c * gin.Context ) {
119
121
homeTemplate .Execute (c .Writer , c .Request .Host )
120
122
}
@@ -140,13 +142,9 @@ func main() {
140
142
// Check if certificates made with Agent <=1.2.7 needs to be moved over the new location
141
143
cert .MigrateCertificatesGeneratedWithOldAgentVersions (config .GetCertificatesDir ())
142
144
143
- configPath := config .GetConfigPath ()
144
- fmt .Println ("configPath: " , configPath )
145
-
146
145
// SetupSystray is the main thread
147
146
configDir := config .GetDefaultConfigDir ()
148
-
149
- stray := & systray.Systray {
147
+ stray := systray.Systray {
150
148
Hibernate : * hibernate ,
151
149
Version : version + "-" + commit ,
152
150
DebugURL : func () string {
@@ -155,29 +153,24 @@ func main() {
155
153
AdditionalConfig : * additionalConfig ,
156
154
ConfigDir : configDir ,
157
155
}
158
- stray .SetCurrentConfigFile (configPath )
159
156
160
157
// Launch main loop in a goroutine
161
- go loop (stray , configPath )
158
+ go loop (& stray )
162
159
163
160
if src , err := os .Executable (); err != nil {
164
161
panic (err )
165
162
} else if restartPath := updater .Start (src ); restartPath != "" {
166
- stray .RestartWith (restartPath )
163
+ Systray .RestartWith (restartPath )
167
164
} else {
168
- stray .Start ()
165
+ Systray .Start ()
169
166
}
170
167
}
171
168
172
- func loop (stray * systray.Systray , configPath * paths. Path ) {
169
+ func loop (stray * systray.Systray ) {
173
170
if * hibernate {
174
171
return
175
172
}
176
173
177
- if configPath == nil {
178
- log .Panic ("configPath is nil" )
179
- }
180
-
181
174
log .SetLevel (log .InfoLevel )
182
175
log .SetOutput (os .Stdout )
183
176
@@ -190,12 +183,8 @@ func loop(stray *systray.Systray, configPath *paths.Path) {
190
183
os .Exit (0 )
191
184
}
192
185
193
- // serialPorts contains the ports attached to the machine
194
186
serialPorts := newSerialPortList ()
195
187
serialHub := newSerialHub ()
196
-
197
- // var loggerWs logWriter
198
-
199
188
hub := newHub (serialHub , serialPorts )
200
189
201
190
logger := func (msg string ) {
@@ -204,6 +193,39 @@ func loop(stray *systray.Systray, configPath *paths.Path) {
204
193
hub .broadcastSys <- mapB
205
194
}
206
195
196
+ // Let's handle the config
197
+ configDir := config .GetDefaultConfigDir ()
198
+ var configPath * paths.Path
199
+
200
+ // see if the env var is defined, if it is take the config from there, this will override the default path
201
+ if envConfig := os .Getenv ("ARDUINO_CREATE_AGENT_CONFIG" ); envConfig != "" {
202
+ configPath = paths .New (envConfig )
203
+ if configPath .NotExist () {
204
+ log .Panicf ("config from env var %s does not exists" , envConfig )
205
+ }
206
+ log .Infof ("using config from env variable: %s" , configPath )
207
+ } else if defaultConfigPath := configDir .Join ("config.ini" ); defaultConfigPath .Exist () {
208
+ // by default take the config from the ~/.arduino-create/config.ini file
209
+ configPath = defaultConfigPath
210
+ log .Infof ("using config from default: %s" , configPath )
211
+ } else {
212
+ // Fall back to the old config.ini location
213
+ src , _ := os .Executable ()
214
+ oldConfigPath := paths .New (src ).Parent ().Join ("config.ini" )
215
+ if oldConfigPath .Exist () {
216
+ err := oldConfigPath .CopyTo (defaultConfigPath )
217
+ if err != nil {
218
+ log .Errorf ("cannot copy old %s, to %s, generating new config" , oldConfigPath , configPath )
219
+ } else {
220
+ configPath = defaultConfigPath
221
+ log .Infof ("copied old %s, to %s" , oldConfigPath , configPath )
222
+ }
223
+ }
224
+ }
225
+ if configPath == nil {
226
+ configPath = config .GenerateConfig (configDir )
227
+ }
228
+
207
229
// if the default browser is Safari, prompt the user to install HTTPS certificates
208
230
// and eventually install them
209
231
if runtime .GOOS == "darwin" {
@@ -241,6 +263,7 @@ func loop(stray *systray.Systray, configPath *paths.Path) {
241
263
if err != nil {
242
264
log .Panicf ("cannot parse arguments: %s" , err )
243
265
}
266
+ Systray .SetCurrentConfigFile (configPath )
244
267
245
268
// Parse additional ini config if defined
246
269
if len (* additionalConfig ) > 0 {
0 commit comments