Adding the ability to differenitate builtin plugins when listing

This commit is contained in:
Neko Box Coder
2025-07-29 23:00:55 +01:00
parent 7492195a5b
commit 1096c4f3ba
3 changed files with 21 additions and 11 deletions

View File

@@ -71,7 +71,7 @@ type Plugin struct {
Info *PluginInfo // json file containing info
Srcs []RuntimeFile // lua files
Loaded bool
Default bool // pre-installed plugin
Builtin bool
}
// IsLoaded returns if a plugin is enabled

View File

@@ -42,6 +42,7 @@ type PluginPackage struct {
Author string
Tags []string
Versions PluginVersions
Builtin bool
}
// PluginPackages is a list of PluginPackage instances.
@@ -75,6 +76,9 @@ func (pp *PluginPackage) String() string {
buf := new(bytes.Buffer)
buf.WriteString("Plugin: ")
buf.WriteString(pp.Name)
if pp.Builtin {
buf.WriteString(" (built-in)")
}
buf.WriteRune('\n')
if pp.Author != "" {
buf.WriteString("Author: ")
@@ -334,7 +338,7 @@ func isUnknownCoreVersion() bool {
return err != nil
}
func newStaticPluginVersion(name, version string) *PluginVersion {
func newStaticPluginVersion(name, version string, builtin bool) *PluginVersion {
vers, err := semver.ParseTolerant(version)
if err != nil {
@@ -344,6 +348,7 @@ func newStaticPluginVersion(name, version string) *PluginVersion {
}
pl := &PluginPackage{
Name: name,
Builtin: builtin,
}
pv := &PluginVersion{
pack: pl,
@@ -358,7 +363,7 @@ func newStaticPluginVersion(name, version string) *PluginVersion {
func GetInstalledVersions(withCore bool) PluginVersions {
result := PluginVersions{}
if withCore {
result = append(result, newStaticPluginVersion(CorePluginName, util.Version))
result = append(result, newStaticPluginVersion(CorePluginName, util.Version, true))
}
for _, p := range Plugins {
@@ -366,7 +371,7 @@ func GetInstalledVersions(withCore bool) PluginVersions {
continue
}
version := GetInstalledPluginVersion(p.Name)
if pv := newStaticPluginVersion(p.Name, version); pv != nil {
if pv := newStaticPluginVersion(p.Name, version, p.Builtin); pv != nil {
result = append(result, pv)
}
}
@@ -604,7 +609,7 @@ func UpdatePlugins(out io.Writer, plugins []string) {
// if no plugins are specified, update all installed plugins.
if len(plugins) == 0 {
for _, p := range Plugins {
if !p.IsLoaded() || p.Default {
if !p.IsLoaded() || p.Builtin {
continue
}
plugins = append(plugins, p.Name)
@@ -613,7 +618,7 @@ func UpdatePlugins(out io.Writer, plugins []string) {
fmt.Fprintln(out, "Checking for plugin updates")
microVersion := PluginVersions{
newStaticPluginVersion(CorePluginName, util.Version),
newStaticPluginVersion(CorePluginName, util.Version, true),
}
var updates = make(PluginDependencies, 0)
@@ -665,8 +670,8 @@ func PluginCommand(out io.Writer, cmd string, args []string) {
for _, plugin := range args {
// check if the plugin exists.
for _, p := range Plugins {
if p.Name == plugin && p.Default {
fmt.Fprintln(out, "Default plugins cannot be removed, but can be disabled via settings.")
if p.Name == plugin && p.Builtin {
fmt.Fprintln(out, "Built-in plugins cannot be removed, but can be disabled via settings.")
continue
}
if p.Name == plugin {
@@ -687,8 +692,12 @@ func PluginCommand(out io.Writer, cmd string, args []string) {
plugins := GetInstalledVersions(false)
fmt.Fprintln(out, "The following plugins are currently installed:")
for _, p := range plugins {
if p.Pack().Builtin {
fmt.Fprintf(out, "%s (built-in)\n", p.Pack().Name)
} else {
fmt.Fprintf(out, "%s (%s)\n", p.Pack().Name, p.Version)
}
}
case "search":
plugins := SearchPlugin(out, args)
fmt.Fprintln(out, len(plugins), " plugins found")

View File

@@ -187,6 +187,7 @@ func InitPlugins() {
p.Name = "initlua"
p.DirName = "initlua"
p.Srcs = append(p.Srcs, realFile(initlua))
p.Builtin = false
Plugins = append(Plugins, p)
}
@@ -242,7 +243,7 @@ func InitPlugins() {
p := new(Plugin)
p.Name = d
p.DirName = d
p.Default = true
p.Builtin = true
for _, f := range srcs {
if strings.HasSuffix(f, ".lua") {
p.Srcs = append(p.Srcs, assetFile(filepath.Join(plugdir, d, f)))