2020package systray
2121
2222import (
23- "fmt"
2423 "os"
2524 "os/user"
26- "path/filepath"
2725
2826 log "github.com/sirupsen/logrus"
2927
@@ -59,6 +57,7 @@ func (s *Systray) start() {
5957 // Add links
6058 mURL := systray .AddMenuItem ("Go to Arduino Create" , "Arduino Create" )
6159 mDebug := systray .AddMenuItem ("Open Debug Console" , "Debug console" )
60+ mConfig := systray .AddMenuItem ("Open Configuration" , "Config File" )
6261
6362 // Remove crash-reports
6463 mRmCrashes := systray .AddMenuItem ("Remove crash reports" , "" )
@@ -80,6 +79,8 @@ func (s *Systray) start() {
8079 _ = open .Start ("https://create.arduino.cc" )
8180 case <- mDebug .ClickedCh :
8281 _ = open .Start (s .DebugURL ())
82+ case <- mConfig .ClickedCh :
83+ _ = open .Start (s .currentConfigFilePath .String ())
8384 case <- mRmCrashes .ClickedCh :
8485 s .RemoveCrashes ()
8586 s .updateMenuItem (mRmCrashes , s .CrashesIsEmpty ())
@@ -155,7 +156,7 @@ func (s *Systray) end() {
155156func (s * Systray ) addConfigs () {
156157 var mConfigCheckbox []* systray.MenuItem
157158
158- configs := getConfigs ()
159+ configs := s . getConfigs ()
159160 if len (configs ) > 1 {
160161 for _ , config := range configs {
161162 entry := systray .AddMenuItem (config .Name , "" )
@@ -185,35 +186,30 @@ type configIni struct {
185186 Location string
186187}
187188
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 {
194191 var configs []configIni
195192
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"
210209 }
210+ conf := configIni {Name : name , Location : file .String ()}
211+ configs = append (configs , conf )
211212 }
212- return nil
213- })
214-
215- if err != nil {
216- fmt .Println ("error walking through executable configuration: %w" , err )
217213 }
218214
219215 return configs
0 commit comments