@@ -39,6 +39,7 @@ import (
3939 log "github.com/Sirupsen/logrus"
4040 "github.com/arduino/arduino-create-agent/icon"
4141 "github.com/getlantern/systray"
42+ "github.com/go-ini/ini"
4243 "github.com/kardianos/osext"
4344 "github.com/skratchdot/open-golang/open"
4445 "github.com/vharitonsky/iniflags"
@@ -82,7 +83,13 @@ func getConfigs() []ConfigIni {
8283 filepath .Walk (dest , func (path string , f os.FileInfo , _ error ) error {
8384 if ! f .IsDir () {
8485 if filepath .Ext (path ) == ".ini" {
85- conf := ConfigIni {Name : f .Name (), Localtion : filepath .Join (dest , f .Name ())}
86+ cfg , _ := ini .LoadSources (ini.LoadOptions {IgnoreInlineComment : true }, filepath .Join (dest , f .Name ()))
87+ defaultSection , err := cfg .GetSection ("" )
88+ name := defaultSection .Key ("name" ).String ()
89+ if name == "" || err != nil {
90+ name = "Default config"
91+ }
92+ conf := ConfigIni {Name : name , Localtion : f .Name ()}
8693 configs = append (configs , conf )
8794 }
8895 }
@@ -91,6 +98,21 @@ func getConfigs() []ConfigIni {
9198 return configs
9299}
93100
101+ func applyEnvironment (filename string ) {
102+ src , _ := osext .Executable ()
103+ dest := filepath .Dir (src )
104+ cfg , _ := ini .LoadSources (ini.LoadOptions {IgnoreInlineComment : true }, filepath .Join (dest , filename ))
105+ defaultSection , err := cfg .GetSection ("env" )
106+ if err != nil {
107+ return
108+ }
109+ for _ , env := range defaultSection .KeyStrings () {
110+ val := defaultSection .Key (env ).String ()
111+ log .Info ("Applying env setting: " + env + "=" + val )
112+ os .Setenv (env , val )
113+ }
114+ }
115+
94116func setupSysTrayReal () {
95117
96118 systray .SetIcon (icon .GetIcon ())
@@ -103,8 +125,14 @@ func setupSysTrayReal() {
103125 configs := getConfigs ()
104126
105127 for _ , config := range configs {
106- log .Println ("Adding " + config .Name )
107- mConfigCheckbox = append (mConfigCheckbox , systray .AddMenuItem (config .Name , "" ))
128+ entry := systray .AddMenuItem (config .Name , "" )
129+ mConfigCheckbox = append (mConfigCheckbox , entry )
130+ // decorate configs
131+ gliph := " ☐ "
132+ if * configIni == config .Localtion {
133+ gliph = " 🗹 "
134+ }
135+ entry .SetTitle (gliph + config .Name )
108136 }
109137 //mQuit := systray.AddMenuItem("Quit Plugin", "")
110138
@@ -116,11 +144,12 @@ func setupSysTrayReal() {
116144 <- mConfigCheckbox [v ].ClickedCh
117145 flag .Set ("config" , configs [v ].Localtion )
118146 iniflags .UpdateConfig ()
119- mConfigCheckbox [v ].SetTitle (" ✓ " + configs [v ].Name )
147+ applyEnvironment (configs [v ].Localtion )
148+ mConfigCheckbox [v ].SetTitle (" 🗹 " + configs [v ].Name )
120149 //mConfigCheckbox[v].Check()
121150 for j , _ := range mConfigCheckbox {
122151 if j != v {
123- mConfigCheckbox [j ].SetTitle (" " + configs [j ].Name )
152+ mConfigCheckbox [j ].SetTitle (" ☐ " + configs [j ].Name )
124153 }
125154 }
126155 }
0 commit comments