mirror of
https://github.com/jixishi/SerialTerminalForWindowsTerminal.git
synced 2026-06-15 16:42:46 +00:00
feat: auto-load all .lua plugins from plugins/ directory
Replace loadDefaultDemoPlugin with loadPluginsFromDir that scans the plugins/ directory for .lua files and loads them all. All plugins are disabled by default; user enables them via .plugin enable or TUI panel. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+17
-8
@@ -66,7 +66,7 @@ func New(cfg *appconfig.Config, sess *session.SerialSession, out io.Writer) (*Ap
|
|||||||
a.forward = forward.NewManager(a.writeRawToSession, a.Notifyf)
|
a.forward = forward.NewManager(a.writeRawToSession, a.Notifyf)
|
||||||
a.forward.SetInboundReporter(a.reportForwardIngress)
|
a.forward.SetInboundReporter(a.reportForwardIngress)
|
||||||
a.dispatcher = command.NewDispatcher(a)
|
a.dispatcher = command.NewDispatcher(a)
|
||||||
if err = a.loadDefaultDemoPlugin(); err != nil {
|
if err = a.loadPluginsFromDir(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return a, nil
|
return a, nil
|
||||||
@@ -91,20 +91,29 @@ func (a *App) LoadConfiguredForwards() { a.loadConfiguredForwards() }
|
|||||||
func (a *App) Sess() *session.SerialSession { return a.sess }
|
func (a *App) Sess() *session.SerialSession { return a.sess }
|
||||||
func (a *App) Out() io.Writer { return a.out }
|
func (a *App) Out() io.Writer { return a.out }
|
||||||
|
|
||||||
func (a *App) loadDefaultDemoPlugin() error {
|
func (a *App) loadPluginsFromDir() error {
|
||||||
demoPath := filepath.Join("plugins", "demo.lua")
|
entries, err := os.ReadDir("plugins")
|
||||||
if _, err := os.Stat(demoPath); err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
name, err := a.plugins.Load(demoPath)
|
for _, entry := range entries {
|
||||||
if err != nil {
|
if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".lua") {
|
||||||
return err
|
continue
|
||||||
|
}
|
||||||
|
pluginPath := filepath.Join("plugins", entry.Name())
|
||||||
|
name, loadErr := a.plugins.Load(pluginPath)
|
||||||
|
if loadErr != nil {
|
||||||
|
a.Notifyf("[plugin] load %s failed: %v", entry.Name(), loadErr)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Disable by default; user enables via .plugin enable or TUI panel
|
||||||
|
_ = a.plugins.Disable(name)
|
||||||
}
|
}
|
||||||
return a.plugins.Disable(name)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) Notifyf(format string, args ...any) {
|
func (a *App) Notifyf(format string, args ...any) {
|
||||||
|
|||||||
Reference in New Issue
Block a user