mirror of
https://github.com/Hopiu/micro.git
synced 2026-04-15 20:01:04 +00:00
allow user to set plugin channels / repos in settings.json
This commit is contained in:
parent
d7da72a720
commit
a940ce3036
2 changed files with 38 additions and 5 deletions
|
|
@ -19,10 +19,6 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
pluginChannels PluginChannels = PluginChannels{
|
||||
PluginChannel("https://www.boombuler.de/channel.json"),
|
||||
}
|
||||
|
||||
allPluginPackages PluginPackages = nil
|
||||
)
|
||||
|
||||
|
|
@ -211,7 +207,40 @@ func (pp *PluginPackage) UnmarshalJSON(data []byte) error {
|
|||
// GetAllPluginPackages gets all PluginPackages which may be available.
|
||||
func GetAllPluginPackages() PluginPackages {
|
||||
if allPluginPackages == nil {
|
||||
allPluginPackages = pluginChannels.Fetch()
|
||||
getOption := func(name string) []string {
|
||||
data := GetOption(name)
|
||||
if strs, ok := data.([]string); ok {
|
||||
return strs
|
||||
}
|
||||
if ifs, ok := data.([]interface{}); ok {
|
||||
result := make([]string, len(ifs))
|
||||
for i, urlIf := range ifs {
|
||||
if url, ok := urlIf.(string); ok {
|
||||
result[i] = url
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
channels := PluginChannels{}
|
||||
for _, url := range getOption("pluginchannels") {
|
||||
channels = append(channels, PluginChannel(url))
|
||||
}
|
||||
repos := []PluginRepository{}
|
||||
for _, url := range getOption("pluginrepos") {
|
||||
repos = append(repos, PluginRepository(url))
|
||||
}
|
||||
allPluginPackages = fetchAllSources(len(repos)+1, func(i int) PluginPackages {
|
||||
if i == 0 {
|
||||
return channels.Fetch()
|
||||
} else {
|
||||
return repos[i-1].Fetch()
|
||||
}
|
||||
})
|
||||
}
|
||||
return allPluginPackages
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,6 +192,10 @@ func DefaultGlobalSettings() map[string]interface{} {
|
|||
"syntax": true,
|
||||
"tabsize": float64(4),
|
||||
"tabstospaces": false,
|
||||
"pluginchannels": []string{
|
||||
"https://www.boombuler.de/channel.json",
|
||||
},
|
||||
"pluginrepos": []string{},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue