- Each plugin connect connection gets a session id that is forwarded with channel/<id>/message; when the connection ends the host notifies the sidecar with channel/<id>/closed so it can cancel calls and release input. - host/console.screenshot crops a region from the full-resolution frame, optionally measured in a reference image size, and full frames now honor max_width up to 2560. - host/console.key can hold or release one key, and host/console.release lifts keys and pointer buttons in one call. Driver consoles stay press-only. - host/vm.shutdown accepts force, and host/vm.snapshot.list needs only vm:read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
|
|
"github.com/Nwflower/reims-go/internal/control"
|
|
"github.com/Nwflower/reims-go/internal/plugin"
|
|
)
|
|
|
|
func (a *App) startPluginControlServer() {
|
|
a.mu.Lock()
|
|
if a.ctx == nil || a.pluginMgr == nil || a.controlServer != nil {
|
|
a.mu.Unlock()
|
|
return
|
|
}
|
|
a.mu.Unlock()
|
|
|
|
currentManager := func() *plugin.Manager {
|
|
a.mu.Lock()
|
|
defer a.mu.Unlock()
|
|
return a.pluginMgr
|
|
}
|
|
server, err := control.ListenWithOptions(control.PipeName(), func(ctx context.Context, pluginID, channel string, message json.RawMessage) (json.RawMessage, error) {
|
|
mgr := currentManager()
|
|
if mgr == nil {
|
|
return nil, errors.New("plugin manager is not ready")
|
|
}
|
|
return mgr.ChannelMessage(ctx, pluginID, channel, control.SessionFrom(ctx), message)
|
|
}, control.Options{OnSessionEnd: func(session string, targets []control.Target) {
|
|
mgr := currentManager()
|
|
if mgr == nil {
|
|
return
|
|
}
|
|
for _, target := range targets {
|
|
mgr.ChannelSessionClosed(target.PluginID, target.Channel, session)
|
|
}
|
|
}})
|
|
if err != nil {
|
|
a.emitLog("plugin", "Could not open local plugin control channel: "+err.Error())
|
|
return
|
|
}
|
|
|
|
a.mu.Lock()
|
|
if a.ctx == nil || a.pluginMgr == nil || a.controlServer != nil {
|
|
a.mu.Unlock()
|
|
_ = server.Close()
|
|
return
|
|
}
|
|
a.controlServer = server
|
|
a.mu.Unlock()
|
|
}
|
|
|
|
func (a *App) stopPluginControlServer() {
|
|
a.mu.Lock()
|
|
server := a.controlServer
|
|
a.controlServer = nil
|
|
a.mu.Unlock()
|
|
if server != nil {
|
|
_ = server.Close()
|
|
}
|
|
}
|