@@ -39,6 +39,7 @@ import (
39
39
log "github.com/Sirupsen/logrus"
40
40
"github.com/arduino/arduino-create-agent/icon"
41
41
"github.com/getlantern/systray"
42
+ "github.com/go-ini/ini"
42
43
"github.com/kardianos/osext"
43
44
"github.com/skratchdot/open-golang/open"
44
45
"github.com/vharitonsky/iniflags"
@@ -82,7 +83,13 @@ func getConfigs() []ConfigIni {
82
83
filepath .Walk (dest , func (path string , f os.FileInfo , _ error ) error {
83
84
if ! f .IsDir () {
84
85
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 ()}
86
93
configs = append (configs , conf )
87
94
}
88
95
}
@@ -91,6 +98,21 @@ func getConfigs() []ConfigIni {
91
98
return configs
92
99
}
93
100
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
+
94
116
func setupSysTrayReal () {
95
117
96
118
systray .SetIcon (icon .GetIcon ())
@@ -103,8 +125,14 @@ func setupSysTrayReal() {
103
125
configs := getConfigs ()
104
126
105
127
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 )
108
136
}
109
137
//mQuit := systray.AddMenuItem("Quit Plugin", "")
110
138
@@ -116,11 +144,12 @@ func setupSysTrayReal() {
116
144
<- mConfigCheckbox [v ].ClickedCh
117
145
flag .Set ("config" , configs [v ].Localtion )
118
146
iniflags .UpdateConfig ()
119
- mConfigCheckbox [v ].SetTitle (" ✓ " + configs [v ].Name )
147
+ applyEnvironment (configs [v ].Localtion )
148
+ mConfigCheckbox [v ].SetTitle (" 🗹 " + configs [v ].Name )
120
149
//mConfigCheckbox[v].Check()
121
150
for j , _ := range mConfigCheckbox {
122
151
if j != v {
123
- mConfigCheckbox [j ].SetTitle (" " + configs [j ].Name )
152
+ mConfigCheckbox [j ].SetTitle (" ☐ " + configs [j ].Name )
124
153
}
125
154
}
126
155
}
0 commit comments