@@ -21,10 +21,9 @@ type indexFile struct {
2121}
2222
2323type indexEntry struct {
24- ID string `json:"id"`
25- Name string `json:"name"`
26- Category string `json:"category"`
27- Platforms []string `json:"platforms"`
24+ ID string `json:"id"`
25+ Name string `json:"name"`
26+ Category string `json:"category"`
2827}
2928
3029type pluginState struct {
@@ -48,33 +47,21 @@ type manifest struct {
4847 Comment map [string ]string `json:"comment"`
4948}
5049
51- type connectFile struct {
52- Platforms map [string ]platformConnect `json:"platforms"`
53- }
54-
5550type platformConnect struct {
5651 DisplayName string `json:"display_name"`
5752 Executable executableConfig `json:"executable"`
5853 Launch map [string ]interface {} `json:"launch"`
54+ MatchFirst []string `json:"match_first"`
55+ IsDefault bool `json:"is_default"`
56+ IsSet bool `json:"is_set"`
57+ IsInternal bool `json:"is_internal"`
5958}
6059
6160type executableConfig struct {
6261 Type string `json:"type"`
6362 Default string `json:"default"`
6463}
6564
66- type defaultsFile struct {
67- Platforms map [string ]platformDefaults `json:"platforms"`
68- }
69-
70- type platformDefaults struct {
71- MatchFirst []string `json:"match_first"`
72- IsDefault bool `json:"is_default"`
73- IsSet bool `json:"is_set"`
74- IsInternal bool `json:"is_internal"`
75- Path string `json:"path"`
76- }
77-
7865func osKey () string {
7966 switch runtime .GOOS {
8067 case "darwin" :
@@ -177,6 +164,32 @@ func readJSON(path string, target interface{}) error {
177164 return json .Unmarshal (data , target )
178165}
179166
167+ func readConnect (path , osName string ) (platformConnect , bool , error ) {
168+ var raw map [string ]json.RawMessage
169+ if err := readJSON (path , & raw ); err != nil {
170+ return platformConnect {}, false , err
171+ }
172+
173+ if platformsRaw , ok := raw ["platforms" ]; ok {
174+ var platforms map [string ]platformConnect
175+ if err := json .Unmarshal (platformsRaw , & platforms ); err != nil {
176+ return platformConnect {}, false , err
177+ }
178+ connect , ok := platforms [osName ]
179+ return connect , ok , nil
180+ }
181+
182+ var connect platformConnect
183+ data , err := os .ReadFile (path )
184+ if err != nil {
185+ return platformConnect {}, false , err
186+ }
187+ if err := json .Unmarshal (data , & connect ); err != nil {
188+ return platformConnect {}, false , err
189+ }
190+ return connect , true , nil
191+ }
192+
180193func sanitizeState (state * pluginState ) bool {
181194 if state == nil || state .Selections == nil {
182195 return false
@@ -201,7 +214,7 @@ func sanitizeState(state *pluginState) bool {
201214 if runtime .GOOS != "windows" {
202215 for _ , key := range []string {"terminal:ssh" , "terminal:telnet" } {
203216 if state .Selections [key ] == osName + ".putty" {
204- delete ( state .Selections , key )
217+ state .Selections [ key ] = osName + ".terminal"
205218 changed = true
206219 }
207220 }
@@ -247,7 +260,7 @@ func launchToArgFormat(launch map[string]interface{}) (string, []config.AutoItCo
247260 }
248261}
249262
250- func resolvePath (pluginID string , defaults platformDefaults , connect platformConnect , state pluginState ) (string , bool , bool ) {
263+ func resolvePath (pluginID string , connect platformConnect , state pluginState ) (string , bool , bool ) {
251264 userPath := ""
252265 enabled := true
253266 hasUserPlugin := false
@@ -257,41 +270,23 @@ func resolvePath(pluginID string, defaults platformDefaults, connect platformCon
257270 enabled = item .Enabled
258271 }
259272
260- path := defaults . Path
273+ path := connect . Executable . Default
261274 if userPath != "" {
262275 path = userPath
263- } else if path == "" {
264- path = connect .Executable .Default
265276 }
266277
267- isSet := (defaults .IsSet || userPath != "" || (defaults .IsInternal && path != "" && hasUserPlugin )) && enabled
268- return path , isSet , defaults .IsInternal
278+ isSet := (connect .IsSet || userPath != "" || (connect .IsInternal && path != "" && hasUserPlugin )) && enabled
279+ return path , isSet , connect .IsInternal
269280}
270281
271- func buildMatchFirst (pluginID , category string , protocols []string , selections map [string ]string , fallback [] string ) []string {
282+ func buildMatchFirst (pluginID , category string , protocols []string , selections map [string ]string ) []string {
272283 matched := []string {}
273284 for _ , proto := range protocols {
274285 key := category + ":" + proto
275286 if selections [key ] == pluginID {
276287 matched = append (matched , proto )
277288 }
278289 }
279-
280- seen := map [string ]bool {}
281- for _ , proto := range matched {
282- seen [proto ] = true
283- }
284- for _ , proto := range fallback {
285- if seen [proto ] {
286- continue
287- }
288- key := category + ":" + proto
289- if selected := selections [key ]; selected != "" && selected != pluginID {
290- continue
291- }
292- matched = append (matched , proto )
293- seen [proto ] = true
294- }
295290 return matched
296291}
297292
@@ -353,31 +348,23 @@ func LoadAppConfig(configDir string) (*config.AppConfig, bool) {
353348 for _ , entry := range index .Plugins {
354349 pluginDir := filepath .Join (builtinDir , entry .ID )
355350 var manifest manifest
356- var connect connectFile
357- var defaults defaultsFile
358351
359352 if err := readJSON (filepath .Join (pluginDir , "manifest.json" ), & manifest ); err != nil {
360353 continue
361354 }
362- if err := readJSON (filepath .Join (pluginDir , "connect.json" ), & connect ); err != nil {
363- continue
364- }
365- _ = readJSON (filepath .Join (pluginDir , "defaults.json" ), & defaults )
366-
367- platformConnect , ok := connect .Platforms [osName ]
368- if ! ok {
355+ platformConnect , ok , err := readConnect (filepath .Join (pluginDir , "connect.json" ), osName )
356+ if err != nil || ! ok || platformConnect .Executable .Type == "" {
369357 continue
370358 }
371- platformDefaults := defaults .Platforms [osName ]
372359
373360 displayName := platformConnect .DisplayName
374361 if displayName == "" {
375362 displayName = manifest .DisplayName
376363 }
377364
378365 argFormat , autoit := launchToArgFormat (platformConnect .Launch )
379- matchFirst := buildMatchFirst (entry .ID , manifest .Category , manifest .Protocols , state .Selections , platformDefaults . MatchFirst )
380- path , isSet , isInternal := resolvePath (entry .ID , platformDefaults , platformConnect , state )
366+ matchFirst := buildMatchFirst (entry .ID , manifest .Category , manifest .Protocols , state .Selections )
367+ path , isSet , isInternal := resolvePath (entry .ID , platformConnect , state )
381368 if len (matchFirst ) > 0 {
382369 isSet = true
383370 }
@@ -392,7 +379,7 @@ func LoadAppConfig(configDir string) (*config.AppConfig, bool) {
392379 ArgFormat : argFormat ,
393380 AutoIt : autoit ,
394381 IsInternal : isInternal ,
395- IsDefault : platformDefaults .IsDefault ,
382+ IsDefault : platformConnect .IsDefault ,
396383 IsSet : isSet ,
397384 }
398385
0 commit comments