20
20
package systray
21
21
22
22
import (
23
- "fmt"
24
23
"os"
25
24
"os/user"
26
- "path/filepath"
27
25
28
26
log "github.com/sirupsen/logrus"
29
27
@@ -59,6 +57,7 @@ func (s *Systray) start() {
59
57
// Add links
60
58
mURL := systray .AddMenuItem ("Go to Arduino Create" , "Arduino Create" )
61
59
mDebug := systray .AddMenuItem ("Open Debug Console" , "Debug console" )
60
+ mConfig := systray .AddMenuItem ("Open Configuration" , "Config File" )
62
61
63
62
// Remove crash-reports
64
63
mRmCrashes := systray .AddMenuItem ("Remove crash reports" , "" )
@@ -80,6 +79,8 @@ func (s *Systray) start() {
80
79
_ = open .Start ("https://create.arduino.cc" )
81
80
case <- mDebug .ClickedCh :
82
81
_ = open .Start (s .DebugURL ())
82
+ case <- mConfig .ClickedCh :
83
+ _ = open .Start (s .currentConfigFilePath .String ())
83
84
case <- mRmCrashes .ClickedCh :
84
85
s .RemoveCrashes ()
85
86
s .updateMenuItem (mRmCrashes , s .CrashesIsEmpty ())
@@ -155,7 +156,7 @@ func (s *Systray) end() {
155
156
func (s * Systray ) addConfigs () {
156
157
var mConfigCheckbox []* systray.MenuItem
157
158
158
- configs := getConfigs ()
159
+ configs := s . getConfigs ()
159
160
if len (configs ) > 1 {
160
161
for _ , config := range configs {
161
162
entry := systray .AddMenuItem (config .Name , "" )
@@ -185,35 +186,30 @@ type configIni struct {
185
186
Location string
186
187
}
187
188
188
- // getconfigs parses all config files in the executable folder
189
- func getConfigs () []configIni {
190
- // config.ini must be there, so call it Default
191
- src , _ := os .Executable () // TODO change path
192
- dest := filepath .Dir (src )
193
-
189
+ // getConfigs parses all config files in the .arduino-create folder
190
+ func (s * Systray ) getConfigs () []configIni {
194
191
var configs []configIni
195
192
196
- err := filepath .Walk (dest , func (path string , f os.FileInfo , _ error ) error {
197
- if ! f .IsDir () {
198
- if filepath .Ext (path ) == ".ini" {
199
- cfg , err := ini .LoadSources (ini.LoadOptions {IgnoreInlineComment : true , AllowPythonMultilineValues : true }, filepath .Join (dest , f .Name ()))
200
- if err != nil {
201
- return err
202
- }
203
- defaultSection , err := cfg .GetSection ("" )
204
- name := defaultSection .Key ("name" ).String ()
205
- if name == "" || err != nil {
206
- name = "Default config"
207
- }
208
- conf := configIni {Name : name , Location : f .Name ()}
209
- configs = append (configs , conf )
193
+ files , err := s .ConfigDir .ReadDir ()
194
+ if err != nil {
195
+ log .Errorf ("cannot read the content of %s" , s .ConfigDir )
196
+ return nil
197
+ }
198
+ files .FilterOutDirs ()
199
+ files .FilterSuffix (".ini" )
200
+ for _ , file := range files {
201
+ cfg , err := ini .LoadSources (ini.LoadOptions {IgnoreInlineComment : true , AllowPythonMultilineValues : true }, file .String ())
202
+ if err != nil {
203
+ log .Errorf ("error walking through executable configuration: %s" , err )
204
+ } else {
205
+ defaultSection , err := cfg .GetSection ("" )
206
+ name := defaultSection .Key ("name" ).String ()
207
+ if name == "" || err != nil {
208
+ name = "Default config"
210
209
}
210
+ conf := configIni {Name : name , Location : file .String ()}
211
+ configs = append (configs , conf )
211
212
}
212
- return nil
213
- })
214
-
215
- if err != nil {
216
- fmt .Println ("error walking through executable configuration: %w" , err )
217
213
}
218
214
219
215
return configs
0 commit comments